summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2012-09-19 12:00:52 -0400
committerBernard Normier <bernard@zeroc.com>2012-09-19 12:09:56 -0400
commit2068ac0ec6ce1f239abc73ff23407326ba33ffbf (patch)
tree110b52821232cdc5ffb1d6cd4f5f2110ed520f4d /cpp/src
parentPython support for optionals (diff)
downloadice-2068ac0ec6ce1f239abc73ff23407326ba33ffbf.tar.bz2
ice-2068ac0ec6ce1f239abc73ff23407326ba33ffbf.tar.xz
ice-2068ac0ec6ce1f239abc73ff23407326ba33ffbf.zip
Partial fix for ICE-3393:
- strealined StreamTraits.h - added ability to define custom dictionaries in C++ (with cpp:type:...) - added tests for custom dictionaries in test/Ice/custom Fixed ICE-4867: - clear parameter before unmarshaling into dictionary/map in C++ - added test
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/StreamI.cpp7
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp35
-rw-r--r--cpp/src/slice2cpp/Gen.cpp57
3 files changed, 79 insertions, 20 deletions
diff --git a/cpp/src/Ice/StreamI.cpp b/cpp/src/Ice/StreamI.cpp
index 431926d64b0..e533b77ceda 100644
--- a/cpp/src/Ice/StreamI.cpp
+++ b/cpp/src/Ice/StreamI.cpp
@@ -702,6 +702,13 @@ void
ObjectReader::__read(BasicStream* is)
{
InputStreamI* stream = reinterpret_cast<InputStreamI*>(is->closure());
+
+ if(stream == 0)
+ {
+ Ice::ObjectNotExistException ex(__FILE__, __LINE__);
+ cerr << ex.ice_stackTrace() << endl;
+ }
+
assert(stream);
read(stream);
}
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 9eaed2ebcc5..992ba303cda 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -116,6 +116,21 @@ sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typ
}
}
+string
+dictionaryTypeToString(const DictionaryPtr& dict, const StringList& metaData, int typeCtx)
+{
+ string dictType = findMetaData(metaData, typeCtx);
+ if(!dictType.empty())
+ {
+ return dictType;
+ }
+ else
+ {
+ return fixKwd(dict->scoped());
+ }
+}
+
+
void
writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const string& fixedName,
const StringList& metaData, int typeCtx)
@@ -472,7 +487,13 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
{
return sequenceTypeToString(seq, metaData, typeCtx);
}
-
+
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
+ if(dict)
+ {
+ return dictionaryTypeToString(dict, metaData, typeCtx);
+ }
+
ContainedPtr contained = ContainedPtr::dynamicCast(type);
if(contained)
{
@@ -596,6 +617,12 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
{
return "const " + sequenceTypeToString(seq, metaData, typeCtx) + "&";
}
+
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
+ if(dict)
+ {
+ return "const " + dictionaryTypeToString(dict, metaData, typeCtx) + "&";
+ }
ContainedPtr contained = ContainedPtr::dynamicCast(type);
if(contained)
@@ -678,6 +705,12 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
return sequenceTypeToString(seq, metaData, typeCtx) + "&";
}
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
+ if(dict)
+ {
+ return dictionaryTypeToString(dict, metaData, typeCtx) + "&";
+ }
+
ContainedPtr contained = ContainedPtr::dynamicCast(type);
if(contained)
{
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index b0c4f5666db..e7477b1bd95 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -1384,31 +1384,48 @@ void
Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
{
string name = fixKwd(p->name());
- TypePtr keyType = p->keyType();
- if(SequencePtr::dynamicCast(keyType))
+ string dictType = findMetaData(p->getMetaData());
+
+ if(dictType.empty())
{
- SequencePtr s = SequencePtr::dynamicCast(keyType);
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(s->type());
- if(builtin && builtin->kind() == Builtin::KindByte)
+ //
+ // A default std::map dictionary
+ //
+
+ TypePtr keyType = p->keyType();
+ if(SequencePtr::dynamicCast(keyType))
{
- StringList metaData = s->getMetaData();
- bool protobuf;
- findMetaData(s, metaData, protobuf);
- if(protobuf)
+ SequencePtr s = SequencePtr::dynamicCast(keyType);
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(s->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
{
- emitWarning(p->file(), p->line(), "protobuf cannot be used as a dictionary key in C++");
+ StringList metaData = s->getMetaData();
+ bool protobuf;
+ findMetaData(s, metaData, protobuf);
+ if(protobuf)
+ {
+ emitWarning(p->file(), p->line(), "protobuf cannot be used as a dictionary key in C++");
+ }
}
}
+
+ TypePtr valueType = p->valueType();
+ string ks = typeToString(keyType, p->keyMetaData(), _useWstring);
+ if(ks[0] == ':')
+ {
+ ks.insert(0, " ");
+ }
+ string vs = typeToString(valueType, p->valueMetaData(), _useWstring);
+
+ H << sp << nl << "typedef ::std::map<" << ks << ", " << vs << "> " << name << ';';
}
-
- TypePtr valueType = p->valueType();
- string ks = typeToString(keyType, p->keyMetaData(), _useWstring);
- if(ks[0] == ':')
+ else
{
- ks.insert(0, " ");
+ //
+ // A custom dictionary
+ //
+ H << sp << nl << "typedef " << dictType << ' ' << name << ';';
}
- string vs = typeToString(valueType, p->valueMetaData(), _useWstring);
- H << sp << nl << "typedef ::std::map<" << ks << ", " << vs << "> " << name << ';';
}
void
@@ -6143,7 +6160,6 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p)
H << nl << "static const ::Ice::StreamTraitType type = ::Ice::StreamTraitTypeStruct;";
}
H << nl << "static const int minWireSize = " << p->minWireSize() << ";";
- H << nl << "static const bool isVariableLength = " << p->isVariableLength() << ";";
if(p->isVariableLength())
{
H << nl << "static const ::Ice::OptionalType optionalType = ::Ice::OptionalTypeFSize;";
@@ -6167,7 +6183,6 @@ Slice::Gen::StreamVisitor::visitEnum(const EnumPtr& p)
H << nl << "static const ::Ice::StreamTraitType type = ::Ice::StreamTraitTypeEnum;";
H << nl << "static const int enumLimit = " << p->getEnumerators().size() << ";";
H << nl << "static const int minWireSize = " << p->minWireSize() << ";";
- H << nl << "static const bool isVariableLength = true;";
H << nl << "static const ::Ice::OptionalType optionalType = ::Ice::OptionalTypeSize;";
H << eb << ";" << nl;
}
@@ -6431,6 +6446,10 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin
continue;
}
}
+ if(DictionaryPtr::dynamicCast(cont) && ss.find("type:") == 0)
+ {
+ continue;
+ }
if(StructPtr::dynamicCast(cont) && ss.find("class") == 0)
{
continue;