diff options
author | JackLivio <jack@livio.io> | 2018-08-04 16:52:56 -0400 |
---|---|---|
committer | JackLivio <jack@livio.io> | 2018-08-04 16:52:56 -0400 |
commit | fd7f61fae6e83a81449399080ae18efde16d6ccc (patch) | |
tree | 2f51a461eae95577ffe74a34d7ced2d48ba43a63 | |
parent | f32ad14bf6f0e435433e899fa1381f5990f5c77d (diff) | |
download | sdl_core-fd7f61fae6e83a81449399080ae18efde16d6ccc.tar.gz |
Add enum history support to generator
5 files changed, 145 insertions, 8 deletions
diff --git a/src/components/include/utils/semantic_version.h b/src/components/include/utils/semantic_version.h index efa3b2e92d..905f6b0c2e 100644 --- a/src/components/include/utils/semantic_version.h +++ b/src/components/include/utils/semantic_version.h @@ -53,7 +53,10 @@ struct SemanticVersion { minor_version = atoi(str_array[1].c_str()); patch_version = atoi(str_array[2].c_str()); } else { - exit(1); + //Invalid case + major_version = 0; + minor_version = 0; + patch_version = 0; } } diff --git a/src/components/smart_objects/include/smart_objects/enum_schema_item.h b/src/components/smart_objects/include/smart_objects/enum_schema_item.h index 787960659f..f6b7bdff92 100644 --- a/src/components/smart_objects/include/smart_objects/enum_schema_item.h +++ b/src/components/smart_objects/include/smart_objects/enum_schema_item.h @@ -42,10 +42,40 @@ #include "smart_objects/default_shema_item.h" #include "utils/semantic_version.h" +#include <boost/optional.hpp> namespace NsSmartDeviceLink { namespace NsSmartObjects { +//Element Signature for enums. Fields represent "since", "until", and "removed" +//typedef boost::optional<std::string> OptionalString; +//typedef boost::optional<bool> OptionalBool; +//typedef std::tuple<OptionalString, OptionalString, OptionalBool> ElementSignature; + +struct ElementSignature { + boost::optional<utils::SemanticVersion> mSince; + boost::optional<utils::SemanticVersion> mUntil; + bool mRemoved; + + ElementSignature(std::string since="", std::string until="", bool removed=false) { + utils::SemanticVersion since_struct(since); + utils::SemanticVersion until_struct(until); + + if(since_struct.isValid()) { + mSince = since_struct; + } + + if(until_struct.isValid()) { + mUntil = until_struct; + } + + mRemoved = removed; + } +}; + +//typedef std::map<OptionalString, OptionalString, OptionalBool> ElementSignature; + + template <typename EnumType> class EnumConversionHelper; /** @@ -65,6 +95,18 @@ class TEnumSchemaItem : public CDefaultSchemaItem<EnumType> { const std::set<EnumType>& AllowedElements, const TSchemaItemParameter<EnumType>& DefaultValue = TSchemaItemParameter<EnumType>()); + + /** + * @brief Create a new schema item. + * @param AllowedElements Set of allowed enumeration elements. + * @param DefaultValue Default value. + * @return Shared pointer to a new schema item. + **/ + static std::shared_ptr<TEnumSchemaItem> createWithSignatures( + const std::set<EnumType>& AllowedElements, + const std::set<ElementSignature>& ElementSignatures, + const TSchemaItemParameter<EnumType>& DefaultValue = + TSchemaItemParameter<EnumType>()); /** * @deprecated * @brief Validate smart object. @@ -115,12 +157,17 @@ class TEnumSchemaItem : public CDefaultSchemaItem<EnumType> { **/ TEnumSchemaItem(const std::set<EnumType>& AllowedElements, const TSchemaItemParameter<EnumType>& DefaultValue); + + TEnumSchemaItem(const std::set<EnumType>& AllowedElements, + const TSchemaItemParameter<EnumType>& DefaultValue, + const std::set<ElementSignature>& ElementSignatures); SmartType getSmartType() const OVERRIDE; EnumType getDefaultValue() const OVERRIDE; /** * @brief Set of allowed enumeration elements. **/ const std::set<EnumType> mAllowedElements; + const std::set<ElementSignature> mElementSignatures; /** * @brief Default value. **/ @@ -227,6 +274,15 @@ std::shared_ptr<TEnumSchemaItem<EnumType> > TEnumSchemaItem<EnumType>::create( } template <typename EnumType> +std::shared_ptr<TEnumSchemaItem<EnumType> > TEnumSchemaItem<EnumType>::createWithSignatures( + const std::set<EnumType>& AllowedElements, + const std::set<ElementSignature>& ElementSignatures, + const TSchemaItemParameter<EnumType>& DefaultValue ) { + return std::shared_ptr<TEnumSchemaItem<EnumType> >( + new TEnumSchemaItem<EnumType>(AllowedElements, DefaultValue, ElementSignatures)); +} + +template <typename EnumType> Errors::eType TEnumSchemaItem<EnumType>::validate(const SmartObject& Object) { rpc::ValidationReport report("RPC"); return validate(Object, &report); @@ -303,6 +359,15 @@ TEnumSchemaItem<EnumType>::TEnumSchemaItem( : CDefaultSchemaItem<EnumType>(DefaultValue) , mAllowedElements(AllowedElements) {} +template <typename EnumType> +TEnumSchemaItem<EnumType>::TEnumSchemaItem( + const std::set<EnumType>& AllowedElements, + const TSchemaItemParameter<EnumType>& DefaultValue, + const std::set<ElementSignature>& ElementSignatures) + : CDefaultSchemaItem<EnumType>(DefaultValue) + , mAllowedElements(AllowedElements) + , mElementSignatures(mElementSignatures) {} + } // namespace NsSmartObjects } // namespace NsSmartDeviceLink #endif // SRC_COMPONENTS_SMART_OBJECTS_INCLUDE_SMART_OBJECTS_ENUM_SCHEMA_ITEM_H_ diff --git a/tools/InterfaceGenerator/generator/Model.py b/tools/InterfaceGenerator/generator/Model.py index 827553bda2..e7cce732ed 100755 --- a/tools/InterfaceGenerator/generator/Model.py +++ b/tools/InterfaceGenerator/generator/Model.py @@ -304,7 +304,6 @@ class Struct(InterfaceItemBase): platform=platform, scope=scope, since=since, until=until, deprecated=deprecated, removed=removed, history=history) - print since self.members = \ members if members is not None else collections.OrderedDict() diff --git a/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py b/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py index 65359fe54e..2f643edb3a 100755 --- a/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py +++ b/tools/InterfaceGenerator/generator/generators/SmartFactoryBase.py @@ -505,8 +505,6 @@ class CodeGenerator(object): String with structs implementation source code. """ - #print struct.name - #print struct.since processed_enums = [] return self._struct_impl_template.substitute( namespace=namespace, @@ -522,6 +520,31 @@ class CodeGenerator(object): struct.members.values(), struct.since, struct.until, struct.deprecated, struct.removed)), 1)) + + def _enum_has_history_present(self, enum): + ''' + Check if any elements in an enum has history signature + ''' + for element in enum.param_type.elements.values(): + if ( element.history is not None or + element.since is not None or + element.until is not None or + element.removed is not None ): + return True + return False + + def _element_has_history_present(self, element): + ''' + Check if a specific element has a history signature + ''' + if ( element.history is not None or + element.since is not None or + element.until is not None or + element.removed is not None ): + return True + return False + + def _gen_schema_loc_decls(self, members, processed_enums): """Generate local declarations of variables for schema. @@ -541,6 +564,7 @@ class CodeGenerator(object): for member in members: if type(member.param_type) is Model.Enum and \ member.param_type.name not in processed_enums: + has_history = self._enum_has_history_present(member) local_var = self._gen_schema_loc_emum_var_name( member.param_type) result = u"\n".join( @@ -556,6 +580,46 @@ class CodeGenerator(object): enum=member.param_type.name, value=x.primary_name) for x in member.param_type.elements.values()])]) + + if has_history == True: + history_result = u"\n" + history_result += self._impl_code_loc_decl_enum_history_set_template.substitute( + type=member.param_type.name) + history_result += u"\n" + history_result += u"\n".join( + [self._impl_code_loc_decl_enum_history_set_value_init_template.substitute( + enum=member.param_type.name, + value=x.primary_name) + for x in member.param_type.elements.values() if self._element_has_history_present(x)]) + history_result += u"\n" + history_map_result = [] + + for x in member.param_type.elements.values(): + if self._element_has_history_present(x): + history_map_result.append( + self._impl_code_loc_decl_enum_history_set_insert_template. + substitute( + enum=member.param_type.name, + value=x.primary_name, + since=x.since if x.since is not None else "", + until=x.until if x.until is not None else "", + removed=x.removed if x.removed is not None else u"false")) + if(x.history is not None) : + history_list = x.history + for item in history_list: + history_map_result.append( + self._impl_code_loc_decl_enum_history_set_insert_template. + substitute( + enum=member.param_type.name, + value=x.primary_name, + since=item.since if item.since is not None else "", + until=item.until if item.until is not None else "", + removed=item.removed if item.removed is not None else u"false")) + + history_result += u"\n".join(history_map_result) + result += "\n" + result += history_result + processed_enums.append(member.param_type.name) result = u"".join([result, u"\n\n"]) if result else u"" elif type(member.param_type) is Model.EnumSubset: @@ -833,8 +897,6 @@ class CodeGenerator(object): String with schema item fill code. """ - #print(member.since) - #print member.name if (since is not None or until is not None or deprecated is not None or @@ -1595,9 +1657,19 @@ class CodeGenerator(object): _impl_code_loc_decl_enum_template = string.Template( u'''std::set<${type}::eType> ${var_name};''') + _impl_code_loc_decl_enum_history_set_template = string.Template( + u'''std::map<${type}::eType, std::vector<ElementSignature>> ${type}_element_signatures;''') + _impl_code_loc_decl_enum_insert_template = string.Template( u'''${var_name}.insert(${enum}::${value});''') + _impl_code_loc_decl_enum_history_set_value_init_template = string.Template( + u'''${enum}_element_signatures[${enum}::${value}] = std::vector<ElementSignature>();''' + ) + + _impl_code_loc_decl_enum_history_set_insert_template = string.Template( + u'''${enum}_element_signatures[${enum}::${value}].push_back(ElementSignature("${since}", "${until}", ${removed}));''') + _impl_code_item_decl_temlate = string.Template( u'''${comment}''' u'''std::shared_ptr<ISchemaItem> ${var_name} = ${item_decl};''') diff --git a/tools/InterfaceGenerator/generator/parsers/RPCBase.py b/tools/InterfaceGenerator/generator/parsers/RPCBase.py index c587a97b3a..29e5fc2ce7 100755 --- a/tools/InterfaceGenerator/generator/parsers/RPCBase.py +++ b/tools/InterfaceGenerator/generator/parsers/RPCBase.py @@ -909,8 +909,6 @@ class Parser(object): elif subelement.tag == "function" and parent.tag == "function": items.append(self.__parse_function(subelement, prefix)) else: - print subelement.tag - print parent.tag raise ParseError("A history tag must be nested within the element it notes the history for. Fix item: '" + parent.attrib["name"] + "'") |