diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-02-09 19:20:38 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-02-09 19:20:38 +0100 |
commit | 124b43c7bd718655556bd3cba2a554293bf63d16 (patch) | |
tree | 5c3138e3c96e9f3a4763e1b6eea92018d892b241 /cpp/src/Slice/CPlusPlusUtil.cpp | |
parent | Bug 3519 - fix use of tolower in slice2freeze (diff) | |
download | ice-124b43c7bd718655556bd3cba2a554293bf63d16.tar.bz2 ice-124b43c7bd718655556bd3cba2a554293bf63d16.tar.xz ice-124b43c7bd718655556bd3cba2a554293bf63d16.zip |
Support for serializable and protobuf metadata (from cs_serial branch)
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 142 |
1 files changed, 131 insertions, 11 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 6997b9b436c..e09e622ea41 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -215,6 +215,13 @@ Slice::typeToString(const TypePtr& type, bool useWstring, const StringList& meta } else { + // Get the metadata associated at the point of definition. + bool protobuf; + seqType = findMetaData(seq, seq->getMetaData(), true, protobuf); + if(protobuf && !seqType.empty()) + { + return seqType; + } return fixKwd(seq->scoped()); } } @@ -348,6 +355,13 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList& } else { + // Get the metadata associated at the point of definition. + bool protobuf; + seqType = findMetaData(seq, seq->getMetaData(), true, protobuf); + if(protobuf && !seqType.empty()) + { + return "const " + seqType + "&"; + } return "const " + fixKwd(seq->scoped()) + "&"; } } @@ -432,6 +446,12 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList } else { + bool protobuf; + seqType = findMetaData(seq, seq->getMetaData(), true, protobuf); + if(protobuf && !seqType.empty()) + { + return seqType + "&"; + } return fixKwd(seq->scoped()) + "&"; } } @@ -679,6 +699,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& if(marshal) { string scope = fixKwd(seq->scope()); + if(seqType == "array" || seqType == "range:array") { // @@ -758,11 +779,13 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& else { // - // No modifying metadata specified. Use appropriate write methods for type. + // No modifying metadata specified. Use appropriate + // write methods for type. // StringList l = seq->getMetaData(); - seqType = findMetaData(l, false); - if(!seqType.empty()) + bool protobuf; + seqType = findMetaData(seq, l, false, protobuf); + if(protobuf || !seqType.empty()) { out << nl << scope << "__" << funcSeq << (pointer ? "" : "&") << stream << ", " << fixedParam << ");"; @@ -911,12 +934,14 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& else { // - // No modifying metadata supplied. Just use appropriate read function. + // No modifying metadata supplied. Just use + // appropriate read function. // StringList l = seq->getMetaData(); - seqType = findMetaData(l, false); - if(!seqType.empty() || !builtin || builtin->kind() == Builtin::KindObject || - builtin->kind() == Builtin::KindObjectProxy) + bool protobuf; + seqType = findMetaData(seq, l, false, protobuf); + if(protobuf || !seqType.empty() || !builtin || builtin->kind() == Builtin::KindObject || + builtin->kind() == Builtin::KindObjectProxy) { out << nl << scope << "__" << funcSeq << (pointer ? "" : "&") << stream << ", " << fixedParam << ");"; @@ -1019,8 +1044,13 @@ writeRangeAllocateCode(Output& out, const TypePtr& type, const string& fixedName SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { - string seqType = findMetaData(metaData, true); - if(seqType.find("range") == 0 && seqType != "range:array") + bool protobuf; + string seqType = findMetaData(seq, metaData, true, protobuf); + if(!protobuf && seqType.empty()) + { + seqType = findMetaData(seq, seq->getMetaData(), true, protobuf); + } + if(!protobuf && seqType.find("range") == 0 && seqType != "range:array") { StringList md; if(seqType.find("range:") == 0) @@ -1305,9 +1335,10 @@ Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const s } else { - seqType = findMetaData(seq->getMetaData(), false); + bool protobuf; + seqType = findMetaData(seq, seq->getMetaData(), false, protobuf); builtin = BuiltinPtr::dynamicCast(seq->type()); - if(!seqType.empty() || !builtin || (builtin->kind() == Builtin::KindObject || + if(protobuf || !seqType.empty() || !builtin || (builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindObjectProxy)) { string scope = fixKwd(seq->scope()); @@ -1501,6 +1532,95 @@ Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const s assert(false); } +// Accepted metadata. +// +// cpp:type:<typename> +// cpp:const +// cpp:array +// cpp:range:<typename> +// cpp:protobuf<:typename> +// + +// This form is for sequences definitions only. +string +Slice::findMetaData(const SequencePtr& seq, const StringList& metaData, bool inParam, bool& isProtobuf) +{ + isProtobuf = false; + static const string prefix = "cpp:"; + for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q) + { + string str = *q; + if(str.find(prefix) == 0) + { + string::size_type pos = str.find(':', prefix.size()); + string ss; + if(pos == string::npos) + { + ss = str.substr(prefix.size()); + } + else + { + ss = str.substr(prefix.size(), pos - prefix.size()); + } + // + // If the form is cpp:type:<...> the data after cpp:type: + // is returned. If the form is cpp:range:<...> (and this + // is an inParam) the data after cpp: is returned. + // + if(ss == "protobuf" || pos != string::npos) + { + string ss = str.substr(prefix.size(), pos - prefix.size()); + if(ss == "type") + { + return str.substr(pos + 1); + } + else if(ss == "protobuf") + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); + if(!builtin || builtin->kind() != Builtin::KindByte) + { + continue; + } + isProtobuf = true; + if(pos != string::npos) + { + return str.substr(pos + 1); + } + return ""; + } + else if(inParam && ss == "range") + { + return str.substr(prefix.size()); + } + } + // + // If the data is an inParam and the metadata is cpp:array + // or cpp:range then array or range is returned. + // + else if(inParam) + { + if(ss == "array" || ss == "range") + { + return ss; + } + } + // + // Otherwise if the data is "class" it is returned. + // + else + { + if(ss == "class") + { + return ss; + } + } + } + } + + return ""; +} + +// Does not handle cpp:protobuf string Slice::findMetaData(const StringList& metaData, bool inParam) { |