def createTypeCode(xmlRorgNode, xmlFuncNode): itemNumber = 0 for xmlTypeNode in xmlFuncNode.findall("type"): if profileHelper.profileName(xmlRorgNode, xmlFuncNode, xmlTypeNode) in supportedProfiles: itemNumber += 1 if itemNumber == 0: return " throw std::out_of_range(\"Invalid EFuncIds\");" code = " switch(static_cast<ETypeIds>(typeId))\n" code += " {\n" for xmlTypeNode in xmlFuncNode.findall("type"): if profileHelper.profileName( xmlRorgNode, xmlFuncNode, xmlTypeNode) not in supportedProfiles: continue enumValue = cppHelper.toEnumValueName( xmlTypeNode.find("number").text) className = cppHelper.toCppName( "CProfile_" + profileHelper.profileName( xmlRorgNode, xmlFuncNode, xmlTypeNode)) code += " case " + enumValue + ": return boost::make_shared<" + className + ">(deviceId, api);\n" code += " default : throw std::out_of_range(\"Invalid EFuncIds\");\n" code += " }" return code
def createTypeCode(xmlRorgNode, xmlFuncNode): itemNumber = 0 # Add types found in XML file for xmlTypeNode in xmlFuncNode.findall("type"): if profileHelper.profileName(xmlRorgNode, xmlFuncNode, xmlTypeNode) in supportedProfiles: itemNumber += 1 # Add hard-coded types not present in XML file profilePattern = profileHelper.profileFuncPattern( xmlRorgNode, xmlFuncNode) hardCodedProfilesNotInXml = list( filter(lambda p: re.match(profilePattern, p), hardCodedProfiles.getProfilesNotInXml())) itemNumber += len(hardCodedProfilesNotInXml) if itemNumber == 0: return " throw std::out_of_range(\"Invalid EFuncIds\");" code = " switch(static_cast<ETypeIds>(typeId))\n" code += " {\n" # Add types found in XML file for xmlTypeNode in xmlFuncNode.findall("type"): if profileHelper.profileName( xmlRorgNode, xmlFuncNode, xmlTypeNode) not in supportedProfiles: continue enumValue = cppHelper.toEnumValueName( xmlTypeNode.find("number").text) className = cppHelper.toCppName( "CProfile_" + profileHelper.profileName( xmlRorgNode, xmlFuncNode, xmlTypeNode)) code += " case " + enumValue + ": return boost::make_shared<" + className + ">(deviceId, api);\n" # Add hard-coded types not present in XML file for profile in hardCodedProfilesNotInXml: enumValue = cppHelper.toEnumValueName( "0x" + profileHelper.getType(profile)) className = cppHelper.toCppName("CProfile_" + profile) code += " case " + enumValue + ": return boost::make_shared<" + className + ">(deviceId, api);\n" code += " default : throw std::out_of_range(\"Invalid EFuncIds\");\n" code += " }" return code
enumValueNameTag="number", enumValueTag="number"), cppClass.PUBLIC)) funcClass.addMethod( cppClass.CppMethod( "id", "unsigned int", "", cppClass.PUBLIC, cppClass.CONST | cppClass.OVERRIDE, " return " + xmlFuncNode.find("number").text + ";")) funcClass.addMethod(cppClass.CppMethod("title", "const std::string&", "", cppClass.PUBLIC, cppClass.CONST | cppClass.OVERRIDE, \ " static const std::string title(\"" + xmlFuncNode.find("title").text + "\");\n" \ " return title;")) #------------------------------------------------------------------------ # Type cppTypes for xmlTypeNode in xmlFuncNode.findall("type"): profileName = profileHelper.profileName(xmlRorgNode, xmlFuncNode, xmlTypeNode) typeClassName = cppHelper.toCppName("CProfile_" + profileName) if hardCodedProfiles.isProfileHardCoded(profileName): # Profile is hard-coded, nothing to do continue typeClass = cppClass.CppClass(typeClassName) typeClass.inheritFrom("IType", cppClass.PUBLIC) typeClass.addConstructor( cppClass.CppClassConstructor( "const std::string& deviceId, boost::shared_ptr<yApi::IYPluginApi> api" )) funcClass.addDependency(typeClass) def isLinearValue(xmlDataFieldNode): return True if xmlDataFieldNode.find("range/min") is not None \ and xmlDataFieldNode.find("range/max") is not None \
# Func cppTypes for xmlFuncNode in xmlRorgNode.findall("func"): funcClass = cppClass.CppClass("C" + xmlRorgNode.find("telegram").text + "_" + cppHelper.toCppName(xmlFuncNode.find("number").text)) funcClass.addComment(cppHelper.toCppName(xmlFuncNode.find("title").text)) funcClass.inheritFrom("IFunc", cppClass.PUBLIC) rorgClass.addDependency(funcClass) funcClass.addSubType(cppClass.CppEnumType("ETypeIds", xmlHelper.getEnumValues(inNode=xmlFuncNode, foreachSubNode="type", enumValueNameTag="number", enumValueTag="number"), cppClass.PUBLIC)) funcClass.addMethod(cppClass.CppMethod("id", "unsigned int", "", cppClass.PUBLIC, cppClass.CONST | cppClass.OVERRIDE, " return " + xmlFuncNode.find("number").text + ";")) funcClass.addMethod(cppClass.CppMethod("title", "const std::string&", "", cppClass.PUBLIC, cppClass.CONST | cppClass.OVERRIDE, \ " static const std::string title(\"" + xmlFuncNode.find("title").text + "\");\n" \ " return title;")) #------------------------------------------------------------------------ # Type cppTypes for xmlTypeNode in xmlFuncNode.findall("type"): profileName = profileHelper.profileName(xmlRorgNode, xmlFuncNode, xmlTypeNode) typeClassName = cppHelper.toCppName("CProfile_" + profileName) if hardCodedProfiles.isProfileHardCoded(profileName): # Profile is hard-coded, nothing to do continue typeClass = cppClass.CppClass(typeClassName) typeClass.inheritFrom("IType", cppClass.PUBLIC) typeClass.addConstructor(cppClass.CppClassConstructor("const std::string& deviceId, boost::shared_ptr<yApi::IYPluginApi> api")) funcClass.addDependency(typeClass) def isLinearValue(xmlDataFieldNode): return True if xmlDataFieldNode.find("range/min") is not None \ and xmlDataFieldNode.find("range/max") is not None \ and xmlDataFieldNode.find("scale/min") is not None \ and xmlDataFieldNode.find("scale/max") is not None else False