diff options
author | ZeroC Staff <git@zeroc.com> | 2014-06-04 23:03:57 +0000 |
---|---|---|
committer | ZeroC Staff <git@zeroc.com> | 2014-06-04 23:03:57 +0000 |
commit | 7aaf53c7ecb429a8e3b6abab3f7b9dbdc387b171 (patch) | |
tree | 78bde514408b4d02488e5efffd325faaa1c9a287 /cpp/src | |
parent | fix for Java metrics test (diff) | |
download | ice-7aaf53c7ecb429a8e3b6abab3f7b9dbdc387b171.tar.bz2 ice-7aaf53c7ecb429a8e3b6abab3f7b9dbdc387b171.tar.xz ice-7aaf53c7ecb429a8e3b6abab3f7b9dbdc387b171.zip |
New cpp:view-type metadata for strings, sequences and dictionaries, plus updates
to throughput demo. Fixes ICE-5382.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Ice/StreamI.cpp | 20 | ||||
-rw-r--r-- | cpp/src/Ice/StreamI.h | 3 | ||||
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 115 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 20 |
5 files changed, 106 insertions, 58 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index 580cd342839..3b2d7fa41c6 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -1350,7 +1350,7 @@ IceInternal::BasicStream::write(const char*) */ void -IceInternal::BasicStream::writeConverted(const string& v) +IceInternal::BasicStream::writeConverted(const char* vdata, size_t vsize) { // // What is the size of the resulting UTF-8 encoded string? @@ -1359,13 +1359,13 @@ IceInternal::BasicStream::writeConverted(const string& v) // try { - Int guessedSize = static_cast<Int>(v.size()); + Int guessedSize = static_cast<Int>(vsize); writeSize(guessedSize); // writeSize() only writes the size; it does not reserve any buffer space. size_t firstIndex = b.size(); StreamUTF8BufferI buffer(*this); - Byte* lastByte = _stringConverter->toUTF8(v.data(), v.data() + v.size(), buffer); + Byte* lastByte = _stringConverter->toUTF8(vdata, vdata + vsize, buffer); if(lastByte != b.end()) { b.resize(lastByte - b.begin()); diff --git a/cpp/src/Ice/StreamI.cpp b/cpp/src/Ice/StreamI.cpp index f8572ebd136..e5a9920dd23 100644 --- a/cpp/src/Ice/StreamI.cpp +++ b/cpp/src/Ice/StreamI.cpp @@ -206,6 +206,18 @@ InputStreamI::read(string& v, bool convert) } void +InputStreamI::read(const char*& vdata, size_t& vsize) +{ + _is->read(vdata, vsize); +} + +void +InputStreamI::read(const char*& vdata, size_t& vsize, string& holder) +{ + _is->read(vdata, vsize, holder); +} + +void InputStreamI::read(vector<string>& v, bool convert) { _is->read(v, convert); @@ -521,9 +533,15 @@ OutputStreamI::write(const string& v, bool convert) } void +OutputStreamI::write(const char* vdata, size_t vsize, bool convert) +{ + _os->write(vdata, vsize, convert); +} + +void OutputStreamI::write(const char* v, bool convert) { - _os->write(v, convert); + _os->write(v, strlen(v), convert); } void diff --git a/cpp/src/Ice/StreamI.h b/cpp/src/Ice/StreamI.h index 989ddf2c5fc..4ea957be74d 100644 --- a/cpp/src/Ice/StreamI.h +++ b/cpp/src/Ice/StreamI.h @@ -78,6 +78,8 @@ public: virtual void read(Float&); virtual void read(Double&); virtual void read(std::string&, bool = true); + virtual void read(const char*&, size_t&); + virtual void read(const char*&, size_t&, std::string&); virtual void read(std::vector<std::string>&, bool); virtual void read(std::wstring&); virtual void read(std::vector<bool>&); @@ -136,6 +138,7 @@ public: virtual void write(Float); virtual void write(Double); virtual void write(const std::string&, bool = true); + virtual void write(const char*, size_t, bool = true); virtual void write(const std::vector<std::string>&, bool); virtual void write(const char*, bool = true); virtual void write(const std::wstring&); diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 86a7b138805..3f1104a156c 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -43,6 +43,31 @@ string toTemplateArg(const string& arg) } string +stringTypeToString(const TypePtr& type, const StringList& metaData, int typeCtx) +{ + string strType = findMetaData(metaData, typeCtx); + if(strType == "wstring" || (typeCtx & TypeContextUseWstring && strType == "")) + { + if(featureProfile == IceE) + { + return "::Ice::Wstring"; + } + else + { + return "::std::wstring"; + } + } + else if(strType != "" && strType != "string") + { + return strType; + } + else + { + return "::std::string"; + } +} + +string sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typeCtx) { string seqType = findMetaData(metaData, typeCtx); @@ -420,6 +445,7 @@ Slice::printDllExportStuff(Output& out, const string& dllExport) } } + string Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx) { @@ -443,20 +469,12 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx { if(builtin->kind() == Builtin::KindString) { - string strType = findMetaData(metaData); - if(strType != "string" && (typeCtx & TypeContextUseWstring || strType == "wstring")) - { - if(featureProfile == IceE) - { - return "::Ice::Wstring"; - } - else - { - return "::std::wstring"; - } - } + return stringTypeToString(type, metaData, typeCtx); + } + else + { + return builtinTable[builtin->kind()]; } - return builtinTable[builtin->kind()]; } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); @@ -567,20 +585,12 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m { if(builtin->kind() == Builtin::KindString) { - string strType = findMetaData(metaData); - if(strType != "string" && (typeCtx & TypeContextUseWstring || strType == "wstring")) - { - if(featureProfile == IceE) - { - return "const ::Ice::Wstring&"; - } - else - { - return "const ::std::wstring&"; - } - } + return string("const ") + stringTypeToString(type, metaData, typeCtx) + "&"; + } + else + { + return inputBuiltinTable[builtin->kind()]; } - return inputBuiltinTable[builtin->kind()]; } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); @@ -660,20 +670,12 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& { if(builtin->kind() == Builtin::KindString) { - string strType = findMetaData(metaData); - if(strType != "string" && (typeCtx & TypeContextUseWstring || strType == "wstring")) - { - if(featureProfile == IceE) - { - return "::Ice::Wstring&"; - } - else - { - return "::std::wstring&"; - } - } + return stringTypeToString(type, metaData, typeCtx) + "&"; + } + else + { + return outputBuiltinTable[builtin->kind()]; } - return outputBuiltinTable[builtin->kind()]; } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); @@ -1015,6 +1017,7 @@ string Slice::findMetaData(const StringList& metaData, int typeCtx) { static const string prefix = "cpp:"; + for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q) { string str = *q; @@ -1025,34 +1028,50 @@ Slice::findMetaData(const StringList& metaData, int typeCtx) // // If the form is cpp:type:<...> the data after cpp:type: // is returned. + // If the form is cpp:view-type:<...> the data after the + // cpp:view-type: is returned // If the form is cpp:range[:<...>], cpp:array or cpp:class, // the return value is % followed by the string after cpp:. // + // The priority of the metadata is as follows: + // 1: protobuf + // 2: array, range, range:array, view-type for "view" parameters + // 3: class + if(pos != string::npos) { string ss = str.substr(prefix.size()); - if(ss.find("type:") == 0 || ss.find("protobuf:") == 0) + + if(ss.find("protobuf:") == 0) { return str.substr(pos + 1); - } - else if((typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd)) && - !(typeCtx & TypeContextAMIEnd) && ss.find("range:") == 0) + } + + if(typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd)) { - return string("%") + str.substr(prefix.size()); + if(ss.find("range:") == 0) + { + return string("%") + str.substr(prefix.size()); + } + else if(ss.find("view-type:") == 0) + { + return str.substr(pos + 1); + } } - else if((typeCtx & TypeContextAMIPrivateEnd) && ss == "range:array") + + if(ss.find("type:") == 0) { - return "%range:array"; + return str.substr(pos + 1); } } - else if(typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd) && !(typeCtx & TypeContextAMIEnd)) + else if(typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd)) { string ss = str.substr(prefix.size()); if(ss == "array") { return "%array"; } - else if((typeCtx & TypeContextInParam) && ss == "range") + else if(ss == "range") { return "%range"; } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index ac6939b836e..534c5fea292 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -6413,7 +6413,8 @@ Slice::Gen::MetaDataVisitor::visitOperation(const OperationPtr& p) { for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q) { - if(q->find("cpp:type:", 0) == 0 || q->find("cpp:array", 0) == 0 || q->find("cpp:range", 0) == 0) + if(q->find("cpp:type:", 0) == 0 || q->find("cpp:view-type:", 0) == 0 + || (*q) == "cpp:array" || q->find("cpp:range", 0) == 0) { emitWarning(p->file(), p->line(), "ignoring invalid metadata `" + *q + "' for operation with void return type"); @@ -6477,7 +6478,7 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin if(s.find(prefix) == 0) { string ss = s.substr(prefix.size()); - if(ss.find("type:wstring") == 0 || ss.find("type:string") == 0) + if(ss == "type:wstring" || ss == "type:string") { BuiltinPtr builtin = BuiltinPtr::dynamicCast(cont); ModulePtr module = ModulePtr::dynamicCast(cont); @@ -6489,22 +6490,29 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin continue; } } + if(BuiltinPtr::dynamicCast(cont) && (ss.find("type:") == 0 || ss.find("view-type:") == 0)) + { + if(BuiltinPtr::dynamicCast(cont)->kind() == Builtin::KindString) + { + continue; + } + } if(SequencePtr::dynamicCast(cont)) { - if(ss.find("type:") == 0 || ss == "array" || ss.find("range") == 0) + if(ss.find("type:") == 0 || ss.find("view-type:") == 0 || ss == "array" || ss.find("range") == 0) { continue; } } - if(DictionaryPtr::dynamicCast(cont) && ss.find("type:") == 0) + if(DictionaryPtr::dynamicCast(cont) && (ss.find("type:") == 0 || ss.find("view-type:") == 0)) { continue; } - if(StructPtr::dynamicCast(cont) && (ss.find("class") == 0 || ss.find("comparable") == 0)) + if(StructPtr::dynamicCast(cont) && (ss == "class" || ss == "comparable")) { continue; } - if(ClassDefPtr::dynamicCast(cont) && ss.find("virtual") == 0) + if(ClassDefPtr::dynamicCast(cont) && ss == "virtual") { continue; } |