diff options
author | Mark Spruiell <mes@zeroc.com> | 2004-10-19 02:27:18 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2004-10-19 02:27:18 +0000 |
commit | 4ee06da3e23c279897cef5b2b51487875b4486b7 (patch) | |
tree | e2080691778256ebf32ceabc7d8edce6e869fbad /cpp/src/slice2cpp/Gen.cpp | |
parent | updating dependencies (diff) | |
download | ice-4ee06da3e23c279897cef5b2b51487875b4486b7.tar.bz2 ice-4ee06da3e23c279897cef5b2b51487875b4486b7.tar.xz ice-4ee06da3e23c279897cef5b2b51487875b4486b7.zip |
adding streaming API
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 350 |
1 files changed, 335 insertions, 15 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 5e66e89e292..369e86b6c7d 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -22,7 +22,7 @@ using namespace IceUtil; Slice::Gen::Gen(const string& name, const string& base, const string& headerExtension, const string& sourceExtension, const string& include, const vector<string>& includePaths, - const string& dllExport, const string& dir, bool imp, bool checksum) : + const string& dllExport, const string& dir, bool imp, bool checksum, bool stream) : _base(base), _headerExtension(headerExtension), _sourceExtension(sourceExtension), @@ -30,7 +30,8 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte _includePaths(includePaths), _dllExport(dllExport), _impl(imp), - _checksum(checksum) + _checksum(checksum), + _stream(stream) { for(vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) { @@ -192,6 +193,11 @@ Slice::Gen::generate(const UnitPtr& p) H << "\n#include <Ice/IncomingAsync.h>"; } H << "\n#include <Ice/Direct.h>"; + if(_stream) + { + H << "\n#include <Ice/StreamF.h>"; + C << "\n#include <Ice/Stream.h>"; + } C << "\n#include <Ice/LocalException.h>"; C << "\n#include <Ice/ObjectFactory.h>"; @@ -243,10 +249,10 @@ Slice::Gen::generate(const UnitPtr& p) IceInternalVisitor iceInternalVisitor(H, C, _dllExport); p->visit(&iceInternalVisitor, false); - HandleVisitor handleVisitor(H, C, _dllExport); + HandleVisitor handleVisitor(H, C, _dllExport, _stream); p->visit(&handleVisitor, false); - TypesVisitor typesVisitor(H, C, _dllExport); + TypesVisitor typesVisitor(H, C, _dllExport, _stream); p->visit(&typesVisitor, false); AsyncVisitor asyncVisitor(H, C, _dllExport); @@ -267,7 +273,7 @@ Slice::Gen::generate(const UnitPtr& p) DelegateDVisitor delegateDVisitor(H, C, _dllExport); p->visit(&delegateDVisitor, false); - ObjectVisitor objectVisitor(H, C, _dllExport); + ObjectVisitor objectVisitor(H, C, _dllExport, _stream); p->visit(&objectVisitor, false); if(_impl) @@ -316,8 +322,8 @@ Slice::Gen::generate(const UnitPtr& p) } } -Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport) +Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport, bool stream) : + H(h), C(c), _dllExport(dllExport), _stream(stream) { } @@ -453,6 +459,12 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) H << sp << nl << "virtual void __write(::IceInternal::BasicStream*) const;"; H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);"; + if(_stream) + { + H << sp << nl << "virtual void __write(const ::Ice::OutputStreamPtr&) const;"; + H << nl << "virtual void __read(const ::Ice::InputStreamPtr&, bool);"; + } + TypeStringList memberList; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { @@ -506,6 +518,57 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } C << eb; + if(_stream) + { + C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __out) const"; + C << sb; + C << nl << "__out->writeString(::std::string(\"" << p->scoped() << "\"));"; + C << nl << "__out->startSlice();"; + writeStreamMarshalCode(C, memberList, 0); + C << nl << "__out->endSlice();"; + if(base) + { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << fixKwd(base->name()) << "::__write(__out);"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); + C << nl << fixKwd(base->scoped()) << "::__write(__out);"; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); + } + C << eb; + + C << sp << nl << "void" << nl << scoped.substr(2) + << "::__read(const ::Ice::InputStreamPtr& __in, bool __rid)"; + C << sb; + C << nl << "if(__rid)"; + C << sb; + C << nl << "__in->readString();"; + C << eb; + C << nl << "__in->startSlice();"; + writeStreamUnmarshalCode(C, memberList, 0); + C << nl << "__in->endSlice();"; + if(base) + { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << fixKwd(base->name()) << "::__read(__in, true);"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); + C << nl << fixKwd(base->scoped()) << "::__read(__in, true);"; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); + } + C << eb; + } + if(p->usesClasses()) { if(!base || (base && !base->usesClasses())) @@ -649,6 +712,12 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) H << sp << nl << _dllExport << "void __write(::IceInternal::BasicStream*) const;"; H << nl << _dllExport << "void __read(::IceInternal::BasicStream*);"; + if(_stream) + { + H << sp << nl << _dllExport << "void __write(const ::Ice::OutputStreamPtr&) const;"; + H << nl << _dllExport << "void __read(const ::Ice::InputStreamPtr&);"; + } + TypeStringList memberList; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { @@ -663,9 +732,41 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) C << sb; writeUnmarshalCode(C, memberList, 0); C << eb; + + if(_stream) + { + C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __out) const"; + C << sb; + writeStreamMarshalCode(C, memberList, 0); + C << eb; + + C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr& __in)"; + C << sb; + writeStreamUnmarshalCode(C, memberList, 0); + C << eb; + } } H << eb << ';'; + + if(!p->isLocal() && _stream) + { + H << sp << nl << _dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " + << name << "&);"; + H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name << "&);"; + + C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() + << "(const ::Ice::OutputStreamPtr& __out, const " << scoped << "& __v)"; + C << sb; + C << nl << "__v.__write(__out);"; + C << eb; + + C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name() + << "(const ::Ice::InputStreamPtr& __in, " << scoped << "& __v)"; + C << sb; + C << nl << "__v.__read(__in);"; + C << eb; + } } void @@ -700,6 +801,13 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) << ");"; H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "&, __U__" << name << ");"; + if(_stream) + { + H << nl << _dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " + << name << "&);"; + H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name << "&);"; + } + C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, const " << scoped << "& v, " << scope << "__U__" << name << ")"; C << sb; @@ -746,6 +854,31 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) C << eb; C << nl << "__is->endSeq(sz);"; C << eb; + + if(_stream) + { + C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() + << "(const ::Ice::OutputStreamPtr& __out, const " << scoped << "& v)"; + C << sb; + C << nl << "__out->writeSize(::Ice::Int(v.size()));"; + C << nl << scoped << "::const_iterator p;"; + C << nl << "for(p = v.begin(); p != v.end(); ++p)"; + C << sb; + writeStreamMarshalUnmarshalCode(C, type, "(*p)", true); + C << eb; + C << eb; + + C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name() + << "(const ::Ice::InputStreamPtr& __in, " << scoped << "& v)"; + C << sb; + C << nl << "::Ice::Int sz = __in->readSize();"; + C << nl << "v.resize(sz);"; + C << nl << "for(int i = 0; i < sz; ++i)"; + C << sb; + writeStreamMarshalUnmarshalCode(C, type, "v[i]", false); + C << eb; + C << eb; + } } } @@ -774,6 +907,13 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "&, __U__" << name << ");"; + if(_stream) + { + H << nl << _dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " << name + << "&);"; + H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name << "&);"; + } + C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, const " << scoped << "& v, " << scope << "__U__" << name << ")"; C << sb; @@ -800,6 +940,35 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) writeMarshalUnmarshalCode(C, valueType, "__i->second", false); C << eb; C << eb; + + if(_stream) + { + C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() + << "(const ::Ice::OutputStreamPtr& __out, const " << scoped << "& v)"; + C << sb; + C << nl << "__out->writeSize(::Ice::Int(v.size()));"; + C << nl << scoped << "::const_iterator p;"; + C << nl << "for(p = v.begin(); p != v.end(); ++p)"; + C << sb; + writeStreamMarshalUnmarshalCode(C, keyType, "p->first", true); + writeStreamMarshalUnmarshalCode(C, valueType, "p->second", true); + C << eb; + C << eb; + + C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name() + << "(const ::Ice::InputStreamPtr& __in, " << scoped << "& v)"; + C << sb; + C << nl << "::Ice::Int sz = __in->readSize();"; + C << nl << "while(sz--)"; + C << sb; + C << nl << "::std::pair<const " << ks << ", " << vs << "> pair;"; + string pf = string("const_cast<") + ks + "&>(pair.first)"; + writeStreamMarshalUnmarshalCode(C, keyType, pf, false); + C << nl << scoped << "::iterator __i = v.insert(v.end(), pair);"; + writeStreamMarshalUnmarshalCode(C, valueType, "__i->second", false); + C << eb; + C << eb; + } } } @@ -832,6 +1001,13 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) H << sp << nl << _dllExport << "void __write(::IceInternal::BasicStream*, " << name << ");"; H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "&);"; + if(_stream) + { + H << sp << nl << _dllExport << "void ice_write" << p->name() + << "(const ::Ice::OutputStreamPtr&, " << name << ");"; + H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name << "&);"; + } + C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, " << scoped << " v)"; C << sb; @@ -871,6 +1047,46 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) C << nl << "v = static_cast< " << scoped << ">(val);"; } C << eb; + + if(_stream) + { + C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() + << "(const ::Ice::OutputStreamPtr& __out, " << scoped << " v)"; + C << sb; + if(sz <= 0x7f) + { + C << nl << "__out->writeByte(static_cast< ::Ice::Byte>(v));"; + } + else if(sz <= 0x7fff) + { + C << nl << "__out->writeShort(static_cast< ::Ice::Short>(v));"; + } + else + { + C << nl << "__out->writeInt(static_cast< ::Ice::Int>(v));"; + } + C << eb; + + C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name() + << "(const ::Ice::InputStreamPtr& __in, " << scoped << "& v)"; + C << sb; + if(sz <= 0x7f) + { + C << nl << "::Ice::Byte val = __in->readByte();"; + C << nl << "v = static_cast< " << scoped << ">(val);"; + } + else if(sz <= 0x7fff) + { + C << nl << "::Ice::Short val = __in->readShort();"; + C << nl << "v = static_cast< " << scoped << ">(val);"; + } + else + { + C << nl << "::Ice::Int val = __in->readInt();"; + C << nl << "v = static_cast< " << scoped << ">(val);"; + } + C << eb; + } } } @@ -1857,8 +2073,8 @@ Slice::Gen::ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p) H << nl << _dllExport << "bool operator<(const " << name << "&, const " << name << "&);"; } -Slice::Gen::ObjectVisitor::ObjectVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport) +Slice::Gen::ObjectVisitor::ObjectVisitor(Output& h, Output& c, const string& dllExport, bool stream) : + H(h), C(c), _dllExport(dllExport), _stream(stream) { } @@ -2152,6 +2368,11 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) H << sp; H << nl << "virtual void __write(::IceInternal::BasicStream*) const;"; H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);"; + if(_stream) + { + H << nl << "virtual void __write(const ::Ice::OutputStreamPtr&) const;"; + H << nl << "virtual void __read(const ::Ice::InputStreamPtr&, bool);"; + } TypeStringList memberList; DataMemberList dataMembers = p->dataMembers(); @@ -2203,6 +2424,51 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) C.restoreIndent(); C << eb; + if(_stream) + { + C << sp; + C << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __out) const"; + C << sb; + C << nl << "__out->writeTypeId(ice_staticId());"; + C << nl << "__out->startSlice();"; + writeStreamMarshalCode(C, memberList, 0); + C << nl << "__out->endSlice();"; + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << (base ? fixKwd(base->name()) : "Object") << "::__write(__out);"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); + C << nl << (base ? fixKwd(base->scoped()) : "::Ice::Object") << "::__write(__out);"; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); + C << eb; + C << sp; + C << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr& __in, bool __rid)"; + C << sb; + C << nl << "if(__rid)"; + C << sb; + C << nl << "__in->readTypeId();"; + C << eb; + C << nl << "__in->startSlice();"; + writeStreamUnmarshalCode(C, memberList, 0); + C << nl << "__in->endSlice();"; + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << (base ? fixKwd(base->name()) : "Object") << "::__read(__in, true);"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); + C << nl << (base ? fixKwd(base->scoped()) : "::Ice::Object") << "::__read(__in, true);"; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); + C << eb; + } + if(!p->isAbstract()) { H << sp << nl << "static const ::Ice::ObjectFactoryPtr& ice_factory();"; @@ -2912,8 +3178,8 @@ Slice::Gen::IceInternalVisitor::visitClassDefStart(const ClassDefPtr& p) return true; } -Slice::Gen::HandleVisitor::HandleVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport) +Slice::Gen::HandleVisitor::HandleVisitor(Output& h, Output& c, const string& dllExport, bool stream) : + H(h), C(c), _dllExport(dllExport), _stream(stream) { } @@ -2956,8 +3222,19 @@ Slice::Gen::HandleVisitor::visitClassDecl(const ClassDeclPtr& p) H << nl << _dllExport << "void __write(::IceInternal::BasicStream*, const " << name << "Prx&);"; H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "Prx&);"; H << nl << _dllExport << "void __write(::IceInternal::BasicStream*, const " << name << "Ptr&);"; - H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "Ptr&);"; H << nl << _dllExport << "void __patch__" << name << "Ptr(void*, ::Ice::ObjectPtr&);"; + if(_stream) + { + H << sp; + H << nl << _dllExport << "void ice_write" << name << "Prx(const ::Ice::OutputStreamPtr&, const " << name + << "Prx&);"; + H << nl << _dllExport << "void ice_read" << name << "Prx(const ::Ice::InputStreamPtr&, " << name + << "Prx&);"; + + H << nl << _dllExport << "void ice_write" << name << "(const ::Ice::OutputStreamPtr&, const " + << name << "Ptr&);"; + H << nl << _dllExport << "void ice_read" << name << "(const ::Ice::InputStreamPtr&, " << name << "Ptr&);"; + } } } @@ -2966,6 +3243,7 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) { if(!p->isLocal()) { + string name = p->name(); string scoped = fixKwd(p->scoped()); string scope = fixKwd(p->scope()); @@ -2984,14 +3262,14 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) C << sp; C << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, const " - << scope << p->name() << "Prx& v)"; + << scope << name << "Prx& v)"; C << sb; C << nl << "__os->write(::Ice::ObjectPrx(v));"; C << eb; C << sp; C << nl << "void" << nl << scope.substr(2) << "__read(::IceInternal::BasicStream* __is, " - << scope << p->name() << "Prx& v)"; + << scope << name << "Prx& v)"; C << sb; C << nl << "::Ice::ObjectPrx proxy;"; C << nl << "__is->read(proxy);"; @@ -3008,10 +3286,52 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) C << sp; C << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, const " - << scope << p->name() << "Ptr& v)"; + << scope << name << "Ptr& v)"; C << sb; C << nl << "__os->write(::Ice::ObjectPtr(v));"; C << eb; + + if(_stream) + { + C << sp; + C << nl << "void" << nl << scope.substr(2) << "ice_write" << name + << "Prx(const ::Ice::OutputStreamPtr& __out, const " << scope << name << "Prx& v)"; + C << sb; + C << nl << "__out->writeProxy(v);"; + C << eb; + + C << sp; + C << nl << "void" << nl << scope.substr(2) << "ice_read" << name + << "Prx(const ::Ice::InputStreamPtr& __in, " << scope << name << "Prx& v)"; + C << sb; + C << nl << "::Ice::ObjectPrx proxy = __in->readProxy();"; + C << nl << "if(!proxy)"; + C << sb; + C << nl << "v = 0;"; + C << eb; + C << nl << "else"; + C << sb; + C << nl << "v = new ::IceProxy" << scoped << ';'; + C << nl << "v->__copyFrom(proxy);"; + C << eb; + C << eb; + + C << sp; + C << nl << "void" << nl << scope.substr(2) << "ice_write" << name + << "(const ::Ice::OutputStreamPtr& __out, const " << scope << name << "Ptr& v)"; + C << sb; + C << nl << "__out->writeObject(v);"; + C << eb; + + C << sp; + C << nl << "void" << nl << scope.substr(2) << "ice_read" << name << "(const ::Ice::InputStreamPtr& __in, " + << scoped << "Ptr& __v)"; + C << sb; + C << nl << "::Ice::ReadObjectCallbackPtr __cb = new ::Ice::ReadObjectCallbackI(" << scope << "__patch__" + << name << "Ptr, &__v);"; + C << nl << "__in->readObject(__cb);"; + C << eb; + } } return true; |