summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorJoe George <joe@zeroc.com>2016-06-08 15:30:30 -0400
committerJoe George <joe@zeroc.com>2016-06-08 15:30:30 -0400
commite5a8741b6af4bff17d3db4a3f37c26c4f21194c4 (patch)
treedfeb2fb83d200b8a411cd65b7de3db928a418ce4 /cpp/src
parentReplaced some ScopeArrays by vector or wstring (diff)
downloadice-e5a8741b6af4bff17d3db4a3f37c26c4f21194c4.tar.bz2
ice-e5a8741b6af4bff17d3db4a3f37c26c4f21194c4.tar.xz
ice-e5a8741b6af4bff17d3db4a3f37c26c4f21194c4.zip
ICE-6982 and ICE-6946
- Refactord C++ class/exception stream generated code - Changed return type of Obejct::ice_id() to std::string for C++11
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Object.cpp8
-rw-r--r--cpp/src/Ice/Value.cpp6
-rw-r--r--cpp/src/IceUtil/UtilException.cpp2
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp49
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.h2
-rw-r--r--cpp/src/Slice/Parser.cpp19
-rw-r--r--cpp/src/Slice/Parser.h1
-rw-r--r--cpp/src/slice2cpp/Gen.cpp261
-rw-r--r--cpp/src/slice2cpp/Gen.h3
9 files changed, 170 insertions, 181 deletions
diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp
index 7b049322512..b4bd4597fbe 100644
--- a/cpp/src/Ice/Object.cpp
+++ b/cpp/src/Ice/Object.cpp
@@ -78,7 +78,11 @@ Ice::Object::ice_ids(const Current&) const
return vector<string>(&__Ice__Object_ids[0], &__Ice__Object_ids[1]);
}
+#ifdef ICE_CPP11_MAPPING
+string
+#else
const string&
+#endif
Ice::Object::ice_id(const Current&) const
{
return __Ice__Object_ids[0];
@@ -388,7 +392,7 @@ Ice::BlobjectAsync::__dispatch(Incoming& in, const Current& current)
auto async = IncomingAsync::create(in);
try
{
- ice_invoke_async(vector<Byte>(inEncaps, inEncaps + sz),
+ ice_invoke_async(vector<Byte>(inEncaps, inEncaps + sz),
[async](bool ok, const vector<Byte>& outEncaps)
{
if(async->__validateResponse(ok))
@@ -470,7 +474,7 @@ Ice::BlobjectArrayAsync::__dispatch(Incoming& in, const Current& current)
auto async = IncomingAsync::create(in);
try
{
- ice_invoke_async(inEncaps,
+ ice_invoke_async(inEncaps,
[async](bool ok, const pair<const Byte*, const Byte*>& outEncaps)
{
if(async->__validateResponse(ok))
diff --git a/cpp/src/Ice/Value.cpp b/cpp/src/Ice/Value.cpp
index a489c5500be..f5a7f6b1bbf 100644
--- a/cpp/src/Ice/Value.cpp
+++ b/cpp/src/Ice/Value.cpp
@@ -54,14 +54,14 @@ const string __Ice__Object_ids[] =
}
-const string&
-Ice::Value::ice_staticId()
+string
+Ice::Value::ice_id() const
{
return __Ice__Object_ids[0];
}
const string&
-Ice::Value::ice_id() const
+Ice::Value::ice_staticId()
{
return __Ice__Object_ids[0];
}
diff --git a/cpp/src/IceUtil/UtilException.cpp b/cpp/src/IceUtil/UtilException.cpp
index 96bcc813958..7a9cfb9d776 100644
--- a/cpp/src/IceUtil/UtilException.cpp
+++ b/cpp/src/IceUtil/UtilException.cpp
@@ -23,7 +23,7 @@
//
// For UINTPTR_MAX on Ubuntu Precise
//
-#ifndef __STDC_LIMIT_MACROS
+#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
#endif
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 8197c7612c8..ce2b2690324 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -1254,6 +1254,55 @@ Slice::writeEndCode(Output& out, const ParamDeclList& params, const OperationPtr
}
}
+void
+Slice::writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output& C,
+ const string& holder,
+ const DataMemberPtr& p,
+ bool marshal)
+{
+ writeMarshalUnmarshalCode(C, p->type(), p->optional(), p->tag(), holder + fixKwd(p->name()), marshal,
+ p->getMetaData());
+}
+
+void
+Slice::writeStreamHelpers(Output& out, const ContainedPtr& c, DataMemberList dataMembers, bool checkClassMetaData)
+{
+ string scoped = c->scoped();
+ bool classMetaData = false;
+
+ if(checkClassMetaData)
+ {
+ classMetaData = findMetaData(c->getMetaData(), false) == "%class";
+ }
+
+ string fullName = classMetaData ? fixKwd(scoped + "Ptr") : fixKwd(scoped);
+ string holder = classMetaData ? "v->" : "v.";
+
+ out << nl << "template<typename S>";
+ out << nl << "struct StreamWriter< " << fullName << ", S>";
+ out << sb;
+ out << nl << "static void write(S* __os, const " << fullName << "& v)";
+ out << sb;
+ for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ writeMarshalUnmarshalDataMemberInHolder(out, holder, *q, true);
+ }
+ out << eb;
+ out << eb << ";" << nl;
+
+ out << nl << "template<typename S>";
+ out << nl << "struct StreamReader< " << fullName << ", S>";
+ out << sb;
+ out << nl << "static void read(S* __is, " << fullName << "& v)";
+ out << sb;
+ for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ writeMarshalUnmarshalDataMemberInHolder(out, holder, *q, false);
+ }
+ out << eb;
+ out << eb << ";" << nl;
+}
+
bool
Slice::findMetaData(const string& prefix, const ClassDeclPtr& cl, string& value)
{
diff --git a/cpp/src/Slice/CPlusPlusUtil.h b/cpp/src/Slice/CPlusPlusUtil.h
index 5a3ad0f4b14..60eaf710c71 100644
--- a/cpp/src/Slice/CPlusPlusUtil.h
+++ b/cpp/src/Slice/CPlusPlusUtil.h
@@ -57,6 +57,8 @@ void writeAllocateCode(::IceUtilInternal::Output&, const ParamDeclList&, const O
std::string getEndArg(const TypePtr&, const StringList&, const std::string&);
void writeEndCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool = false);
+void writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberPtr&, bool);
+void writeStreamHelpers(::IceUtilInternal::Output&, const ContainedPtr&, DataMemberList, bool = false);
bool findMetaData(const std::string&, const ClassDeclPtr&, std::string&);
bool findMetaData(const std::string&, const StringList&, std::string&);
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 68728049a89..8dce5096a56 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -1649,7 +1649,26 @@ Slice::Container::hasNonLocalExceptions() const
return false;
}
+bool
+Slice::Container::hasExceptions() const
+{
+ for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p)
+ {
+ ExceptionPtr q = ExceptionPtr::dynamicCast(*p);
+ if(q)
+ {
+ return true;
+ }
+ ContainerPtr container = ContainerPtr::dynamicCast(*p);
+ if(container && container->hasExceptions())
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
bool
Slice::Container::hasClassDecls() const
diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h
index a142ec921d0..ece0c696e02 100644
--- a/cpp/src/Slice/Parser.h
+++ b/cpp/src/Slice/Parser.h
@@ -448,6 +448,7 @@ public:
bool hasLocalClassDefsWithAsync() const;
bool hasNonLocalSequences() const;
bool hasNonLocalExceptions() const;
+ bool hasExceptions() const;
bool hasDictionaries() const;
bool hasOnlyDictionaries(DictionaryList&) const;
bool hasClassDecls() const;
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 0f603adfe61..43f570889fd 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -427,37 +427,6 @@ writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const Synt
}
void
-writeMarshalUnmarshalDataMember(IceUtilInternal::Output& C, const DataMemberPtr& p, bool marshal)
-{
- writeMarshalUnmarshalCode(C, p->type(), p->optional(), p->tag(), fixKwd(p->name()), marshal, p->getMetaData());
-}
-
-void
-writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output& C, const string& holder, const DataMemberPtr& p, bool marshal)
-{
- writeMarshalUnmarshalCode(C, p->type(), p->optional(), p->tag(), holder + fixKwd(p->name()), marshal, p->getMetaData());
-}
-
-void
-writeMarshalUnmarshalDataMembers(IceUtilInternal::Output& C,
- const DataMemberList& dataMembers,
- const DataMemberList& optionalDataMembers,
- bool marshal)
-{
- for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
- {
- if(!(*q)->optional())
- {
- writeMarshalUnmarshalDataMember(C, *q, marshal);
- }
- }
- for(DataMemberList::const_iterator q = optionalDataMembers.begin(); q != optionalDataMembers.end(); ++q)
- {
- writeMarshalUnmarshalDataMember(C, *q, marshal);
- }
-}
-
-void
writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& members, int useWstring, bool cpp11 = false)
{
bool first = true;
@@ -729,6 +698,11 @@ Slice::Gen::generate(const UnitPtr& p)
H << "\n#include <IceUtil/ScopedArray.h>";
H << "\n#include <IceUtil/Optional.h>";
+ if(p->hasExceptions())
+ {
+ H << "\n#include <Ice/ExceptionHelpers.h>";
+ }
+
if(p->usesNonLocals())
{
C << "\n#include <Ice/InputStream.h>";
@@ -812,9 +786,6 @@ Slice::Gen::generate(const UnitPtr& p)
Cpp11TypesVisitor typesVisitor(H, C, _dllExport);
p->visit(&typesVisitor, false);
- Cpp11StreamVisitor streamVisitor(H, C, _dllExport);
- p->visit(&streamVisitor, false);
-
Cpp11ProxyVisitor proxyVisitor(H, C, _dllExport);
p->visit(&proxyVisitor, false);
@@ -827,6 +798,9 @@ Slice::Gen::generate(const UnitPtr& p)
Cpp11ValueVisitor valueVisitor(H, C, _dllExport);
p->visit(&valueVisitor, false);
+ Cpp11StreamVisitor streamVisitor(H, C, _dllExport);
+ p->visit(&streamVisitor, false);
+
if(_implCpp11)
{
implH << "\n#include <";
@@ -873,9 +847,6 @@ Slice::Gen::generate(const UnitPtr& p)
TypesVisitor typesVisitor(H, C, _dllExport);
p->visit(&typesVisitor, false);
- StreamVisitor streamVisitor(H, C, _dllExport);
- p->visit(&streamVisitor, false);
-
AsyncVisitor asyncVisitor(H, C, _dllExport);
p->visit(&asyncVisitor, false);
@@ -897,6 +868,9 @@ Slice::Gen::generate(const UnitPtr& p)
ObjectVisitor objectVisitor(H, C, _dllExport);
p->visit(&objectVisitor, false);
+ StreamVisitor streamVisitor(H, C, _dllExport);
+ p->visit(&streamVisitor, false);
+
//
// We need to delay generating the template after the proxy
// definition, because completed calls the begin_ method in the
@@ -1271,8 +1245,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
H << nl << "virtual void __readImpl(::Ice::InputStream*);";
string baseName = base ? fixKwd(base->scoped()) : string("::Ice::UserException");
- //H << nl << "using " << baseName << "::__writeImpl;";
- //H << nl << "using " << baseName << "::__readImpl;";
if(preserved && !basePreserved)
{
@@ -1297,7 +1269,8 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
C << sp << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::Ice::OutputStream* __os) const";
C << sb;
C << nl << "__os->startSlice(\"" << p->scoped() << "\", -1, " << (!base ? "true" : "false") << ");";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
+ C << nl << "Ice::StreamWriter<" << scoped.substr(2) << ", ::Ice::OutputStream>::write(__os, *this);";
+
C << nl << "__os->endSlice();";
if(base)
{
@@ -1308,7 +1281,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
C << sp << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::Ice::InputStream* __is)";
C << sb;
C << nl << "__is->startSlice();";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
+ C << nl << "Ice::StreamReader<" << scoped.substr(2) << ", ::Ice::InputStream>::read(__is, *this);";
C << nl << "__is->endSlice();";
if(base)
{
@@ -2811,7 +2784,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
StringList allOpNames;
transform(allOps.begin(), allOps.end(), back_inserter(allOpNames),
::IceUtil::constMemFun(&Contained::name));
-
+
allOpNames.push_back("ice_id");
allOpNames.push_back("ice_ids");
allOpNames.push_back("ice_isA");
@@ -2962,6 +2935,11 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
string baseName = base ? fixKwd(base->scoped()) : string("::Ice::Object");
H << nl << "using " << baseName << "::__writeImpl;";
H << nl << "using " << baseName << "::__readImpl;";
+ H << sp;
+ H << nl << "template<typename T, typename S>";
+ H << nl << "friend struct Ice::StreamWriter;";
+ H << nl << "template<typename T, typename S>";
+ H << nl << "friend struct Ice::StreamReader;";
if(preserved && !basePreserved)
{
@@ -2986,7 +2964,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
C << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::Ice::OutputStream* __os) const";
C << sb;
C << nl << "__os->startSlice(ice_staticId(), " << p->compactId() << (!base ? ", true" : ", false") << ");";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
+ C << nl << "Ice::StreamWriter<" << scoped.substr(2) << ", ::Ice::OutputStream>::write(__os, *this);";
C << nl << "__os->endSlice();";
if(base)
{
@@ -2998,7 +2976,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
C << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::Ice::InputStream* __is)";
C << sb;
C << nl << "__is->startSlice();";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
+ C << nl << "Ice::StreamReader<" << scoped.substr(2) << ", ::Ice::InputStream>::read(__is, *this);";
C << nl << "__is->endSlice();";
if(base)
{
@@ -4733,6 +4711,7 @@ Slice::Gen::StreamVisitor::visitModuleStart(const ModulePtr& m)
{
if(!m->hasNonLocalContained(Contained::ContainedTypeStruct) &&
!m->hasNonLocalContained(Contained::ContainedTypeEnum) &&
+ !m->hasNonLocalContained(Contained::ContainedTypeClass) &&
!m->hasNonLocalContained(Contained::ContainedTypeException))
{
return false;
@@ -4767,6 +4746,16 @@ Slice::Gen::StreamVisitor::visitModuleEnd(const ModulePtr& m)
}
bool
+Slice::Gen::StreamVisitor::visitClassDefStart(const ClassDefPtr& c)
+{
+ if(!c->isLocal())
+ {
+ writeStreamHelpers(H, c, c->dataMembers(), true);
+ }
+ return false;
+}
+
+bool
Slice::Gen::StreamVisitor::visitExceptionStart(const ExceptionPtr& p)
{
if(!p->isLocal())
@@ -4777,6 +4766,8 @@ Slice::Gen::StreamVisitor::visitExceptionStart(const ExceptionPtr& p)
H << sb;
H << nl << "static const StreamHelperCategory helper = StreamHelperCategoryUserException;";
H << eb << ";" << nl;
+
+ writeStreamHelpers(H, p, p->dataMembers(), true);
}
return false;
}
@@ -4815,33 +4806,7 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p)
}
H << eb << ";" << nl;
- DataMemberList dataMembers = p->dataMembers();
-
- string holder = classMetaData ? "v->" : "v.";
-
- H << nl << "template<class S>";
- H << nl << "struct StreamWriter< " << fullStructName << ", S>";
- H << sb;
- H << nl << "static void write(S* __os, const " << fullStructName << "& v)";
- H << sb;
- for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
- {
- writeMarshalUnmarshalDataMemberInHolder(H, holder, *q, true);
- }
- H << eb;
- H << eb << ";" << nl;
-
- H << nl << "template<class S>";
- H << nl << "struct StreamReader< " << fullStructName << ", S>";
- H << sb;
- H << nl << "static void read(S* __is, " << fullStructName << "& v)";
- H << sb;
- for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
- {
- writeMarshalUnmarshalDataMemberInHolder(H, holder, *q, false);
- }
- H << eb;
- H << eb << ";" << nl;
+ writeStreamHelpers(H, p, p->dataMembers(), true);
}
return false;
}
@@ -5425,18 +5390,12 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
}
}
- H << sp << nl << "class " << _dllExport << name << " : ";
- H.useCurrentPosAsIndent();
- H << "public ";
- if(!base)
- {
- H << (p->isLocal() ? "::Ice::LocalException" : "::Ice::UserException");
- }
- else
- {
- H << fixKwd(base->scoped());
- }
- H.restoreIndent();
+ string helperClass = p->isLocal() ? "Ice::LocalExceptionHelper" : "Ice::UserExceptionHelper";
+ string baseClass = base ? fixKwd(base->scoped()) : (p->isLocal() ? "::Ice::LocalException" : "::Ice::UserException");
+ string templateParameters = name + ", " + baseClass;
+
+ H << sp << nl;
+ H << "class " << _dllExport << name << " : public ::" << helperClass << "<" << templateParameters << ">";
H << sb;
H.dec();
@@ -5446,7 +5405,8 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
if(p->isLocal())
{
H << sp << nl << name << "(const char* __ice_file, int __ice_line) : ";
- H << (base ? fixKwd(base->scoped()) : "::Ice::LocalException") << "(__ice_file, __ice_line)";
+ H << "::Ice::LocalExceptionHelper" << "<" << templateParameters << ">";
+ H << "(__ice_file, __ice_line)";
H << sb;
H << eb;
}
@@ -5494,7 +5454,7 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
H.inc();
if(base && (p->isLocal() || !baseDataMembers.empty()))
{
- H << nl << fixKwd(base->scoped()) << "(";
+ H << nl << "::" << helperClass << "<" << templateParameters << ">" << "(";
if(p->isLocal())
{
H << "__ice_file, __ice_line";
@@ -5528,7 +5488,8 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
}
else if(p->isLocal())
{
- H << nl << "::Ice::LocalException(__ice_file, __ice_line)";
+ H << " ::Ice::LocalExceptionHelper" << "<" << templateParameters << ">";
+ H << "(__ice_file, __ice_line)";
if(!dataMembers.empty())
{
H << ",";
@@ -5557,12 +5518,22 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
}
H << sp;
- H << nl << "virtual ::std::string ice_id() const;";
- C << sp << nl << "::std::string" << nl << scoped.substr(2) << "::ice_id() const";
+ H << nl << "static const ::std::string& ice_staticId();";
+
+ if(p->isLocal())
+ {
+ C << sp << nl << "namespace" << sb;
+ C.dec();
+ C << nl << "const std::string " << p->flattenedScope() << p->name() << "_id = \"" << p->scoped() << "\";";
+ C.inc();
+ C << eb;
+ }
+
+ C << sp << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_staticId()";
C << sb;
if(p->isLocal())
{
- C << nl << "return \"" << p->scoped() << "\";" << ";";
+ C << nl << "return " << p->flattenedScope() << p->name() << "_id;";
}
else
{
@@ -5576,12 +5547,6 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
H << nl << "virtual void ice_print(::std::ostream&) const;";
}
- H << nl << "virtual void ice_throw() const;";
- C << sp << nl << "void" << nl << scoped.substr(2) << "::ice_throw() const";
- C << sb;
- C << nl << "throw *this;";
- C << eb;
-
if(!p->isLocal() && p->usesClasses(false))
{
if(!base || (base && !base->usesClasses(false)))
@@ -5616,7 +5581,6 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
ExceptionPtr base = p->base();
bool basePreserved = p->inheritsMetaData("preserve-slice");
bool preserved = p->hasMetaData("preserve-slice");
- string typeId = p->flattenedScope() + p->name() + "_init.typeId";
if(preserved && !basePreserved)
{
@@ -5624,13 +5588,6 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
H << nl << "virtual void __read(::Ice::InputStream*);";
}
- H.dec();
- H << sp << nl << "protected:";
- H.inc();
- H << sp;
- H << nl << "virtual void __writeImpl(::Ice::OutputStream*) const;";
- H << nl << "virtual void __readImpl(::Ice::InputStream*);";
-
if(preserved && !basePreserved)
{
H << sp << nl << "::std::shared_ptr<::Ice::SlicedData> __slicedData;";
@@ -5649,28 +5606,6 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
C << nl << "__slicedData = __is->endException(true);";
C << eb;
}
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::Ice::OutputStream* __os) const";
- C << sb;
- C << nl << "__os->startSlice(" << typeId << ", -1, " << (!base ? "true" : "false") << ");";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
- C << nl << "__os->endSlice();";
- if(base)
- {
- emitUpcall(base, "::__writeImpl(__os);");
- }
- C << eb;
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::Ice::InputStream* __is)";
- C << sb;
- C << nl << "__is->startSlice();";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
- C << nl << "__is->endSlice();";
- if(base)
- {
- emitUpcall(base, "::__readImpl(__is);");
- }
- C << eb;
}
H << eb << ';';
@@ -6993,7 +6928,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitClassDefStart(const ClassDefPtr& p)
H << sp;
H << nl << "virtual bool ice_isA(::std::string, const ::Ice::Current& = ::Ice::noExplicitCurrent) const;";
H << nl << "virtual ::std::vector< ::std::string> ice_ids(const ::Ice::Current& = ::Ice::noExplicitCurrent) const;";
- H << nl << "virtual const ::std::string& ice_id(const ::Ice::Current& = ::Ice::noExplicitCurrent) const;";
+ H << nl << "virtual ::std::string ice_id(const ::Ice::Current& = ::Ice::noExplicitCurrent) const;";
H << nl << "static const ::std::string& ice_staticId();";
string flatName = p->flattenedScope() + p->name() + "_ids";
@@ -7011,7 +6946,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitClassDefStart(const ClassDefPtr& p)
C << eb;
C << sp;
- C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_id(const ::Ice::Current&) const";
+ C << nl << "::std::string" << nl << scoped.substr(2) << "::ice_id(const ::Ice::Current&) const";
C << sb;
C << nl << "return " << flatName << '[' << scopedPos << "];";
C << eb;
@@ -7523,9 +7458,12 @@ Slice::Gen::Cpp11ValueVisitor::visitClassDefEnd(const ClassDefPtr& p)
H.dec();
H << sp << nl << "protected:";
H.inc();
+
H << sp;
- H << nl << "virtual void __writeImpl(::Ice::OutputStream*) const;";
- H << nl << "virtual void __readImpl(::Ice::InputStream*);";
+ H << nl << "template<typename T, typename S>";
+ H << nl << "friend struct Ice::StreamWriter;";
+ H << nl << "template<typename T, typename S>";
+ H << nl << "friend struct Ice::StreamReader;";
if(preserved && !basePreserved)
{
@@ -7547,30 +7485,6 @@ Slice::Gen::Cpp11ValueVisitor::visitClassDefEnd(const ClassDefPtr& p)
}
C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::Ice::OutputStream* __os) const";
- C << sb;
- C << nl << "__os->startSlice(" << typeId << ", " << p->compactId() << (!base ? ", true" : ", false") << ");";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
- C << nl << "__os->endSlice();";
- if(base)
- {
- emitUpcall(base, "::__writeImpl(__os);");
- }
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::Ice::InputStream* __is)";
- C << sb;
- C << nl << "__is->startSlice();";
- writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
- C << nl << "__is->endSlice();";
- if(base)
- {
- emitUpcall(base, "::__readImpl(__is);");
- }
- C << eb;
-
- C << sp;
C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_staticId()";
C << sb;
C << nl << "return " << typeId << ";";
@@ -7769,7 +7683,9 @@ bool
Slice::Gen::Cpp11StreamVisitor::visitModuleStart(const ModulePtr& m)
{
if(!m->hasNonLocalContained(Contained::ContainedTypeStruct) &&
- !m->hasNonLocalContained(Contained::ContainedTypeEnum))
+ !m->hasNonLocalContained(Contained::ContainedTypeEnum) &&
+ !m->hasNonLocalContained(Contained::ContainedTypeException) &&
+ !m->hasNonLocalContained(Contained::ContainedTypeClass))
{
return false;
}
@@ -7825,33 +7741,28 @@ Slice::Gen::Cpp11StreamVisitor::visitStructStart(const StructPtr& p)
H << nl << "static const bool fixedLength = " << (p->isVariableLength() ? "false" : "true") << ";";
H << eb << ";" << nl;
- DataMemberList dataMembers = p->dataMembers();
+ writeStreamHelpers(H, p, p->dataMembers());
- H << nl << "template<class S>";
- H << nl << "struct StreamWriter<" << scoped << ", S>";
- H << sb;
- H << nl << "static void write(S* __os, const " << scoped << "& v)";
- H << sb;
- for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ return false;
+}
+
+bool
+Slice::Gen::Cpp11StreamVisitor::visitClassDefStart(const ClassDefPtr& c)
+{
+ if(!c->isLocal() && !c->isInterface())
{
- writeMarshalUnmarshalDataMemberInHolder(H, "v.", *q, true);
+ writeStreamHelpers(H, c, c->dataMembers(), true);
}
- H << eb;
- H << eb << ";" << nl;
+ return false;
+}
- H << nl << "template<class S>";
- H << nl << "struct StreamReader<" << scoped << ", S>";
- H << sb;
- H << nl << "static void read(S* __is, " << scoped << "& v)";
- H << sb;
- for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+void
+Slice::Gen::Cpp11StreamVisitor::visitExceptionEnd(const ExceptionPtr& p)
+{
+ if(!p->isLocal())
{
- writeMarshalUnmarshalDataMemberInHolder(H, "v.", *q, false);
+ writeStreamHelpers(H, p, p->dataMembers(), true);
}
- H << eb;
- H << eb << ";" << nl;
-
- return false;
}
void
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index 9e1d6a76283..1e45e246fb3 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -329,6 +329,7 @@ private:
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
virtual bool visitStructStart(const StructPtr&);
+ virtual bool visitClassDefStart(const ClassDefPtr&);
virtual bool visitExceptionStart(const ExceptionPtr&);
virtual void visitEnum(const EnumPtr&);
@@ -561,6 +562,8 @@ private:
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
virtual bool visitStructStart(const StructPtr&);
+ virtual bool visitClassDefStart(const ClassDefPtr&);
+ virtual void visitExceptionEnd(const ExceptionPtr&);
virtual void visitEnum(const EnumPtr&);
private: