summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/CPlusPlusUtil.cpp
diff options
context:
space:
mode:
authorJoe George <joe@zeroc.com>2015-12-03 09:45:09 -0500
committerJoe George <joe@zeroc.com>2015-12-03 09:45:09 -0500
commiteb1473089bfe9105b3884a490edafeb561df935e (patch)
tree71249e567e5dc11b26b27543083d1ec5c5585037 /cpp/src/Slice/CPlusPlusUtil.cpp
parentC++11 mapping: update & timeout tests (diff)
downloadice-eb1473089bfe9105b3884a490edafeb561df935e.tar.bz2
ice-eb1473089bfe9105b3884a490edafeb561df935e.tar.xz
ice-eb1473089bfe9105b3884a490edafeb561df935e.zip
ICE-6897 - Add delegate metadata
The "delegate" metadata tag can be applied to interfaces with one operation. In C++ they are mapped to std::function's, in C# delegates. In Java we still generate a interface with one operation, which is a FunctionalInterface.
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 480feedd064..bc61ca61fe3 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -486,7 +486,7 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
"::Ice::LocalObjectPtr",
"::Ice::ValuePtr"
};
-
+
static const char* cpp11BuiltinTable[] =
{
"::Ice::Byte",
@@ -543,6 +543,10 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
{
return t;
}
+ else if(cl->definition() && cl->definition()->isDelegate())
+ {
+ return classDefToDelegateString(cl->definition());
+ }
else
{
if(cl->isInterface() && !cl->isLocal())
@@ -673,7 +677,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
"const ::Ice::LocalObjectPtr&",
"const ::Ice::ValuePtr&"
};
-
+
static const char* cpp11InputBuiltinTable[] =
{
"::Ice::Byte",
@@ -738,6 +742,10 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
{
return "const ::std::shared_ptr<::Ice::Value>&";
}
+ else if(cl->definition() && cl->definition()->isDelegate())
+ {
+ return classDefToDelegateString(cl->definition(), typeCtx, cpp11);
+ }
else
{
return "const ::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&";
@@ -829,7 +837,7 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
"::Ice::LocalObjectPtr&",
"::Ice::ValuePtr&"
};
-
+
static const char* cpp11OutputBuiltinTable[] =
{
"::Ice::Byte&",
@@ -1258,7 +1266,7 @@ Slice::findMetaData(const string& prefix, const ClassDeclPtr& cl, string& value)
{
return true;
}
-
+
ClassDefPtr def = cl->definition();
return def ? findMetaData(prefix, def->getMetaData(), value) : false;
}
@@ -1406,3 +1414,36 @@ Slice::getDataMemberRef(const DataMemberPtr& p)
return "(*" + name + ")";
}
}
+
+string
+Slice::classDefToDelegateString(const ClassDefPtr& cl, int typeCtx, bool cpp11)
+{
+ assert(cl->isDelegate());
+
+ // A delegate only has one operation
+ OperationPtr op = cl->allOperations().front();
+
+ TypePtr ret = op->returnType();
+ string retS = returnTypeToString(ret, op->returnIsOptional(), op->getMetaData(), typeCtx, cpp11);
+
+ string t = "::std::function<" + retS + " (";
+
+ ParamDeclList paramList = cl->allOperations().front()->parameters();
+ for(ParamDeclList::iterator q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if((*q)->isOutParam())
+ {
+ t += outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx, cpp11);
+ }
+ else
+ {
+ t += inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx, cpp11);
+ }
+
+ t += distance(q, paramList.end()) == 1 ? "" : ", ";
+ }
+
+ t += ")>";
+
+ return t;
+}