#include "JsonFormatter.hpp"
+#include "Attribute.hpp"
+#include "ProfileAttribute.hpp"
#include <Poco/JSON/Parser.h>
#include <Poco/DateTime.h>
}
}
-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>();
}
}
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&);