summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/CPlusPlusUtil.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-02-06 14:21:00 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-02-06 14:21:00 +0000
commit79496603519f5356862f5bd537dd0b161d33d4be (patch)
tree9d445c1157b839098e3276dcaa10328b00866fc2 /cpp/src/Slice/CPlusPlusUtil.cpp
parentFixed one-shot constructors. (diff)
downloadice-79496603519f5356862f5bd537dd0b161d33d4be.tar.bz2
ice-79496603519f5356862f5bd537dd0b161d33d4be.tar.xz
ice-79496603519f5356862f5bd537dd0b161d33d4be.zip
Added support for alternate sequences Added custom test
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp252
1 files changed, 128 insertions, 124 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index e90809a334c..841e26d48ad 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -77,7 +77,7 @@ Slice::printHeader(Output& out)
static const char* header =
"// **********************************************************************\n"
"//\n"
-"// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.\n"
+"// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.\n"
"//\n"
"// This copy of Ice is licensed to you under the terms described in the\n"
"// ICE_LICENSE file included in this distribution.\n"
@@ -1048,7 +1048,7 @@ Slice::writeAllocateCode(Output& out, const ParamDeclList& params, const TypePtr
void
Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& param, bool marshal,
- const string& str)
+ const string& str, const StringList& metaData)
{
string fixedParam = fixKwd(param);
@@ -1233,127 +1233,157 @@ Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const s
SequencePtr seq = SequencePtr::dynamicCast(type);
if(seq)
{
- builtin = BuiltinPtr::dynamicCast(seq->type());
- if(!builtin || (builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindObjectProxy))
- {
- string scope = fixKwd(seq->scope());
- if(marshal)
- {
- out << nl << scope << "ice_write" << seq->name() << '(' << stream << ", " << fixedParam << ");";
- }
- else
- {
- out << nl << scope << "ice_read" << seq->name() << '(' << stream << ", " << fixedParam << ");";
- }
- }
- else
- {
- switch(builtin->kind())
+ string seqType = findMetaData(metaData, false);
+ if(!seqType.empty())
+ {
+ if(marshal)
+ {
+ out << nl << stream << "->writeSize(static_cast< ::Ice::Int>(" << fixedParam << ".size()));";
+ out << nl << seqType << "::const_iterator __" << fixedParam << ";";
+ out << nl << "for(__" << fixedParam << " = " << fixedParam << ".begin(); __" << fixedParam << " != "
+ << fixedParam << ".end(); ++__" << fixedParam << ")";
+ out << sb;
+ writeStreamMarshalUnmarshalCode(out, seq->type(), "(*__" + fixedParam + ")", true);
+ out << eb;
+ }
+ else
+ {
+ out << nl << seqType << "(static_cast< ::Ice::Int>(" << stream << "->readSize())).swap("
+ << fixedParam << ");";
+ out << nl << seqType << "::iterator __" << fixedParam << ";";
+ out << nl << "for(__" << fixedParam << " = " << fixedParam << ".begin(); __" << fixedParam << " != "
+ << fixedParam << ".end(); ++__" << fixedParam << ")";
+ out << sb;
+ writeStreamMarshalUnmarshalCode(out, seq->type(), "(*__" + fixedParam + ")", false);
+ out << eb;
+ }
+ }
+ else
+ {
+ seqType = findMetaData(seq->getMetaData(), false);
+ builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(!seqType.empty() || !builtin || (builtin->kind() == Builtin::KindObject ||
+ builtin->kind() == Builtin::KindObjectProxy))
{
- case Builtin::KindByte:
+ string scope = fixKwd(seq->scope());
+ if(marshal)
{
- if(marshal)
- {
- out << nl << stream << "->writeByteSeq(" << fixedParam << ");";
- }
- else
- {
- out << nl << fixedParam << " = " << stream << "->readByteSeq();";
- }
- break;
+ out << nl << scope << "ice_write" << seq->name() << '(' << stream << ", " << fixedParam << ");";
}
- case Builtin::KindBool:
+ else
{
- if(marshal)
- {
- out << nl << stream << "->writeBoolSeq(" << fixedParam << ");";
- }
- else
- {
- out << nl << fixedParam << " = " << stream << "->readBoolSeq();";
- }
- break;
+ out << nl << scope << "ice_read" << seq->name() << '(' << stream << ", " << fixedParam << ");";
}
- case Builtin::KindShort:
- {
- if(marshal)
- {
- out << nl << stream << "->writeShortSeq(" << fixedParam << ");";
- }
- else
- {
- out << nl << fixedParam << " = " << stream << "->readShortSeq();";
- }
- break;
- }
- case Builtin::KindInt:
+ }
+ else
+ {
+ switch(builtin->kind())
{
- if(marshal)
+ case Builtin::KindByte:
{
- out << nl << stream << "->writeIntSeq(" << fixedParam << ");";
+ if(marshal)
+ {
+ out << nl << stream << "->writeByteSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readByteSeq();";
+ }
+ break;
}
- else
+ case Builtin::KindBool:
{
- out << nl << fixedParam << " = " << stream << "->readIntSeq();";
+ if(marshal)
+ {
+ out << nl << stream << "->writeBoolSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readBoolSeq();";
+ }
+ break;
}
- break;
- }
- case Builtin::KindLong:
- {
- if(marshal)
+ case Builtin::KindShort:
{
- out << nl << stream << "->writeLongSeq(" << fixedParam << ");";
+ if(marshal)
+ {
+ out << nl << stream << "->writeShortSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readShortSeq();";
+ }
+ break;
}
- else
+ case Builtin::KindInt:
{
- out << nl << fixedParam << " = " << stream << "->readLongSeq();";
+ if(marshal)
+ {
+ out << nl << stream << "->writeIntSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readIntSeq();";
+ }
+ break;
}
- break;
- }
- case Builtin::KindFloat:
- {
- if(marshal)
+ case Builtin::KindLong:
{
- out << nl << stream << "->writeFloatSeq(" << fixedParam << ");";
+ if(marshal)
+ {
+ out << nl << stream << "->writeLongSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readLongSeq();";
+ }
+ break;
}
- else
+ case Builtin::KindFloat:
{
- out << nl << fixedParam << " = " << stream << "->readFloatSeq();";
+ if(marshal)
+ {
+ out << nl << stream << "->writeFloatSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readFloatSeq();";
+ }
+ break;
}
- break;
- }
- case Builtin::KindDouble:
- {
- if(marshal)
- {
- out << nl << stream << "->writeDoubleSeq(" << fixedParam << ");";
- }
- else
+ case Builtin::KindDouble:
{
- out << nl << fixedParam << " = " << stream << "->readDoubleSeq();";
+ if(marshal)
+ {
+ out << nl << stream << "->writeDoubleSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readDoubleSeq();";
+ }
+ break;
}
- break;
- }
- case Builtin::KindString:
- {
- if(marshal)
+ case Builtin::KindString:
{
- out << nl << stream << "->writeStringSeq(" << fixedParam << ");";
+ if(marshal)
+ {
+ out << nl << stream << "->writeStringSeq(" << fixedParam << ");";
+ }
+ else
+ {
+ out << nl << fixedParam << " = " << stream << "->readStringSeq();";
+ }
+ break;
}
- else
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ case Builtin::KindLocalObject:
{
- out << nl << fixedParam << " = " << stream << "->readStringSeq();";
+ assert(false);
+ break;
}
- break;
}
- case Builtin::KindObject:
- case Builtin::KindObjectProxy:
- case Builtin::KindLocalObject:
- {
- assert(false);
- break;
- }
- }
+ }
}
return;
@@ -1411,32 +1441,6 @@ Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const s
assert(false);
}
-void
-Slice::writeStreamMarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret)
-{
- for(list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p)
- {
- writeStreamMarshalUnmarshalCode(out, p->first, p->second, true, "");
- }
- if(ret)
- {
- writeStreamMarshalUnmarshalCode(out, ret, "__ret", true, "");
- }
-}
-
-void
-Slice::writeStreamUnmarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret)
-{
- for(list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p)
- {
- writeStreamMarshalUnmarshalCode(out, p->first, p->second, false, "");
- }
- if(ret)
- {
- writeStreamMarshalUnmarshalCode(out, ret, "__ret", false, "");
- }
-}
-
string
Slice::findMetaData(const StringList& metaData, bool inParam)
{