C++: Add terms to ScriptDependentPriceSpecification
authorjani <jani@asema.com>
Thu, 14 Mar 2019 22:32:04 +0000 (00:32 +0200)
committerjani <jani@asema.com>
Thu, 14 Mar 2019 22:32:04 +0000 (00:32 +0200)
Common/C++/SmartAPI/smartapi/common/PROPERTY.h
Common/C++/SmartAPI/smartapi/model/Map.cpp
Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.cpp
Common/C++/SmartAPI/smartapi/model/ScriptDependentPriceSpecification.h

index 117b5652066feeb93260c7e01a493fe4b862d7c4..819dc134d6b092fa030c36433c4a053fd53ef9e7 100644 (file)
 #define PROPERTY__ZONEROUTE            "http://smart-api.io/ontology/1.0/smartapi#zoneRoute"
 
 #define PROPERTY__PROGRAMCODE          "http://smart-api.io/ontology/1.0/smartapi#programCode"
+#define PROPERTY__TERMS                "http://smart-api.io/ontology/1.0/smartapi#terms"
 
 #endif //__PROPERTY_H__
index aee15ef77b272ce4519a4a3deff18c1607254071..39b281968ecc4658a532e44f4b112bd6e18cd5ef 100755 (executable)
@@ -44,12 +44,14 @@ QVariantMap Map::toVariantMap()
        QMapIterator<QString, Variant*> i(mMap);
        while (i.hasNext()) {
                i.next();
-               QVariant v = i.value()->getValue();
-               if (i.value()->getType() == SMARTAPIVARIANT::MAP) {
-                       Map* mv = (Map*)v.value<void*>();
-                       m.insert(i.key(), mv->toVariantMap());
-               } else {
-                       m.insert(i.key(), v);
+               if (i.value()) {
+                       QVariant v = i.value()->getValue();
+                       if (i.value()->getType() == SMARTAPIVARIANT::MAP) {
+                               Map* mv = (Map*)v.value<void*>();
+                               if (mv) m.insert(i.key(), mv->toVariantMap());
+                       } else {
+                               m.insert(i.key(), v);
+                       }
                }
        }
        return m;
index a93f2983750fe6d1fc6d658a00c3c2c7d11bfc7f..bcfca94c7b01876187d32c0dc7d4ad436d73ce1c 100644 (file)
@@ -9,6 +9,7 @@ ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(QString ide
 {
        setType(RESOURCE__SCRIPTDEPENDENTPRICESPECIFICATION);
        INIT_PROPERTY(mScript);
+       INIT_PROPERTY(mSpec);
 }
 
 ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(QString unit, QString secondaryUnit, QString secondaryQuantity, QDateTime validFrom, QDateTime validThrough) :
@@ -21,6 +22,7 @@ ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(QString uni
        setValidFrom(validFrom);
        setValidThrough(validThrough);
        INIT_PROPERTY(mScript);
+       INIT_PROPERTY(mSpec);
 }
 
 ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(ScriptDependentPriceSpecification* o) :
@@ -28,6 +30,7 @@ ScriptDependentPriceSpecification::ScriptDependentPriceSpecification(ScriptDepen
 {
        setType(RESOURCE__SCRIPTDEPENDENTPRICESPECIFICATION);
        SET_PROPERTY_REFERENCE(PROPERTY__PROGRAMCODE,mScript,Variant);
+       SET_PROPERTY_REFERENCE(PROPERTY__TERMS,mSpec,Map);
 }
 
 ScriptDependentPriceSpecification::~ScriptDependentPriceSpecification()
@@ -50,5 +53,6 @@ void ScriptDependentPriceSpecification::parse(Statement* statement)
 {
        INIT_PARSE(statement)
        PARSE_PROPERTY(PROPERTY__PROGRAMCODE, setScript, Variant)
+       PARSE_PROPERTY(PROPERTY__TERMS, setTerms, Map)
        FINISH_PARSE(DependentPriceSpecification)
 }
index 22fb44a228527c9761f774aad34c3f33f5b2ce75..2691795536a06fd5c7b5324615fecd97a649d5d1 100644 (file)
@@ -24,8 +24,13 @@ public:
        void setScript(QString script)                                          { setScript(new Variant(script)); }
        void setScript(Variant* script)                                         { set(PROPERTY__PROGRAMCODE, script); mScript = script; }
 
+       bool hasTerms()                                                                         { return mSpec != NULL; }
+       Map* getTerms()                                                                         { return mSpec; }
+       void setTerms(Map* s)                                                           { set(PROPERTY__TERMS, new Variant(s)); mSpec = s; }
+
 private:
        Variant* mScript;
+       Map* mSpec;
 };
 
 #endif // SCRIPTDEPENDENTPRICESPECIFICATION_H