summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2009-11-26 22:58:16 +0100
committerJose <jose@zeroc.com>2009-11-26 22:58:16 +0100
commit9aef7822702155a4bd562765c672d73dcbe8b471 (patch)
tree984b00a3fea5615b594e3e857eadceeb5766283c /cpp
parentAdded generated directory for invoke test (diff)
downloadice-9aef7822702155a4bd562765c672d73dcbe8b471.tar.bz2
ice-9aef7822702155a4bd562765c672d73dcbe8b471.tar.xz
ice-9aef7822702155a4bd562765c672d73dcbe8b471.zip
4385 - new StreamApi & UserExecption
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Ice/Stream.h19
-rw-r--r--cpp/src/slice2cpp/Gen.cpp21
-rw-r--r--cpp/src/slice2cpp/Gen.h2
-rw-r--r--cpp/test/Ice/stream/Client.cpp79
-rw-r--r--cpp/test/Ice/stream/Test.ice23
5 files changed, 144 insertions, 0 deletions
diff --git a/cpp/include/Ice/Stream.h b/cpp/include/Ice/Stream.h
index 658aee69cd2..20ce5481893 100644
--- a/cpp/include/Ice/Stream.h
+++ b/cpp/include/Ice/Stream.h
@@ -38,6 +38,7 @@ enum StreamTraitType
StreamTraitTypeIntEnum, // Enums with more than 32767 enumerators
StreamTraitTypeSequence,
StreamTraitTypeDictionary,
+ StreamTraitTypeUserException,
StreamTraitTypeUnknown
};
@@ -68,6 +69,13 @@ struct StreamTrait< std::vector<T> >
static const int enumLimit = 0; // Used to implement enum range check
};
+template<>
+struct StreamTrait<UserException>
+{
+ static const ::Ice::StreamTraitType type = Ice::StreamTraitTypeUserException;
+ static const int enumLimit = 0; // Used to implement enum range check
+};
+
//
// StreamTrait specialization for std::map.
//
@@ -691,6 +699,17 @@ struct StreamReader<StreamTraitTypeDictionary>
}
}
};
+
+template<> // Writer specialization for UserExceptions.
+struct StreamWriter<StreamTraitTypeUserException>
+{
+ template<typename T>
+ static void write(const ::Ice::OutputStreamPtr& outS, const T& v)
+ {
+ outS->writeException(v);
+ }
+};
+
#endif
class ICE_API ObjectReader : public ::Ice::Object
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 1b0dd3d0294..fa2e480a625 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -6636,6 +6636,27 @@ Slice::Gen::StreamVisitor::visitModuleEnd(const ModulePtr&)
}
bool
+Slice::Gen::StreamVisitor::visitExceptionStart(const ExceptionPtr& p)
+{
+ if(!p->isLocal())
+ {
+ string scoped = p->scoped();
+ H << nl << sp << "template<>";
+ H << nl << "struct StreamTrait< " << fixKwd(scoped) << " >" << nl;
+ H << sb;
+ H << nl << "static const ::Ice::StreamTraitType type = ::Ice::StreamTraitTypeUserException;" << nl;
+ H << nl << "static const int enumLimit = 0;";
+ H << eb << ";" << nl;
+ }
+ return true;
+}
+
+void
+Slice::Gen::StreamVisitor::visitExceptionEnd(const ExceptionPtr&)
+{
+}
+
+bool
Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p)
{
if(!p->isLocal())
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index 5074240bc73..a7834e9c75e 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -448,6 +448,8 @@ private:
virtual void visitModuleEnd(const ModulePtr&);
virtual bool visitStructStart(const StructPtr&);
virtual void visitStructEnd(const StructPtr&);
+ virtual bool visitExceptionStart(const ExceptionPtr&);
+ virtual void visitExceptionEnd(const ExceptionPtr&);
virtual void visitEnum(const EnumPtr&);
private:
diff --git a/cpp/test/Ice/stream/Client.cpp b/cpp/test/Ice/stream/Client.cpp
index 3e0e5f6b663..6b0c7cd1d7e 100644
--- a/cpp/test/Ice/stream/Client.cpp
+++ b/cpp/test/Ice/stream/Client.cpp
@@ -584,6 +584,85 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
test(reader->obj);
test(reader->obj->s.e == Test::enum2);
}
+
+ {
+ out = Ice::createOutputStream(communicator);
+ Test::MyException ex;
+ Test::MyClassForExceptionPtr c = new Test::MyClassForException;
+ c->c = c;
+ c->o = c;
+ c->s.e = Test::enum2;
+
+ c->seq1.push_back(true);
+ c->seq1.push_back(false);
+ c->seq1.push_back(true);
+ c->seq1.push_back(false);
+
+ c->seq2.push_back(1);
+ c->seq2.push_back(2);
+ c->seq2.push_back(3);
+ c->seq2.push_back(4);
+
+ c->seq3.push_back(1);
+ c->seq3.push_back(2);
+ c->seq3.push_back(3);
+ c->seq3.push_back(4);
+
+ c->seq4.push_back(1);
+ c->seq4.push_back(2);
+ c->seq4.push_back(3);
+ c->seq4.push_back(4);
+
+ c->seq5.push_back(1);
+ c->seq5.push_back(2);
+ c->seq5.push_back(3);
+ c->seq5.push_back(4);
+
+ c->seq6.push_back(1);
+ c->seq6.push_back(2);
+ c->seq6.push_back(3);
+ c->seq6.push_back(4);
+
+ c->seq7.push_back(1);
+ c->seq7.push_back(2);
+ c->seq7.push_back(3);
+ c->seq7.push_back(4);
+
+ c->seq8.push_back("string1");
+ c->seq8.push_back("string2");
+ c->seq8.push_back("string3");
+ c->seq8.push_back("string4");
+
+ c->seq9.push_back(Test::enum3);
+ c->seq9.push_back(Test::enum2);
+ c->seq9.push_back(Test::enum1);
+
+ ex.c = c;
+
+ out->write(ex);
+ out->writePendingObjects();
+ out->finished(data);
+
+ in = Ice::createInputStream(communicator, data);
+ try
+ {
+ in->throwException();
+ test(false);
+ }
+ catch(const Test::MyException& ex1)
+ {
+ test(ex1.c->s.e == c->s.e);
+ test(ex1.c->seq1 == c->seq1);
+ test(ex1.c->seq2 == c->seq2);
+ test(ex1.c->seq3 == c->seq3);
+ test(ex1.c->seq4 == c->seq4);
+ test(ex1.c->seq5 == c->seq5);
+ test(ex1.c->seq6 == c->seq6);
+ test(ex1.c->seq7 == c->seq7);
+ test(ex1.c->seq8 == c->seq8);
+ test(ex1.c->seq9 == c->seq9);
+ }
+ }
cout << "ok" << endl;
diff --git a/cpp/test/Ice/stream/Test.ice b/cpp/test/Ice/stream/Test.ice
index dafd2f02d41..6f7d4be6551 100644
--- a/cpp/test/Ice/stream/Test.ice
+++ b/cpp/test/Ice/stream/Test.ice
@@ -86,6 +86,29 @@ interface MyInterface
{
};
+class MyClassForException
+{
+ MyClassForException c;
+ Object o;
+ SmallStruct s;
+ BoolS seq1;
+ ByteS seq2;
+ ShortS seq3;
+ IntS seq4;
+ LongS seq5;
+ FloatS seq6;
+ DoubleS seq7;
+ StringS seq8;
+ MyEnumS seq9;
+};
+
+
+
+exception MyException
+{
+ MyClassForException c;
+};
+
};
#endif