Salome HOME
ProfilesService
[modules/gde.git] / projects / GDE_API_CPP / api / src / JsonFormatter.cpp
index 8f17dfadfaebc7592f2f4a0785a2b62973d8c5f7..c30a7b6e88882165f3e5fa785b01b2c0c41e66a8 100644 (file)
@@ -1,4 +1,6 @@
 #include "JsonFormatter.hpp"
+#include "Attribute.hpp"
+#include "ProfileAttribute.hpp"
 
 #include <Poco/JSON/Parser.h>
 #include <Poco/DateTime.h>
@@ -29,23 +31,24 @@ gde::JsonFormatter::extract(Poco::JSON::Object::Ptr object, const std::string& v
   }
 }
 
-std::vector<gde::Attribute>
+template <typename T>
+std::vector<T>
 gde::JsonFormatter::extractVector(Poco::JSON::Object::Ptr object, const std::string& varName)
 {
   try {
-    std::vector<gde::Attribute> result;
+    std::vector<T> result;
     Poco::JSON::Array::Ptr array = object->getArray(varName);
     typedef Poco::JSON::Array::ConstIterator ArrayIterator;
 
     for (ArrayIterator itr = array->begin(); itr != array->end(); ++itr) {
       std::string json = itr->toString(); // { var:value, ... }
-      result.push_back(Attribute::fromJson(json));
+      result.push_back(T::fromJson(json));
     }
 
     return result;
   } catch (Poco::InvalidAccessException& e) {
     // This exception is raised if Var v is empty
-    return std::vector<gde::Attribute>();
+    return std::vector<T>();
   }
 }
 
@@ -99,3 +102,6 @@ gde::JsonFormatter::format(const std::string txt, bool value)
 template int gde::JsonFormatter::extract<int>(Poco::JSON::Object::Ptr, const std::string&);
 template bool gde::JsonFormatter::extract<bool>(Poco::JSON::Object::Ptr, const std::string&);
 template std::string gde::JsonFormatter::extract<std::string>(Poco::JSON::Object::Ptr, const std::string&);
+
+template std::vector<gde::Attribute> gde::JsonFormatter::extractVector<gde::Attribute>(Poco::JSON::Object::Ptr, const std::string&);
+template std::vector<gde::ProfileAttribute> gde::JsonFormatter::extractVector<gde::ProfileAttribute>(Poco::JSON::Object::Ptr, const std::string&);