summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2012-09-14 15:30:12 -0700
committerMark Spruiell <mes@zeroc.com>2012-09-14 15:30:12 -0700
commitc912d30d47799bbba77d0f2532704d8aaba12a4a (patch)
tree8611fdb0b73a9a78f7c319ca4bb08f1f9d2e9cd0 /cpp/src
parentFixed optional test issues (diff)
downloadice-c912d30d47799bbba77d0f2532704d8aaba12a4a.tar.bz2
ice-c912d30d47799bbba77d0f2532704d8aaba12a4a.tar.xz
ice-c912d30d47799bbba77d0f2532704d8aaba12a4a.zip
Python support for optionals
Diffstat (limited to 'cpp/src')
-rwxr-xr-xcpp/src/Ice/BasicStream.cpp39
-rw-r--r--cpp/src/Ice/SlicedData.cpp6
-rw-r--r--cpp/src/Ice/StreamI.cpp16
-rw-r--r--cpp/src/Ice/StreamI.h5
-rwxr-xr-xcpp/src/Slice/PythonUtil.cpp47
5 files changed, 92 insertions, 21 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 199ef69d639..105afb804bc 100755
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -97,7 +97,8 @@ IceInternal::BasicStream::BasicStream(Instance* instance, const EncodingVersion&
_unlimited(unlimited),
_stringConverter(instance->initializationData().stringConverter),
_wstringConverter(instance->initializationData().wstringConverter),
- _startSeq(-1)
+ _startSeq(-1),
+ _sizePos(-1)
{
//
// Initialize the encoding members of our pre-allocated encapsulations, in case
@@ -126,6 +127,8 @@ IceInternal::BasicStream::clear()
_startSeq = -1;
+ _sizePos = -1;
+
_sliceObjects = true;
}
@@ -163,6 +166,7 @@ IceInternal::BasicStream::swap(BasicStream& other)
std::swap(_unlimited, other._unlimited);
std::swap(_startSeq, other._startSeq);
std::swap(_minSeqSize, other._minSeqSize);
+ std::swap(_sizePos, other._sizePos);
}
void
@@ -2754,12 +2758,39 @@ IceInternal::BasicStream::EncapsDecoder::readInstance()
skipSlice();
//
- // If this is the last slice, keep the object as an opaque
- // UnknownSlicedData object.
+ // If this is the last slice, keep the object as an opaque UnknownSlicedObject.
//
if(_sliceFlags & FLAG_IS_LAST_SLICE)
{
- v = new UnknownSlicedObject(mostDerivedId);
+ //
+ // Provide a factory with an opportunity to supply the object.
+ // We pass the "::Ice::Object" ID to indicate that this is the
+ // last chance to preserve the object.
+ //
+ userFactory = servantFactoryManager->find(Object::ice_staticId());
+ if(userFactory)
+ {
+ v = userFactory->create(Object::ice_staticId());
+ }
+
+ //
+ // If that fails, invoke the default factory if one has been
+ // registered.
+ //
+ if(!v)
+ {
+ userFactory = servantFactoryManager->find("");
+ if(userFactory)
+ {
+ v = userFactory->create(Object::ice_staticId());
+ }
+ }
+
+ if(!v)
+ {
+ v = new UnknownSlicedObject(mostDerivedId);
+ }
+
break;
}
diff --git a/cpp/src/Ice/SlicedData.cpp b/cpp/src/Ice/SlicedData.cpp
index 9b2e88b609c..5332719eec9 100644
--- a/cpp/src/Ice/SlicedData.cpp
+++ b/cpp/src/Ice/SlicedData.cpp
@@ -82,6 +82,12 @@ Ice::UnknownSlicedObject::getUnknownTypeId() const
return _unknownTypeId;
}
+SlicedDataPtr
+Ice::UnknownSlicedObject::getSlicedData() const
+{
+ return _slicedData;
+}
+
void
Ice::UnknownSlicedObject::__addObject(IceInternal::GCCountMap& _c)
{
diff --git a/cpp/src/Ice/StreamI.cpp b/cpp/src/Ice/StreamI.cpp
index e1e73f94617..431926d64b0 100644
--- a/cpp/src/Ice/StreamI.cpp
+++ b/cpp/src/Ice/StreamI.cpp
@@ -570,10 +570,10 @@ OutputStreamI::write(const Double* begin, const Double* end)
_os->write(begin, end);
}
-void
+bool
OutputStreamI::writeOptional(Int tag, OptionalType type)
{
- _os->writeOpt(tag, type);
+ return _os->writeOpt(tag, type);
}
void
@@ -677,6 +677,18 @@ OutputStreamI::rewrite(Int sz, size_type p)
_os->rewrite(sz, p);
}
+void
+OutputStreamI::startSize()
+{
+ _os->startSize();
+}
+
+void
+OutputStreamI::endSize()
+{
+ _os->endSize();
+}
+
//
// ObjectReader
//
diff --git a/cpp/src/Ice/StreamI.h b/cpp/src/Ice/StreamI.h
index 8d9bba4e977..ba0d103a640 100644
--- a/cpp/src/Ice/StreamI.h
+++ b/cpp/src/Ice/StreamI.h
@@ -147,7 +147,7 @@ public:
using OutputStream::write;
#endif
- virtual void writeOptional(Int, OptionalType);
+ virtual bool writeOptional(Int, OptionalType);
virtual void startObject(const SlicedDataPtr&);
virtual void endObject();
@@ -173,6 +173,9 @@ public:
virtual size_type pos();
virtual void rewrite(Int, size_type);
+ virtual void startSize();
+ virtual void endSize();
+
private:
const CommunicatorPtr _communicator;
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index 4e363c17d18..45ded5d48bc 100755
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -565,7 +565,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
string fixedOpName = fixIdent((*oli)->name());
if(!p->isLocal() && (p->hasMetaData("amd") || (*oli)->hasMetaData("amd")))
{
- _out << sp << nl << "def " << fixedOpName << "_async(self, _cb";
+ _out << sp << nl << "def " << (*oli)->name() << "_async(self, _cb";
ParamDeclList params = (*oli)->parameters();
@@ -749,7 +749,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
{
_out << nl << comment;
}
- _out << nl << "def " << fixedOpName << "_async(self, _cb";
+ _out << nl << "def " << (*oli)->name() << "_async(self, _cb";
if(!inParams.empty())
{
_out << ", " << inParams;
@@ -832,7 +832,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
//
// Data members are represented as a tuple:
//
- // ('MemberName', MemberMetaData, MemberType)
+ // ('MemberName', MemberMetaData, MemberType, Optional, Tag)
//
// where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type.
//
@@ -858,7 +858,8 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
writeMetaData((*r)->getMetaData());
_out << ", ";
writeType((*r)->type());
- _out << ')';
+ _out << ", " << ((*r)->optional() ? "True" : "False") << ", "
+ << ((*r)->optional() ? (*r)->tag() : 0) << ')';
}
if(members.size() == 1)
{
@@ -875,7 +876,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
//
// Define each operation. The arguments to the IcePy.Operation constructor are:
//
- // 'opName', Mode, SendMode, AMD, (MetaData), (InParams), (OutParams), ReturnType, (Exceptions)
+ // 'opName', Mode, SendMode, AMD, Format, MetaData, (InParams), (OutParams), ReturnParam, (Exceptions)
//
// where InParams and OutParams are tuples of type descriptions, and Exceptions
// is a tuple of exception type ids.
@@ -923,7 +924,8 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
writeMetaData((*t)->getMetaData());
_out << ", ";
writeType((*t)->type());
- _out << ')';
+ _out << ", " << ((*t)->optional() ? "True" : "False") << ", "
+ << ((*t)->optional() ? (*t)->tag() : 0) << ')';
++count;
}
}
@@ -944,7 +946,8 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
writeMetaData((*t)->getMetaData());
_out << ", ";
writeType((*t)->type());
- _out << ')';
+ _out << ", " << ((*t)->optional() ? "True" : "False") << ", "
+ << ((*t)->optional() ? (*t)->tag() : 0) << ')';
++count;
}
}
@@ -956,7 +959,15 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
TypePtr returnType = (*s)->returnType();
if(returnType)
{
+ //
+ // The return type has the same format as an in/out parameter:
+ //
+ // MetaData, Type, Optional?, OptionalTag
+ //
+ _out << "((), ";
writeType(returnType);
+ _out << ", " << ((*s)->returnIsOptional() ? "True" : "False") << ", "
+ << ((*s)->returnIsOptional() ? (*s)->returnTag() : 0) << ')';
}
else
{
@@ -1125,7 +1136,7 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
//
// Data members are represented as a tuple:
//
- // ('MemberName', MemberMetaData, MemberType)
+ // ('MemberName', MemberMetaData, MemberType, Optional, Tag)
//
// where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type.
//
@@ -1139,7 +1150,8 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
writeMetaData((*dmli)->getMetaData());
_out << ", ";
writeType((*dmli)->type());
- _out << ')';
+ _out << ", " << ((*dmli)->optional() ? "True" : "False") << ", "
+ << ((*dmli)->optional() ? (*dmli)->tag() : 0) << ')';
}
if(members.size() == 1)
{
@@ -1762,24 +1774,27 @@ Slice::Python::CodeVisitor::writeMetaData(const StringList& meta)
void
Slice::Python::CodeVisitor::writeAssign(const MemberInfo& info)
{
+ string paramName = info.fixedName;
+ string memberName = info.fixedName;
+
//
// Structures are treated differently (see bug 3676).
//
StructPtr st = StructPtr::dynamicCast(info.dataMember->type());
- if(st)
+ if(st && !info.dataMember->optional())
{
- _out << nl << "if " << info.fixedName << " is Ice._struct_marker:";
+ _out << nl << "if " << paramName << " is Ice._struct_marker:";
_out.inc();
- _out << nl << "self." << info.fixedName << " = " << getSymbol(st) << "()";
+ _out << nl << "self." << memberName << " = " << getSymbol(st) << "()";
_out.dec();
_out << nl << "else:";
_out.inc();
- _out << nl << "self." << info.fixedName << " = " << info.fixedName;
+ _out << nl << "self." << memberName << " = " << paramName;
_out.dec();
}
else
{
- _out << nl << "self." << info.fixedName << " = " << info.fixedName;
+ _out << nl << "self." << memberName << " = " << paramName;
}
}
@@ -1933,6 +1948,10 @@ Slice::Python::CodeVisitor::writeConstructorParams(const MemberInfoList& members
{
writeConstantValue(member->type(), member->defaultValueType(), member->defaultValue());
}
+ else if(member->optional())
+ {
+ _out << "Ice.Unset";
+ }
else
{
writeInitializer(member->type());