Skip to content

Commit

Permalink
CPPSDK: changes to handle nested array/objects
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Oct 19, 2023
1 parent c043eb1 commit 4f83ee3
Show file tree
Hide file tree
Showing 34 changed files with 134 additions and 63 deletions.
1 change: 1 addition & 0 deletions languages/cpp/templates/additional-types/boolean.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Boolean()
1 change: 1 addition & 0 deletions languages/cpp/templates/additional-types/integer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Number()
1 change: 1 addition & 0 deletions languages/cpp/templates/additional-types/number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Float()
1 change: 1 addition & 0 deletions languages/cpp/templates/additional-types/string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String()
1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/null.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WPEFramework::Core::JSON::VariantContainer
1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/void.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WPEFramework::Core::JSON::VariantContainer
4 changes: 2 additions & 2 deletions languages/cpp/templates/parameter-serialization/array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
WPEFramework::Core::JSON::ArrayType<WPEFramework::Core::JSON::Variant> ${Property};
for (auto& element: ${property}) {
${Property}.Add() = element;
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});
Expand Down
2 changes: 0 additions & 2 deletions languages/cpp/templates/parameter-serialization/boolean.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions languages/cpp/templates/parameter-serialization/default.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion languages/cpp/templates/parameter-serialization/enum.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonValue = ${property};
${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});
4 changes: 2 additions & 2 deletions languages/cpp/templates/parameter-serialization/generic.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
WPEFramework::Core::JSON::Variant ${Property}(${property});
jsonParameters.Set(_T("${property}"), ${Property});
WPEFramework::Core::JSON::Variant ${Property}(${property}${if.optional}.value()${end.if.optional});
jsonParameters.Set(_T("${property}"), ${Property});
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions languages/cpp/templates/parameter-serialization/object.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
auto element = ${property};
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${Property}Container;
${properties}
string ${Property}Str;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${shape} ${if.non.object}${title}.${Property} = ${base.title}.${property};${end.if.non.object}
${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}
2 changes: 0 additions & 2 deletions languages/cpp/templates/parameter-serialization/string.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
${shape} ${if.non.object}${title}.${Property.dependency}${Property} = ${base.title}.${property.dependency}${property};${end.if.non.object}
${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}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${Title} ${property};
1 change: 1 addition & 0 deletions languages/cpp/templates/result-initialization/array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type} ${property};
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
while (jsonResult.Variants().Next()) {
${property}.insert(elements.Label(), elements.Current().${additional.type}.Value());
std::string label = jsonResult.Variants().Label();
${property}.emplace(std::piecewise_construct,
std::forward_as_tuple(label),
std::forward_as_tuple(jsonResult.Variants().Current().${additional.type}));
}
4 changes: 2 additions & 2 deletions languages/cpp/templates/result-instantiation/array.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
auto index(jsonResult.Elements());
while (index.Next() == true) {
${property}.push_back(index.Current().Value());
}
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}.push_back(index.Current().Value());${end.if.non.object}
}
2 changes: 0 additions & 2 deletions languages/cpp/templates/result-instantiation/boolean.cpp

This file was deleted.

4 changes: 4 additions & 0 deletions languages/cpp/templates/result-instantiation/object-array.cpp
Original file line number Diff line number Diff line change
@@ -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}.push_back(${property}Result${level});
4 changes: 3 additions & 1 deletion languages/cpp/templates/result-instantiation/object.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
${properties}
${type} ${property}Result${level};
${properties}
${property} = ${property}Result${level};
2 changes: 1 addition & 1 deletion languages/cpp/templates/result-instantiation/property.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${shape} ${if.non.object}${base.title}.${property} = jsonResult.${Property}.Value();${end.if.non.object}
${shape} ${if.non.array}${if.non.object}${base.title}Result${level}.${property} = jsonResult.${Property}.Value();${end.if.non.object}${end.if.non.array}
1 change: 1 addition & 0 deletions languages/cpp/templates/result-instantiation/ref.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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}
}
Original file line number Diff line number Diff line change
@@ -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}Result.${property}${if.impl.optional}.value()${end.if.impl.optional}.push_back(${property}Result${level});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${properties}
${properties}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${shape} ${if.non.object}${base.title}.${property.dependency}${property} = jsonResult.${Property.dependency}${Property};${end.if.non.object}
${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}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${Title}
${Title}
4 changes: 2 additions & 2 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,10 +1191,10 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
const pullsResultType = pullsResult && types.getSchemaShape(pullsResult, json, { destination: state.destination, templateDir: state.typeTemplateDir, section: state.section })
const pullsForType = pullsResult && types.getSchemaType(pullsResult, json, { destination: state.destination, templateDir: state.typeTemplateDir, section: state.section })
const pullsParamsType = pullsParams ? types.getSchemaShape(pullsParams, json, { destination: state.destination, templateDir: state.typeTemplateDir, section: state.section }) : ''
const serializedParams = flattenedMethod.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'parameter-serialization', property: param.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true })).join('\n')
const serializedParams = flattenedMethod.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'parameter-serialization', property: param.name, required: param.required || false, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true })).join('\n')
const resultInst = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-instantiation', property: flattenedMethod.result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) // w/out level: 1, getSchemaShape skips anonymous types, like primitives
const resultInit = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-initialization', property: flattenedMethod.result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) // w/out level: 1, 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, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true })).join('\n') : ''
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 || false, destination: state.destination, section: state.section, level: 1, 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, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''

Expand Down
Loading

0 comments on commit 4f83ee3

Please sign in to comment.