summaryrefslogtreecommitdiff
path: root/project2/ice/slice2Type.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-03-10 20:24:23 +0000
committerrandomdan <randomdan@localhost>2014-03-10 20:24:23 +0000
commit349993be0149356ac783349a9f1d4012b44a4dbb (patch)
tree114a2d8c8b1534f05fe10d002ff031f590e4f3f8 /project2/ice/slice2Type.cpp
parentAdds native support for time_duration as a variable type (diff)
downloadproject2-349993be0149356ac783349a9f1d4012b44a4dbb.tar.bz2
project2-349993be0149356ac783349a9f1d4012b44a4dbb.tar.xz
project2-349993be0149356ac783349a9f1d4012b44a4dbb.zip
Add basic workings of the Ice client and daemon modules - will probably change, but basic functionality works
Diffstat (limited to 'project2/ice/slice2Type.cpp')
-rw-r--r--project2/ice/slice2Type.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/project2/ice/slice2Type.cpp b/project2/ice/slice2Type.cpp
new file mode 100644
index 0000000..9c3404e
--- /dev/null
+++ b/project2/ice/slice2Type.cpp
@@ -0,0 +1,110 @@
+#include <pch.hpp>
+#include "slice2Type.h"
+#include <Slice/CPlusPlusUtil.h>
+#include <boost/foreach.hpp>
+
+Slice2Type::Slice2Type(FILE * c) :
+ code(c)
+{
+}
+
+bool
+Slice2Type::visitModuleStart(const Slice::ModulePtr & m)
+{
+ module = m->name();
+ return true;
+}
+
+void
+Slice2Type::visitModuleEnd(const Slice::ModulePtr &)
+{
+ module.clear();
+}
+
+void
+Slice2Type::visitClassDecl(const Slice::ClassDeclPtr&)
+{
+}
+
+bool
+Slice2Type::visitExceptionStart(const Slice::ExceptionPtr & e)
+{
+ if (e->hasMetaData("project2:type")) {
+ fprintf(code, "template <>\nvoid IceType< %s::%s >::ForEachDataMember(const %s::%s & obj, const IceEachDataMemberValue & func)\n{\n",
+ module.c_str(), e->name().c_str(),
+ module.c_str(), e->name().c_str());
+ membersToVariables(e->dataMembers(), "obj.");
+ fprintf(code, "}\n\n");
+
+ fprintf(code, "template <>\nvoid IceType< %s::%s >::CreateColumns(const IceEachDataMemberName & func)\n{\n",
+ module.c_str(), e->name().c_str());
+ membersToColumns(e->dataMembers());
+ fprintf(code, "}\n\n");
+ }
+ return false;
+}
+
+bool
+Slice2Type::visitClassDefStart(const Slice::ClassDefPtr & c)
+{
+ if (c->hasMetaData("project2:type")) {
+ fprintf(code, "template <>\nvoid IceType< IceInternal::Handle< %s::%s > >::ForEachDataMember(const IceInternal::Handle< %s::%s > & ptr, const IceEachDataMemberValue & func)\n{\n",
+ module.c_str(), c->name().c_str(),
+ module.c_str(), c->name().c_str());
+ membersToVariables(c->dataMembers(), "ptr->");
+ fprintf(code, "}\n\n");
+
+ fprintf(code, "template <>\nvoid IceType< IceInternal::Handle< %s::%s > >::CreateColumns(const IceEachDataMemberName & func)\n{\n",
+ module.c_str(), c->name().c_str());
+ membersToColumns(c->dataMembers());
+ fprintf(code, "}\n\n");
+ }
+ return false;
+}
+
+bool
+Slice2Type::visitStructStart(const Slice::StructPtr & s)
+{
+ if (s->hasMetaData("project2:type")) {
+ fprintf(code, "template <>\nvoid IceType< %s::%s >::ForEachDataMember(const %s::%s & obj, const IceEachDataMemberValue & func)\n{\n",
+ module.c_str(), s->name().c_str(),
+ module.c_str(), s->name().c_str());
+ membersToVariables(s->dataMembers(), "obj.");
+ fprintf(code, "}\n\n");
+
+ fprintf(code, "template <>\nvoid IceType< %s::%s >::CreateColumns(const IceEachDataMemberName & func)\n{\n",
+ module.c_str(), s->name().c_str());
+ membersToColumns(s->dataMembers());
+ fprintf(code, "}\n\n");
+ }
+ return false;
+}
+
+void
+Slice2Type::membersToVariables(const Slice::DataMemberList & members, const std::string & access) const
+{
+ BOOST_FOREACH(const auto & m, members) {
+ if (m->optional()) {
+ fprintf(code, "\tfunc(IceConvert< IceUtil::Optional< %s> >::ToVariable(%s%s));\n",
+ Slice::typeToString(m->type()).c_str(),
+ access.c_str(),
+ m->name().c_str());
+ }
+ else {
+ fprintf(code, "\tfunc(IceConvert< %s >::ToVariable(%s%s));\n",
+ Slice::typeToString(m->type()).c_str(),
+ access.c_str(),
+ m->name().c_str());
+ }
+ }
+}
+
+void
+Slice2Type::membersToColumns(const Slice::DataMemberList & members) const
+{
+ BOOST_FOREACH(const auto & m, members) {
+ fprintf(code, "\tfunc(\"%s\");\n",
+ m->name().c_str());
+ }
+}
+