diff --git a/languages/cpp/templates/callback-context-instantiation/additionalProperties.cpp b/languages/cpp/templates/callback-context-instantiation/additionalProperties.cpp new file mode 100644 index 00000000..cecd2df5 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/additionalProperties.cpp @@ -0,0 +1,6 @@ + if (strcmp(elements.Label(), "${property}") == 0) { + ${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}JsonData_${title}::Iterator elements = elements.Current().Variants(); + while (elements.Next()) { + ${property}.insert(elements.Label(), elements.Current().${additional.type}; + } + } diff --git a/languages/cpp/templates/callback-context-instantiation/anyOf.cpp b/languages/cpp/templates/callback-context-instantiation/anyOf.cpp new file mode 100644 index 00000000..120561dd --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/anyOf.cpp @@ -0,0 +1 @@ + ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/array.cpp b/languages/cpp/templates/callback-context-instantiation/array.cpp new file mode 100644 index 00000000..63e7c4fa --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/array.cpp @@ -0,0 +1,6 @@ + if (strcmp(elements.Label(), "${property}") == 0) { + auto index(element.Current().Elements()); + while (index.Next() == true) { + ${property}.push_back(index.Current().Value()); + } + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/enum.cpp b/languages/cpp/templates/callback-context-instantiation/enum.cpp new file mode 100644 index 00000000..75545c29 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/enum.cpp @@ -0,0 +1,3 @@ + if (strcmp(elements.Label(), "${property}") == 0) { + ${property} = WPEFramework::Core::EnumerateType<${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}${title}>(elements.Current().String().c_str(), false).Value(); + } diff --git a/languages/cpp/templates/callback-context-instantiation/generic.cpp b/languages/cpp/templates/callback-context-instantiation/generic.cpp new file mode 100644 index 00000000..a715e2cc --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/generic.cpp @@ -0,0 +1,3 @@ + if (strcmp(elements.Label(), "${property}") == 0) { + ${property} = elements.Current().Value(); + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/namespace.cpp b/languages/cpp/templates/callback-context-instantiation/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/object.cpp b/languages/cpp/templates/callback-context-instantiation/object.cpp new file mode 100644 index 00000000..53bea7d7 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/object.cpp @@ -0,0 +1,8 @@ + if (strcmp(elements.Label(), "${property}") == 0) { + WPEFramework::Core::JSON::VariantContainer container = elements.Current().Object(); + std::string strContainer; + container.ToString(strContainer); + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} response; + response.FromString(strContainer); +${properties} + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/primitive.cpp b/languages/cpp/templates/callback-context-instantiation/primitive.cpp new file mode 100644 index 00000000..23bbace7 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/primitive.cpp @@ -0,0 +1 @@ +${type} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/property.cpp b/languages/cpp/templates/callback-context-instantiation/property.cpp new file mode 100644 index 00000000..a4e489d0 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/property.cpp @@ -0,0 +1 @@ +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}.${property} = response.${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/ref.h b/languages/cpp/templates/callback-context-instantiation/ref.h new file mode 100644 index 00000000..4da5b5d9 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/ref.h @@ -0,0 +1 @@ +${shape} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/string.cpp b/languages/cpp/templates/callback-context-instantiation/string.cpp new file mode 100644 index 00000000..e0a62ec1 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/string.cpp @@ -0,0 +1,3 @@ + if (strcmp(elements.Label(), "${property}") == 0) { + ${property} = elements.Current().Value().c_str(); + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/anyOf.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/anyOf.cpp new file mode 100644 index 00000000..e2e80c7c --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/anyOf.cpp @@ -0,0 +1 @@ +${Title} diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/anyOfSchemaShape.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/anyOfSchemaShape.cpp new file mode 100644 index 00000000..f8d48279 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/anyOfSchemaShape.cpp @@ -0,0 +1,3 @@ + string ${property}Str; + response.${Property.dependency}${Property}.ToString(${property}Str); + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str; diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/array.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/array.cpp new file mode 100644 index 00000000..006b4322 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/array.cpp @@ -0,0 +1,5 @@ + ${if.impl.array.optional}${base.title}.${property} = std::make_optional<${type}>();${end.if.impl.array.optional} + auto index(response.${Property}.Elements()); + while (index.Next() == true) { +${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(index.Current().Value());${end.if.non.object} + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/const.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/const.cpp new file mode 100644 index 00000000..41bc1feb --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/const.cpp @@ -0,0 +1 @@ + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = response.${Property.dependency}${Property}; diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/generic.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/generic.cpp new file mode 100644 index 00000000..41bc1feb --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/generic.cpp @@ -0,0 +1 @@ + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = response.${Property.dependency}${Property}; diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/namespace.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/object-array.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/object-array.cpp new file mode 100644 index 00000000..4a4eecb7 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/object-array.cpp @@ -0,0 +1,4 @@ + ${type} ${property}Result${level}; + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current(); +${properties} + ${base.title}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(${property}Result${level}); \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/object-separator.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/object-separator.cpp new file mode 100644 index 00000000..945c9b46 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/object-separator.cpp @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/object.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/object.cpp new file mode 100644 index 00000000..ddd85ed9 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/object.cpp @@ -0,0 +1,3 @@ +${if.impl.optional} + ${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional} +${properties} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/property.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/property.cpp new file mode 100644 index 00000000..0d95dcab --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/property.cpp @@ -0,0 +1 @@ +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = response.${Property.dependency}${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/ref.h b/languages/cpp/templates/callback-context-instantiation/sub-property/ref.h new file mode 100644 index 00000000..4da5b5d9 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/ref.h @@ -0,0 +1 @@ +${shape} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/title.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/title.cpp new file mode 100644 index 00000000..2a420b4b --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/title.cpp @@ -0,0 +1 @@ +${Title} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/title.cpp b/languages/cpp/templates/callback-context-instantiation/title.cpp new file mode 100644 index 00000000..2a420b4b --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/title.cpp @@ -0,0 +1 @@ +${Title} \ No newline at end of file diff --git a/languages/cpp/templates/callback-context-instantiation/tuple.cpp b/languages/cpp/templates/callback-context-instantiation/tuple.cpp new file mode 100644 index 00000000..c2934799 --- /dev/null +++ b/languages/cpp/templates/callback-context-instantiation/tuple.cpp @@ -0,0 +1,4 @@ + if (strcmp(elements.Label(), "${property}") == 0) { + ${property}.first = elements.Current().Get(0); + ${property}.second = elements.Current().Get(1); + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-initialization/additionalProperties.cpp b/languages/cpp/templates/callback-initialization/additionalProperties.cpp new file mode 100644 index 00000000..754b0fed --- /dev/null +++ b/languages/cpp/templates/callback-initialization/additionalProperties.cpp @@ -0,0 +1 @@ + ${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame}${title} ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/callback-initialization/anyOf.cpp b/languages/cpp/templates/callback-initialization/anyOf.cpp new file mode 100644 index 00000000..30f233a7 --- /dev/null +++ b/languages/cpp/templates/callback-initialization/anyOf.cpp @@ -0,0 +1 @@ +{property}; diff --git a/languages/cpp/templates/callback-initialization/array.cpp b/languages/cpp/templates/callback-initialization/array.cpp new file mode 100644 index 00000000..7ecdb522 --- /dev/null +++ b/languages/cpp/templates/callback-initialization/array.cpp @@ -0,0 +1 @@ + ${type} ${property}; diff --git a/languages/cpp/templates/callback-initialization/enum.cpp b/languages/cpp/templates/callback-initialization/enum.cpp new file mode 100644 index 00000000..754b0fed --- /dev/null +++ b/languages/cpp/templates/callback-initialization/enum.cpp @@ -0,0 +1 @@ + ${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame}${title} ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/callback-initialization/generic.cpp b/languages/cpp/templates/callback-initialization/generic.cpp new file mode 100644 index 00000000..b8231bf0 --- /dev/null +++ b/languages/cpp/templates/callback-initialization/generic.cpp @@ -0,0 +1 @@ + ${type} ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/callback-initialization/object-empty-property.cpp b/languages/cpp/templates/callback-initialization/object-empty-property.cpp new file mode 100644 index 00000000..92a17554 --- /dev/null +++ b/languages/cpp/templates/callback-initialization/object-empty-property.cpp @@ -0,0 +1 @@ + std::string ${property}; diff --git a/languages/cpp/templates/callback-initialization/object.cpp b/languages/cpp/templates/callback-initialization/object.cpp new file mode 100644 index 00000000..754b0fed --- /dev/null +++ b/languages/cpp/templates/callback-initialization/object.cpp @@ -0,0 +1 @@ + ${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame}${title} ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/callback-initialization/primitive.cpp b/languages/cpp/templates/callback-initialization/primitive.cpp new file mode 100644 index 00000000..23bbace7 --- /dev/null +++ b/languages/cpp/templates/callback-initialization/primitive.cpp @@ -0,0 +1 @@ +${type} \ No newline at end of file diff --git a/languages/cpp/templates/callback-initialization/title.cpp b/languages/cpp/templates/callback-initialization/title.cpp new file mode 100644 index 00000000..2a420b4b --- /dev/null +++ b/languages/cpp/templates/callback-initialization/title.cpp @@ -0,0 +1 @@ +${Title} \ No newline at end of file diff --git a/languages/cpp/templates/callback-instantiation/generic.cpp b/languages/cpp/templates/callback-instantiation/generic.cpp new file mode 100644 index 00000000..3b0b6489 --- /dev/null +++ b/languages/cpp/templates/callback-instantiation/generic.cpp @@ -0,0 +1,12 @@ + WPEFramework::Core::JSON::VariantContainer::Iterator elements = proxyResponse->Variants(); + while (elements.Next()) { +${callback.result.instantiation} + else if (strcmp(elements.Label(), "context") == 0) { + WPEFramework::Core::JSON::VariantContainer::Iterator params = elements.Current().Object().Variants(); + while (params.Next()) { + ${callback.param.instantiation.with.indent} + } + } else { + ASSERT(false); + } + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-response-instantiation/additionalProperties.cpp b/languages/cpp/templates/callback-response-instantiation/additionalProperties.cpp new file mode 100644 index 00000000..b39e4545 --- /dev/null +++ b/languages/cpp/templates/callback-response-instantiation/additionalProperties.cpp @@ -0,0 +1 @@ +${property} \ No newline at end of file diff --git a/languages/cpp/templates/callback-response-instantiation/generic.cpp b/languages/cpp/templates/callback-response-instantiation/generic.cpp index c8f3f090..b39e4545 100644 --- a/languages/cpp/templates/callback-response-instantiation/generic.cpp +++ b/languages/cpp/templates/callback-response-instantiation/generic.cpp @@ -1 +1 @@ -response \ No newline at end of file +${property} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/additionalProperties.cpp b/languages/cpp/templates/callback-result-instantiation/additionalProperties.cpp index a304af7e..59e3acf2 100644 --- a/languages/cpp/templates/callback-result-instantiation/additionalProperties.cpp +++ b/languages/cpp/templates/callback-result-instantiation/additionalProperties.cpp @@ -1,5 +1,7 @@ - ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} elements = (*proxyResponse)->Variants(); - ${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}${title} response; + ${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}JsonData_${title}::Iterator elements = proxyResponse->Variants(); while (elements.Next()) { - response.insert(elements.Label(), elements.Current().${additional.type}.Value()); - } \ No newline at end of file +${if.not.default} ${namespace}${key} key = WPEFramework::Core::EnumerateType<${namespace}${key}>(elements.Label(), false).Value();${end.if.not.default}${if.default} ${key} key = elements.Label();${end.if.default} + ${property}.emplace(std::piecewise_construct, + std::forward_as_tuple(key), + std::forward_as_tuple(elements.Current().${additional.type})); + } diff --git a/languages/cpp/templates/callback-result-instantiation/anyOf.cpp b/languages/cpp/templates/callback-result-instantiation/anyOf.cpp new file mode 100644 index 00000000..120561dd --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/anyOf.cpp @@ -0,0 +1 @@ + ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/array.cpp b/languages/cpp/templates/callback-result-instantiation/array.cpp index 603644e3..0e48a92b 100644 --- a/languages/cpp/templates/callback-result-instantiation/array.cpp +++ b/languages/cpp/templates/callback-result-instantiation/array.cpp @@ -1,5 +1,4 @@ - auto index((*proxyResponse)->Elements()); - ${type} response; + auto index(proxyResponse->Elements()); while (index.Next() == true) { - response.push_back(index.Current().Value()); - } + ${property}.push_back(index.Current().Value()); + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/generic.cpp b/languages/cpp/templates/callback-result-instantiation/generic.cpp index 8c7a2fea..6d8fa873 100644 --- a/languages/cpp/templates/callback-result-instantiation/generic.cpp +++ b/languages/cpp/templates/callback-result-instantiation/generic.cpp @@ -1 +1 @@ - ${type} response = (*proxyResponse)->Value(); \ No newline at end of file + ${property} = proxyResponse->Value(); \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/namespace.cpp b/languages/cpp/templates/callback-result-instantiation/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/object.cpp b/languages/cpp/templates/callback-result-instantiation/object.cpp index 8722a92e..c4569c3e 100644 --- a/languages/cpp/templates/callback-result-instantiation/object.cpp +++ b/languages/cpp/templates/callback-result-instantiation/object.cpp @@ -1,2 +1 @@ - ${title} response; ${properties} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/property.cpp b/languages/cpp/templates/callback-result-instantiation/property.cpp index 31648b06..db30050c 100644 --- a/languages/cpp/templates/callback-result-instantiation/property.cpp +++ b/languages/cpp/templates/callback-result-instantiation/property.cpp @@ -1 +1 @@ -${shape} ${if.non.object}response.${property} = (*proxyResponse)->${Property};${end.if.non.object} \ No newline at end of file +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}.${property} = proxyResponse->${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/anyOf.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/anyOf.cpp new file mode 100644 index 00000000..e2e80c7c --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/anyOf.cpp @@ -0,0 +1 @@ +${Title} diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/anyOfSchemaShape.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/anyOfSchemaShape.cpp new file mode 100644 index 00000000..56f90f5b --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/anyOfSchemaShape.cpp @@ -0,0 +1,3 @@ + string ${property}Str; + proxyResponse->${Property.dependency}${Property}.ToString(${property}Str); + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str; \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp new file mode 100644 index 00000000..03910b83 --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp @@ -0,0 +1,5 @@ + ${if.impl.array.optional}${base.title}.${property} = std::make_optional<${type}>();${end.if.impl.array.optional} + auto index(proxyResponse->${Property}.Elements()); + while (index.Next() == true) { +${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(index.Current().Value());${end.if.non.object} + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/const.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/const.cpp new file mode 100644 index 00000000..e84a8c35 --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/const.cpp @@ -0,0 +1 @@ + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property}; \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/namespace.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/object-array.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/object-array.cpp new file mode 100644 index 00000000..7bcc042c --- /dev/null +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/object-array.cpp @@ -0,0 +1,4 @@ + ${type} ${property}Result${level}; + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current(); +${properties} + ${property}response.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(${property}Result${level}); \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp index c4569c3e..b134dafe 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp @@ -1 +1,3 @@ +${if.impl.optional} + ${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional} ${properties} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp index 1f8541f2..beff7b1e 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp @@ -1 +1 @@ -${shape} ${if.non.object}response.${property.dependency}${property} = (*proxyResponse)->${Property.dependency}${Property};${end.if.non.object} \ No newline at end of file +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/tuple.cpp b/languages/cpp/templates/callback-result-instantiation/tuple.cpp index 76dde980..09c06ed0 100644 --- a/languages/cpp/templates/callback-result-instantiation/tuple.cpp +++ b/languages/cpp/templates/callback-result-instantiation/tuple.cpp @@ -1,4 +1,2 @@ - auto index((*proxyResponse)->Elements()); - ${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}${title} response; - response.first = index.Get(0); - response.second = index.Get(1); \ No newline at end of file + ${property}.first = proxyResponse->Get(0); + ${property}.second = proxyResponse->Get(1); \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-serialization/additionalProperties.cpp b/languages/cpp/templates/callback-result-serialization/additionalProperties.cpp new file mode 100644 index 00000000..1ee44075 --- /dev/null +++ b/languages/cpp/templates/callback-result-serialization/additionalProperties.cpp @@ -0,0 +1 @@ + WPEFramework::Core::ProxyType& proxyResponse = *(reinterpret_cast*>(jsonResponse)); diff --git a/languages/cpp/templates/callback-result-serialization/generic.cpp b/languages/cpp/templates/callback-result-serialization/generic.cpp new file mode 100644 index 00000000..c08e747a --- /dev/null +++ b/languages/cpp/templates/callback-result-serialization/generic.cpp @@ -0,0 +1 @@ + WPEFramework::Core::ProxyType<${method.result.json}>& proxyResponse = *(reinterpret_cast*>(jsonResponse)); diff --git a/languages/cpp/templates/callback-result-serialization/primitive.cpp b/languages/cpp/templates/callback-result-serialization/primitive.cpp new file mode 100644 index 00000000..23bbace7 --- /dev/null +++ b/languages/cpp/templates/callback-result-serialization/primitive.cpp @@ -0,0 +1 @@ +${type} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-serialization/ref.h b/languages/cpp/templates/callback-result-serialization/ref.h new file mode 100644 index 00000000..4da5b5d9 --- /dev/null +++ b/languages/cpp/templates/callback-result-serialization/ref.h @@ -0,0 +1 @@ +${shape} \ No newline at end of file diff --git a/languages/cpp/templates/callback-serialization/generic.cpp b/languages/cpp/templates/callback-serialization/generic.cpp new file mode 100644 index 00000000..1ee44075 --- /dev/null +++ b/languages/cpp/templates/callback-serialization/generic.cpp @@ -0,0 +1 @@ + WPEFramework::Core::ProxyType& proxyResponse = *(reinterpret_cast*>(jsonResponse)); diff --git a/languages/cpp/templates/declarations-override/calls-metrics.h b/languages/cpp/templates/declarations-override/calls-metrics.h new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/languages/cpp/templates/declarations-override/calls-metrics.h @@ -0,0 +1 @@ + diff --git a/languages/cpp/templates/declarations/calls-metrics.h b/languages/cpp/templates/declarations/calls-metrics.h new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/languages/cpp/templates/declarations/calls-metrics.h @@ -0,0 +1 @@ + diff --git a/languages/cpp/templates/json-types/anyOfSchemaShape.h b/languages/cpp/templates/json-types/anyOfSchemaShape.h index 08d72bbd..ab257971 100644 --- a/languages/cpp/templates/json-types/anyOfSchemaShape.h +++ b/languages/cpp/templates/json-types/anyOfSchemaShape.h @@ -1 +1 @@ - /* anyOf schema shape is not supported right now */ + /* anyOf schema shape is not supported right now */ \ No newline at end of file diff --git a/languages/cpp/templates/json-types/const.h b/languages/cpp/templates/json-types/const.h index e69de29b..2d60a3c8 100644 --- a/languages/cpp/templates/json-types/const.h +++ b/languages/cpp/templates/json-types/const.h @@ -0,0 +1 @@ +FireboltSDK::JSON::String \ No newline at end of file diff --git a/languages/cpp/templates/json-types/integer.h b/languages/cpp/templates/json-types/integer.h index b57fe26e..4bf0dddb 100644 --- a/languages/cpp/templates/json-types/integer.h +++ b/languages/cpp/templates/json-types/integer.h @@ -1 +1 @@ -WPEFramework::Core::JSON::DecSInt32 \ No newline at end of file +WPEFramework::Core::JSON::DecSInt32 diff --git a/languages/cpp/templates/methods/event.cpp b/languages/cpp/templates/methods/event.cpp index 52549399..b46f2208 100644 --- a/languages/cpp/templates/methods/event.cpp +++ b/languages/cpp/templates/methods/event.cpp @@ -1,12 +1,14 @@ /* ${method.rpc.name} - ${method.description} */ static void ${method.name}InnerCallback( void* notification, const void* userData, void* jsonResponse ) { -${event.callback.params.serialization} - ASSERT(proxyResponse->IsValid() == true); +${event.callback.serialization} + ASSERT(proxyResponse.IsValid() == true); - if (proxyResponse->IsValid() == true) { -${event.callback.result.instantiation} - proxyResponse->Release(); + if (proxyResponse.IsValid() == true) { +${event.callback.initialization} + +${event.callback.instantiation} + proxyResponse.Release(); I${info.Title}::I${method.Name}Notification& notifier = *(reinterpret_cast(notification)); notifier.${method.name}(${event.callback.response.instantiation}); @@ -32,4 +34,4 @@ if (err != nullptr) { *err = status; } - } \ No newline at end of file + } diff --git a/languages/cpp/templates/methods/property.cpp b/languages/cpp/templates/methods/property.cpp index ef29221a..4fbe9fc4 100644 --- a/languages/cpp/templates/methods/property.cpp +++ b/languages/cpp/templates/methods/property.cpp @@ -15,4 +15,4 @@ } return ${method.result.name}; - }${method.setter} \ No newline at end of file + }${method.setter} diff --git a/languages/cpp/templates/parameter-serialization/additionalProperties.cpp b/languages/cpp/templates/parameter-serialization/additionalProperties.cpp new file mode 100644 index 00000000..caa132d9 --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/additionalProperties.cpp @@ -0,0 +1,9 @@ + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}${title} map = ${property}${if.impl.optional}.value()${end.if.impl.optional}; + WPEFramework::Core::JSON::Variant ${property}Variant; + for (auto element: map) { + WPEFramework::Core::JSON::Variant jsonElement = element.second; + WPEFramework::Core::JSON::VariantContainer jsonContainer; + jsonContainer.Set(element.first.c_str(), jsonElement); + ${property}Variant = jsonContainer; + } + jsonParameters.Set(_T("${property}"), ${property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/array.cpp b/languages/cpp/templates/parameter-serialization/array.cpp index 5768dfc5..d45916ab 100644 --- a/languages/cpp/templates/parameter-serialization/array.cpp +++ b/languages/cpp/templates/parameter-serialization/array.cpp @@ -4,4 +4,4 @@ } WPEFramework::Core::JSON::Variant ${Property}Variant; ${Property}Variant.Array(${Property}); - jsonParameters.Set(_T("${property}"), ${Property}Variant); \ No newline at end of file + jsonParameters.Set(_T("${property}"), ${Property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/enum.cpp b/languages/cpp/templates/parameter-serialization/enum.cpp index 2367c118..991ea807 100644 --- a/languages/cpp/templates/parameter-serialization/enum.cpp +++ b/languages/cpp/templates/parameter-serialization/enum.cpp @@ -1,3 +1,3 @@ ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonValue = ${property}${if.optional}.value()${end.if.optional}; WPEFramework::Core::JSON::Variant ${Property}(jsonValue.Data()); - jsonParameters.Set(_T("${property}"), ${Property}); \ No newline at end of file + jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/cpp/templates/parameter-serialization/generic.cpp b/languages/cpp/templates/parameter-serialization/generic.cpp index d38bcfca..566c7354 100644 --- a/languages/cpp/templates/parameter-serialization/generic.cpp +++ b/languages/cpp/templates/parameter-serialization/generic.cpp @@ -1,2 +1,2 @@ WPEFramework::Core::JSON::Variant ${Property}(${property}${if.optional}.value()${end.if.optional}); - jsonParameters.Set(_T("${property}"), ${Property}); \ No newline at end of file + jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/cpp/templates/parameter-serialization/object-empty-property.cpp b/languages/cpp/templates/parameter-serialization/object-empty-property.cpp new file mode 100644 index 00000000..566c7354 --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/object-empty-property.cpp @@ -0,0 +1,2 @@ + WPEFramework::Core::JSON::Variant ${Property}(${property}${if.optional}.value()${end.if.optional}); + jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/cpp/templates/parameter-serialization/object.cpp b/languages/cpp/templates/parameter-serialization/object.cpp index 42226921..ef2aa794 100644 --- a/languages/cpp/templates/parameter-serialization/object.cpp +++ b/languages/cpp/templates/parameter-serialization/object.cpp @@ -1,4 +1,4 @@ - auto element = ${property}; + auto element = ${property}${if.impl.optional}.value()${end.if.impl.optional}; ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${Property}Container; ${properties} string ${Property}Str; diff --git a/languages/cpp/templates/parameter-serialization/property.cpp b/languages/cpp/templates/parameter-serialization/property.cpp index 7036ea07..fbbe778a 100644 --- a/languages/cpp/templates/parameter-serialization/property.cpp +++ b/languages/cpp/templates/parameter-serialization/property.cpp @@ -1 +1 @@ -${shape} ${if.non.object}${base.Title}Container.${Property} = element${if.base.optional}.value()${end.if.base.optional}.${property}${if.optional}.value()${end.if.optional};${end.if.non.object} \ No newline at end of file +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.Title}Container.${Property} = element.${property}${if.optional}.value()${end.if.optional};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/anyOf.cpp b/languages/cpp/templates/parameter-serialization/sub-property/anyOf.cpp new file mode 100644 index 00000000..e2e80c7c --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/sub-property/anyOf.cpp @@ -0,0 +1 @@ +${Title} diff --git a/languages/cpp/templates/parameter-serialization/sub-property/anyOfSchemaShape.cpp b/languages/cpp/templates/parameter-serialization/sub-property/anyOfSchemaShape.cpp new file mode 100644 index 00000000..ea65b36f --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/sub-property/anyOfSchemaShape.cpp @@ -0,0 +1 @@ + ${base.Title}Container.${Property.dependency}${Property} = element${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}${if.optional}.value()${end.if.optional}; diff --git a/languages/cpp/templates/parameter-serialization/sub-property/array.cpp b/languages/cpp/templates/parameter-serialization/sub-property/array.cpp new file mode 100644 index 00000000..50bbc39e --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/sub-property/array.cpp @@ -0,0 +1,8 @@ + WPEFramework::Core::JSON::ArrayType ${Property}; + ${type} ${property} = element.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}; + for (auto& element : ${property}) { +${if.object}${items.with.indent}${end.if.object}${if.non.object}${Property}.Add() = element;${end.if.non.object} + } + WPEFramework::Core::JSON::Variant ${Property}Variant; + ${Property}Variant.Array(${Property}); + jsonParameters.Set(_T("${property}"), ${Property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/sub-property/const.cpp b/languages/cpp/templates/parameter-serialization/sub-property/const.cpp new file mode 100644 index 00000000..498529d8 --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/sub-property/const.cpp @@ -0,0 +1 @@ + ${base.Title}Container.${Property.dependency}${Property} = element${property.dependency}.${property}${if.optional}.value()${end.if.optional}; diff --git a/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp b/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp new file mode 100644 index 00000000..f52f229e --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp @@ -0,0 +1,7 @@ + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${Property}Container; +${properties} + string ${Property}Str; + ${Property}Container.ToString(${Property}Str); + WPEFramework::Core::JSON::VariantContainer ${Property}VariantContainer(${Property}Str); + WPEFramework::Core::JSON::Variant ${Property}Variant = ${Property}VariantContainer; + ${Property}.Add() = ${Property}Variant; \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/object.cpp b/languages/cpp/templates/parameter-serialization/sub-property/object.cpp index c4569c3e..c04d0a50 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/object.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/object.cpp @@ -1 +1 @@ -${properties} \ No newline at end of file +${properties} diff --git a/languages/cpp/templates/parameter-serialization/sub-property/property.cpp b/languages/cpp/templates/parameter-serialization/sub-property/property.cpp index 58aa5943..a8ddffe4 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/property.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/property.cpp @@ -1 +1 @@ -${shape} ${if.non.object}${title}.${Property.dependency}${Property} = element${if.base.optional}.value()${end.if.base.optional}.${property.dependency}${property}${if.optional}.value()${end.if.optional};${end.if.non.object} \ No newline at end of file +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.Title}Container.${Property.dependency}${Property} = element${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}${if.optional}.value()${end.if.optional};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/title.cpp b/languages/cpp/templates/parameter-serialization/sub-property/title.cpp index e2e80c7c..2a420b4b 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/title.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/title.cpp @@ -1 +1 @@ -${Title} +${Title} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/title.cpp b/languages/cpp/templates/parameter-serialization/title.cpp new file mode 100644 index 00000000..2a420b4b --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/title.cpp @@ -0,0 +1 @@ +${Title} \ No newline at end of file diff --git a/languages/cpp/templates/result-initialization/additionalProperties.cpp b/languages/cpp/templates/result-initialization/additionalProperties.cpp index c33c2ea0..6f7f63f0 100644 --- a/languages/cpp/templates/result-initialization/additionalProperties.cpp +++ b/languages/cpp/templates/result-initialization/additionalProperties.cpp @@ -1 +1 @@ - ${Title} ${property}; \ No newline at end of file + ${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame}${Title} ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/result-initialization/anyOf.cpp b/languages/cpp/templates/result-initialization/anyOf.cpp new file mode 100644 index 00000000..6a698651 --- /dev/null +++ b/languages/cpp/templates/result-initialization/anyOf.cpp @@ -0,0 +1 @@ + std::string ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/result-initialization/object-empty-property.cpp b/languages/cpp/templates/result-initialization/object-empty-property.cpp new file mode 100644 index 00000000..6f7f63f0 --- /dev/null +++ b/languages/cpp/templates/result-initialization/object-empty-property.cpp @@ -0,0 +1 @@ + ${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame}${Title} ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/result-initialization/ref.h b/languages/cpp/templates/result-initialization/ref.h new file mode 100644 index 00000000..4da5b5d9 --- /dev/null +++ b/languages/cpp/templates/result-initialization/ref.h @@ -0,0 +1 @@ +${shape} \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/additionalProperties.cpp b/languages/cpp/templates/result-instantiation/additionalProperties.cpp index e5d7b116..7f10732d 100644 --- a/languages/cpp/templates/result-instantiation/additionalProperties.cpp +++ b/languages/cpp/templates/result-instantiation/additionalProperties.cpp @@ -1,6 +1,7 @@ - while (jsonResult.Variants().Next()) { - std::string label = jsonResult.Variants().Label(); + WPEFramework::Core::JSON::VariantContainer::Iterator variants = jsonResult.Variants(); + while (variants.Next()) { +${if.not.default} ${namespace}${key} key = WPEFramework::Core::EnumerateType<${namespace}${key}>(variants.Label(), false).Value();${end.if.not.default}${if.default} ${key} key = variants.Label();${end.if.default} ${property}.emplace(std::piecewise_construct, - std::forward_as_tuple(label), - std::forward_as_tuple(jsonResult.Variants().Current().${additional.type})); - } \ No newline at end of file + std::forward_as_tuple(key), + std::forward_as_tuple(variants.Current().${additional.type})); + } diff --git a/languages/cpp/templates/result-instantiation/anyOf.cpp b/languages/cpp/templates/result-instantiation/anyOf.cpp new file mode 100644 index 00000000..8ca96768 --- /dev/null +++ b/languages/cpp/templates/result-instantiation/anyOf.cpp @@ -0,0 +1,3 @@ + std::string resultStr; + jsonResult.ToString(resultStr); + ${property} = resultStr; \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/namespace.cpp b/languages/cpp/templates/result-instantiation/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/result-instantiation/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/object-empty-property.cpp b/languages/cpp/templates/result-instantiation/object-empty-property.cpp new file mode 100644 index 00000000..8ca96768 --- /dev/null +++ b/languages/cpp/templates/result-instantiation/object-empty-property.cpp @@ -0,0 +1,3 @@ + std::string resultStr; + jsonResult.ToString(resultStr); + ${property} = resultStr; \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/property.cpp b/languages/cpp/templates/result-instantiation/property.cpp index fe19dab1..fb6ca4d4 100644 --- a/languages/cpp/templates/result-instantiation/property.cpp +++ b/languages/cpp/templates/result-instantiation/property.cpp @@ -1 +1 @@ -${shape} ${if.non.array}${if.non.object}${base.title}Result${level}.${property} = jsonResult.${Property}.Value();${end.if.non.object}${end.if.non.array} \ No newline at end of file +${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Result${level}.${property} = jsonResult.${Property}.Value();${end.if.non.object}${end.if.non.array}${end.if.non.anyOf} diff --git a/languages/cpp/templates/result-instantiation/sub-property/anyOf.cpp b/languages/cpp/templates/result-instantiation/sub-property/anyOf.cpp new file mode 100644 index 00000000..e2e80c7c --- /dev/null +++ b/languages/cpp/templates/result-instantiation/sub-property/anyOf.cpp @@ -0,0 +1 @@ +${Title} diff --git a/languages/cpp/templates/result-instantiation/sub-property/anyOfSchemaShape.cpp b/languages/cpp/templates/result-instantiation/sub-property/anyOfSchemaShape.cpp new file mode 100644 index 00000000..1d5afa9b --- /dev/null +++ b/languages/cpp/templates/result-instantiation/sub-property/anyOfSchemaShape.cpp @@ -0,0 +1,3 @@ + string ${property}Str; + jsonResult.${Property.dependency}${Property}.ToString(${property}Str); + ${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str; diff --git a/languages/cpp/templates/result-instantiation/sub-property/array.cpp b/languages/cpp/templates/result-instantiation/sub-property/array.cpp index efa1adeb..5d401ef3 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/array.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/array.cpp @@ -1,4 +1,5 @@ + ${if.impl.array.optional}${base.title}Result${level}.${property} = std::make_optional<${type}>();${end.if.impl.array.optional} auto index(jsonResult.${Property}.Elements()); while (index.Next() == true) { -${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}.push_back(index.Current().Value());${end.if.non.object} +${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(index.Current().Value());${end.if.non.object} } \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/sub-property/namespace.cpp b/languages/cpp/templates/result-instantiation/sub-property/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/result-instantiation/sub-property/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp b/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp index 06a4d04d..87f0971d 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp @@ -1,4 +1,4 @@ ${type} ${property}Result${level}; ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current(); ${properties} - ${property}Result.${property}${if.impl.optional}.value()${end.if.impl.optional}.push_back(${property}Result${level}); \ No newline at end of file + ${property}Result.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(${property}Result${level}); \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/sub-property/object.cpp b/languages/cpp/templates/result-instantiation/sub-property/object.cpp index c04d0a50..2f526fef 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/object.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/object.cpp @@ -1 +1,3 @@ -${properties} +${if.impl.optional} + ${base.title}Result${level}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional} +${properties} \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/sub-property/property.cpp b/languages/cpp/templates/result-instantiation/sub-property/property.cpp index 97e0dc0f..6e938509 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/property.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/property.cpp @@ -1 +1 @@ -${shape} ${if.non.object}${base.title}Result${level}.${property.dependency}${if.impl.optional}value().${end.if.impl.optional}${property} = jsonResult.${Property.dependency}${Property};${end.if.non.object} \ No newline at end of file +${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = jsonResult.${Property.dependency}${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf} \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/tuple.cpp b/languages/cpp/templates/result-instantiation/tuple.cpp index 58f79f1d..c94a7054 100644 --- a/languages/cpp/templates/result-instantiation/tuple.cpp +++ b/languages/cpp/templates/result-instantiation/tuple.cpp @@ -1,3 +1,2 @@ - auto index(jsonResult.Elements()); - ${property}.first = index.Get(0); - ${property}.second = index.Get(1); \ No newline at end of file + ${property}.first = jsonResult.Get(0); + ${property}.second = jsonResult.Get(1); \ No newline at end of file diff --git a/languages/cpp/templates/schemas/default.cpp b/languages/cpp/templates/schemas/default.cpp index 9a52cff7..13239ca8 100644 --- a/languages/cpp/templates/schemas/default.cpp +++ b/languages/cpp/templates/schemas/default.cpp @@ -1 +1 @@ -${schema.shape} +${schema.shape} \ No newline at end of file diff --git a/languages/cpp/templates/types/additionalProperties.h b/languages/cpp/templates/types/additionalProperties.h index eced27fe..89a249cc 100644 --- a/languages/cpp/templates/types/additionalProperties.h +++ b/languages/cpp/templates/types/additionalProperties.h @@ -1 +1 @@ -using ${title} = std::unordered_map<${key}, ${type}>; +using ${title} = std::unordered_map<${namespace}${key}, ${type}>; \ No newline at end of file diff --git a/languages/cpp/templates/types/anyOfSchemaShape.h b/languages/cpp/templates/types/anyOfSchemaShape.h index 08d72bbd..c239e142 100644 --- a/languages/cpp/templates/types/anyOfSchemaShape.h +++ b/languages/cpp/templates/types/anyOfSchemaShape.h @@ -1 +1 @@ - /* anyOf schema shape is not supported right now */ +/* anyOf schema shape is not supported right now */ \ No newline at end of file diff --git a/languages/cpp/templates/types/property.h b/languages/cpp/templates/types/property.h index eb813df6..92de9ade 100644 --- a/languages/cpp/templates/types/property.h +++ b/languages/cpp/templates/types/property.h @@ -1 +1 @@ -${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property}; \ No newline at end of file +${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property}; diff --git a/languages/cpp/templates/types/tuple.h b/languages/cpp/templates/types/tuple.h index b00d2610..0ba9370f 100644 --- a/languages/cpp/templates/types/tuple.h +++ b/languages/cpp/templates/types/tuple.h @@ -1,2 +1,2 @@ /* ${title} */ -std::pair<${items}> ${title}; +using ${title} = std::pair<${items}>; \ No newline at end of file diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 031e61ea..8af37cdf 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -1257,11 +1257,25 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) const resultInit = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-initialization', property: flattenedMethod.result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) // w/out primitive: true, getSchemaShape skips anonymous types, like primitives const serializedEventParams = event ? flattenedMethod.params.filter(p => p.name !== 'listen').map(param => types.getSchemaShape(param.schema, json, {templateDir: 'parameter-serialization', property: param.name, required: param.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })).join('\n') : '' // this was wrong... check when we merge if it was fixed - const callbackSerializedParams = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-parameter-serialization', property: result.name, required: event.result.schema.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) : '' - - const callbackResultInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-result-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) : '' - // hmm... how is this different from callbackSerializedParams? i guess they get merged? - const callbackResponseInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-response-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) : '' + const callbackSerializedList = event ? types.getSchemaShape(event.result.schema, json, { templateDir: event.params && event.params.length ? 'callback-serialization' : 'callback-result-serialization', property: result.name, required: event.result.schema.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) : '' + const callbackInitialization = event ? ((event.params && event.params.length ? (event.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'callback-initialization', property: param.name, required: param.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })).join('\n')) + '\n' : '' ) + (types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-initialization', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }))) : '' + let callbackInstantiation = '' + if (event) { + if (event.params && event.params.length) { + callbackInstantiation = types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) + let paramInstantiation = event.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'callback-context-instantiation', property: param.name, required: param.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })).join('\n') + let resultInstantiation = types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-context-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) + callbackInstantiation = callbackInstantiation + .replace(/\$\{callback\.param\.instantiation\.with\.indent\}/g, indent(paramInstantiation, ' ')) + .replace(/\$\{callback\.result\.instantiation\}/g, resultInstantiation) + } + else { + callbackInstantiation = types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-result-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) + } + } + // hmm... how is this different from callbackSerializedList? i guess they get merged? + //console.log("event --- ", event) + const callbackResponseInst = event ? (event.params && event.params.length ? (event.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'callback-response-instantiation', property: param.name, required: param.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })).join(', ')) + ', ' : '' ) + (types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-response-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })) : '' const resultType = result.schema ? types.getSchemaType(result.schema, json, { templateDir: state.typeTemplateDir }) : '' const resultJsonType = result.schema ? types.getSchemaType(result.schema, json, { templateDir: 'json-types' }) : '' const resultParams = generateResultParams(result.schema, json, templates, { name: result.name}) @@ -1329,8 +1343,9 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) .replace(/\$\{event\.signature\.params\}/g, event ? types.getMethodSignatureParams(event, json, { destination: state.destination, section: state.section }) : '') .replace(/\$\{event\.signature\.callback\.params\}/g, event ? types.getMethodSignatureParams(event, json, { destination: state.destination, section: state.section, callback: true }) : '') .replace(/\$\{event\.params\.serialization\}/g, serializedEventParams) - .replace(/\$\{event\.callback\.params\.serialization\}/g, callbackSerializedParams) - .replace(/\$\{event\.callback\.result\.instantiation\}/g, callbackResultInst) + .replace(/\$\{event\.callback\.serialization\}/g, callbackSerializedList) + .replace(/\$\{event\.callback\.initialization\}/g, callbackInitialization) + .replace(/\$\{event\.callback\.instantiation\}/g, callbackInstantiation) .replace(/\$\{event\.callback\.response\.instantiation\}/g, callbackResponseInst) .replace(/\$\{info\.title\.lowercase\}/g, info.title.toLowerCase()) .replace(/\$\{info\.title\}/g, info.title) diff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs index ba26051c..fcb64eff 100644 --- a/src/macrofier/types.mjs +++ b/src/macrofier/types.mjs @@ -156,7 +156,6 @@ function insertSchemaMacros(content, schema, module, { name = '', parent = '', p .replace(/\$\{parent\.title\}/g, parent || moduleTitle) .replace(/\$\{parent\.Title\}/g, capitalize(parent || moduleTitle)) .replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, required ? '' : '$1') - .replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, required ? '' : '$1') .replace(/\$\{description\}/g, schema.description ? schema.description : '') .replace(/\$\{summary\}/g, schema.description ? schema.description.split('\n')[0] : '') .replace(/\$\{name\}/g, title) @@ -214,18 +213,31 @@ const insertObjectAdditionalPropertiesMacros = (content, schema, module, title, } const additionalType = getPrimitiveType(jsonType, 'additional-types') - let key = (propertyNames && propertyNames.title) ? propertyNames.title : getTemplate(path.join(options.templateDir, 'additionalPropertiesKey')).trimEnd() + let namespace = '' + let defaultKey = true + let key = getTemplate(path.join('types', 'additionalPropertiesKey')).trimEnd() + if (propertyNames && propertyNames.title) { + let parent = getXSchemaGroup(propertyNames, module) + key = propertyNames.title + namespace = getTemplate(path.join(options.templateDir, 'namespace')) + .replace(/\$\{if\.namespace\.notsame}(.*?)\$\{end\.if\.namespace\.notsame\}/g, (module.info.title !== (parent || moduleTitle)) ? '$1' : '') + .replace(/\$\{parent\.Title\}/g, (parent && module.info.title !== parent) ? parent : '') + defaultKey = false + } content = content .replace(/\$\{shape\}/g, shape) + .replace(/\$\{if\.default\}(.*?)\$\{end\.if\.default\}/g, defaultKey ? '$1' : '') + .replace(/\$\{if\.not.default\}(.*?)\$\{end\.if\.not.default\}/gms, defaultKey ? '' : '$1') .replace(/\$\{parent\.title\}/g, title) .replace(/\$\{title\}/g, title) .replace(/\$\{type\}/g, type) .replace(/\$\{additional\.type\}/g, additionalType) .replace(/\$\{key\}/g, key) + .replace(/\$\{namespace\}/g, namespace) .replace(/\$\{delimiter\}(.*?)\$\{end.delimiter\}/g, '') .replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/g, '') - .replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/g, '') + .replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/g, options.required ? '' : '$1') return content } @@ -247,11 +259,14 @@ const insertObjectMacros = (content, schema, module, title, property, options) = const subProperty = getTemplate(path.join(options2.templateDir, 'sub-property/object')) options2.templateDir += subProperty ? '/sub-property' : '' const objSeparator = getTemplate(path.join(options2.templateDir, 'object-separator')) - + if (localizedProp.type === 'array' || localizedProp.anyOf || localizedProp.oneOf || (typeof localizedProp.const === 'string')) { + options2.property = name + } else { + options2.property = options.property + } options2.required = schema.required && schema.required.includes(name) - const schemaShape = getSchemaShape(prop, module, options2) - - const type = getSchemaType(prop, module, options2) + const schemaShape = getSchemaShape(localizedProp, module, options2) + const type = getSchemaType(localizedProp, module, options2) // don't push properties w/ unsupported types if (type) { let replacedTemplate = template @@ -268,11 +283,14 @@ const insertObjectMacros = (content, schema, module, title, property, options) = .replace(/\$\{if\.base\.optional\}(.*?)\$\{end\.if\.base\.optional\}/gms, options.required ? '' : '$1') .replace(/\$\{if\.non\.object\}(.*?)\$\{end\.if\.non\.object\}/gms, (localizedProp.type === 'object') ? '' : '$1') .replace(/\$\{if\.non\.array\}(.*?)\$\{end\.if\.non\.array\}/gms, (localizedProp.type === 'array') ? '' : '$1') + .replace(/\$\{if\.non\.anyOf\}(.*?)\$\{end\.if\.non\.anyOf\}/gms, (localizedProp.anyOf || localizedProp.anyOneOf) ? '' : '$1') + .replace(/\$\{if\.non\.const\}(.*?)\$\{end\.if\.non\.const\}/gms, (typeof localizedProp.const === 'string') ? '' : '$1') let baseTitle = options.property if (localizedProp.type === 'object') { replacedTemplate = replacedTemplate - .replace(/\$\{property.dependency\}/g, ((options.level > 1) ? '${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}' : '') + name + objSeparator) - .replace(/\$\{Property.dependency\}/g, ((options.level > 1) ? '${Property.dependency}' : '') + capitalize(name) + (objSeparator)) + .replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, schema.required && schema.required.includes(name) ? '' : '$1') + .replace(/\$\{property.dependency\}/g, ((options.level > 0) ? '${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}' : '') + objSeparator + name) + .replace(/\$\{Property.dependency\}/g, ((options.level > 0) ? '${Property.dependency}' : '') + capitalize(name) + (objSeparator)) } else { if (options2.level <= 1) { @@ -286,7 +304,6 @@ const insertObjectMacros = (content, schema, module, title, property, options) = .replace(/\$\{obj\.separator}/g, objSeparator) .replace(/\$\{base.title\}/g, (baseTitle ? (baseTitle)[0].toLowerCase() + (baseTitle).substr(1) : '')).trimEnd() .replace(/\$\{base.Title\}/g, (baseTitle ? (baseTitle)[0].toUpperCase() + (baseTitle).substr(1) : '')).trimEnd() - .replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, prop.required ? '' : '$1') properties.push((i !== 0 ? indent : '') + replacedTemplate) } }) @@ -335,8 +352,7 @@ const insertObjectMacros = (content, schema, module, title, property, options) = } const regex = new RegExp("\\$\\{" + macro + "\\}", "g") - content = content.replace(regex, properties.join('\n')) - .replace(/\$\{level}/g, options.parentLevel > 0 ? options.parentLevel : '') + content = content.replace(regex, properties.join('\n')).replace(/\$\{level}/g, options.parentLevel > 0 ? options.parentLevel : '') if (!schema.properties && !schema.additionalProperties) { if (schema.propertyNames && schema.propertyNames.enum) { content = getTemplate(path.join(options.templateDir, 'enum-empty-property')) @@ -349,11 +365,13 @@ const insertObjectMacros = (content, schema, module, title, property, options) = return content } -const insertArrayMacros = (content, schema, module, level = 0, items) => { +const insertArrayMacros = (content, schema, module, level = 0, items, required = false) => { content = content .replace(/\$\{json\.type\}/g, getSchemaType(schema.items, module, { templateDir: 'json-types', destination: state.destination, section: state.section, code: false, namespace: true })) .replace(/\$\{items\}/g, items) .replace(/\$\{items\.with\.indent\}/g, indent(items, ' ')) + .replace(/\$\{if\.impl.array.optional\}(.*?)\$\{end\.if\.impl.array.optional\}/gms, required ? '' : '$1') + return content } @@ -456,9 +474,8 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren throw "Unresolvable $ref: " + schema['ref'] + ", in " + module.info.title } else if (schema.hasOwnProperty('const')) { - const shape = insertConstMacros(getTemplate(path.join(templateDir, 'const' + suffix)), schema, module, theTitle) - result = insertSchemaMacros(result.replace(/\$\{shape\}/g, shape), schema, module, { name: theTitle, parent, property, required }) - return result + const shape = insertConstMacros(getTemplate(path.join(templateDir, 'const' + suffix)) || genericTemplate, schema, module, theTitle) + return insertSchemaMacros(result.replace(/\$\{shape\}/g, shape), schema, module, { name: theTitle, parent, property, required }) } else if (!skipTitleOnce && (level > 0) && schema.title) { let enumType = (schema.type === 'string' && Array.isArray(schema.enum)) @@ -482,6 +499,7 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren shape = insertObjectMacros(getTemplate(path.join(templateDir, 'object' + (array ? '-array' : '') + suffix)) || genericTemplate, schema, module, theTitle, property, { parentLevel, level: objectLevel, parent, property, required, templateDir, descriptions, destination, section, enums, namespace: true, primitive }) } result = result.replace(/\$\{shape\}/g, shape) + result = result.replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, required ? '' : '$1') return insertSchemaMacros(result, schema, module, { name: theTitle, parent, property, required, templateDir }) } else if (schema.anyOf || schema.oneOf) { @@ -495,7 +513,7 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren if (!schema.anyOf) { schema.anyOf = schema.oneOf } - shape = insertAnyOfMacros(getTemplate(path.join(templateDir, 'anyOf' + suffix)), schema, module, theTitle) + shape = insertAnyOfMacros(getTemplate(path.join(templateDir, 'anyOf' + suffix)) || genericTemplate, schema, module, theTitle) } if (shape) { result = result.replace(/\$\{shape\}/g, shape) @@ -545,7 +563,7 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren return insertSchemaMacros(result, schema, module, { name: items, parent, property, required, templateDir }) } else if (schema.type) { - const shape = insertPrimitiveMacros(getTemplate(path.join(templateDir, 'primitive' + suffix) || genericTemplate), schema, module, theTitle, templateDir) + const shape = insertPrimitiveMacros(getTemplate(path.join(templateDir, 'primitive' + suffix)), schema, module, theTitle, templateDir) result = result.replace(/\$\{shape\}/g, shape) if (level > 0 || primitive) { return insertSchemaMacros(result, schema, module, { name: theTitle, parent, property, required, templateDir })