Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated dynamic to std::any in Dynamic Header #69

Open
wants to merge 30 commits into
base: feature/profile
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2172a8d
Updated moja.cpp with Profiler functions
parth-gr Sep 1, 2020
e12a53d
Included profiler in OperationManagersimple.cpp
parth-gr Sep 1, 2020
dfef29d
Include profiler in notificationcenter.h
parth-gr Sep 1, 2020
a9f6edd
Include profiler in json2configurationprovider.cpp
parth-gr Sep 1, 2020
812cfef
Included profiler in localdomain.cpp
parth-gr Sep 1, 2020
9e4481f
Added profiler in logging.cpp
parth-gr Sep 1, 2020
fda7d80
Included profiler in threadedaspatiallocaldomaincontroller.cpp
parth-gr Sep 1, 2020
431b445
Updated dynamic to std::any in Dynamic Header
parth-gr Sep 2, 2020
2ea643c
Updated poco::dynamic::var to std::any in Pocojsonutils
parth-gr Sep 2, 2020
11dd9f1
Updated poco::dynamic::var to std::any in Providerrelationalsqlite.cpp
parth-gr Sep 2, 2020
0957fc4
Updated poco::dynamic::var to std::any in Aggregatorfilewriter.cpp
parth-gr Sep 2, 2020
4eb699c
Updated poco::dynamic::var to std::any in Externalpoolsimple.cpp
parth-gr Sep 2, 2020
a2c5741
Updated poco::dynamic::var to std::any in Location
parth-gr Sep 2, 2020
3000ef3
Updated poco::dynamic::var to std::any in Lookuptransform
parth-gr Sep 2, 2020
72c2efc
Updated poco::dynamic::var to std::any in Proxymodule.cpp
parth-gr Sep 2, 2020
31e074f
Updated dynamic to std::any in sqlquerytransform
parth-gr Sep 2, 2020
ef435f5
Updated dynamic to std::any in write
parth-gr Sep 2, 2020
b840a8e
Updated poco::dynamic::var to std::any in Configuration
parth-gr Sep 2, 2020
4268730
Updated Json2configurationprovider.cpp to avoid automatic merges
parth-gr Sep 2, 2020
efcfeae
Reformat and fix minor issues
malfrancis Sep 2, 2020
b47db02
Updated Boost::format to Fmt::Format in writersystemconfig.cpp
parth-gr Sep 3, 2020
e34a692
Merge branch 'feature/profile' into feature/profile
parth-gr Sep 3, 2020
f014a5b
Updated Boost::format to Fmt::Format in writersystemconfig.cpp
parth-gr Sep 3, 2020
4912efb
Merge branch 'feature/profile' of https://github.com/parth-gr/FLINT i…
parth-gr Sep 3, 2020
78cd99a
Merge branch 'feature/profile' of https://github.com/parth-gr/FLINT i…
parth-gr Sep 3, 2020
846aac4
Merge branch 'feature/profile' of https://github.com/parth-gr/FLINT i…
parth-gr Sep 3, 2020
0ccc60e
Merge branch 'feature/profile' of https://github.com/parth-gr/FLINT i…
parth-gr Sep 3, 2020
2699f61
Merge branch 'feature/profile' of https://github.com/parth-gr/FLINT i…
parth-gr Sep 3, 2020
e6787c8
Mergq branch 'feature/profile' of https://github.com/parth-gr/FLINT i…
parth-gr Sep 3, 2020
2004303
Merge branch 'feature/profile' of https://github.com/parth-gr/FLINT i…
parth-gr Sep 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions Source/moja.core/include/moja/dynamic.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*
//Using POCO::DYNAMIC::VAR
#pragma once

#include <Poco/Dynamic/Struct.h>
Expand All @@ -8,3 +10,173 @@ using DynamicVar = Poco::Dynamic::Var;
using DynamicVector = Poco::Dynamic::Vector;
using DynamicObject = Poco::DynamicStruct;
} // namespace moja

*/

//Using std::any

#pragma once

#if 0
#include <Poco/Dynamic/Struct.h>
#include <Poco/Dynamic/Var.h>

namespace moja {
using DynamicVar = Poco::Dynamic::Var;
using DynamicVector = Poco::Dynamic::Vector;
using DynamicObject = Poco::DynamicStruct;
} // namespace moja
#endif

#include <any>
#include <map>
#include <set>
#include <string>
#include <vector>

namespace moja {
class DynamicVar;

template <typename K>
class Struct {
public:
typedef typename std::map<K, DynamicVar> Data;
typedef typename std::set<K> NameSet;
typedef typename Data::iterator Iterator;
typedef typename Data::const_iterator ConstIterator;
typedef typename Struct<K>::Data::value_type ValueType;
typedef typename Struct<K>::Data::size_type SizeType;
typedef typename std::pair<typename Struct<K>::Iterator, bool> InsRetVal;

Struct() : data_() {}

Struct(const Data& val) : data_(val) {}

template <typename T>
explicit Struct(const std::map<K, T>& val) {
typedef typename std::map<K, T>::const_iterator MapConstIterator;
MapConstIterator it = val.begin();
MapConstIterator end = val.end();
for (; it != end; ++it) data_.insert(ValueType(it->first, Var(it->second)));
}

virtual ~Struct() = default;

DynamicVar& operator[](const K& name) { return data_[name]; }

const DynamicVar& operator[](const K& name) const {
ConstIterator it = find(name);
if (it == end()) throw std::runtime_error("name not found: " + name);
return it->second;
}

[[nodiscard]] bool contains(const K& name) const { return find(name) != end(); }

Iterator find(const K& name) { return data_.find(name); }

[[nodiscard]] ConstIterator find(const K& name) const { return data_.find(name); }

Iterator end() { return data_.end(); }

[[nodiscard]] ConstIterator end() const { return data_.end(); }

Iterator begin() { return data_.begin(); }

[[nodiscard]] ConstIterator begin() const { return data_.begin(); }

template <typename T>
InsRetVal insert(const K& key, const T& value) {
return data_.emplace(key, value);
}

InsRetVal insert(const ValueType& aPair) { return data_.emplace(aPair); }

SizeType erase(const K& key) { return data_.erase(key); }

void erase(Iterator& it) { data_.erase(it); }

[[nodiscard]] bool empty() const { return data_.empty(); }

void clear() { data_.clear(); }

[[nodiscard]] SizeType size() const { return data_.size(); }

[[nodiscard]] NameSet members() const {
NameSet keys;
ConstIterator it = begin();
ConstIterator itEnd = end();
for (; it != itEnd; ++it) keys.insert(it->first);
return keys;
}

private:
Data data_;
};

class DynamicVar {
public:
DynamicVar() = default;
template <typename T>
DynamicVar(const T& val) : value_(val) {}
template <typename T>
operator T() const {
if (!value_.has_value()) throw std::runtime_error("Can not convert empty value.");
return extract<T>();
}
template <typename T>
const T& extract() const {
if (value_.has_value()) {
return std::any_cast<const T&>(value_);
}
throw std::runtime_error("Can not extract empty value.");
}
template <typename T>
DynamicVar& operator=(const T& other)
/// Assignment operator for assigning POD to DynamicVar
{
value_ = other;
return *this;
}

[[nodiscard]] bool isEmpty() const { return !value_.has_value(); }
[[nodiscard]] const type_info& type() const { return value_.type(); }

DynamicVar& operator[](const std::string& name);
const DynamicVar& operator[](const std::string& name) const;
bool isObject() const { return value_.type() == typeid(Struct<std::string>); }
bool isVector() const { return value_.type() == typeid(std::vector<DynamicVar>); }
bool isStruct() const { return value_.type() == typeid(Struct<DynamicVar>); }
bool isInteger() const { return value_.type() == typeid(int); }
bool isString() const { return value_.type() == typeid(std::string); }
bool isNumeric() const { return value_.type() == typeid(double); }
bool isBoolean() const { return value_.type() == typeid(bool); }
bool isSigned() const { return value_.type() == typeid(signed); }
int size() const { return sizeof(value_); }

private:
template <typename T, typename N>
static DynamicVar& structIndexOperator(T* struct_pointer, N n);
DynamicVar& get_at(const std::string& name);

std::any value_;
};

inline DynamicVar& DynamicVar::operator[](const std::string& name) { return get_at(name); }

inline const DynamicVar& DynamicVar::operator[](const std::string& name) const {
return const_cast<DynamicVar*>(this)->get_at(name);
}

inline DynamicVar& DynamicVar::get_at(const std::string& name) {
return structIndexOperator(std::any_cast<Struct<std::string>*>(value_), name);
}

template <typename T, typename N>
DynamicVar& DynamicVar::structIndexOperator(T* struct_pointer, N n) {
return struct_pointer->operator[](n);
}

using DynamicObject = Struct<std::string>;
using DynamicVector = std::vector<DynamicVar>;

} // namespace moja
6 changes: 3 additions & 3 deletions Source/moja.core/include/moja/pocojsonutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace moja {

DateTime CORE_API parseSimpleDate(const std::string& yyyymmdd);

DynamicVar CORE_API parsePocoJSONToDynamic(const DynamicVar& data);
DynamicVar CORE_API parsePocoJSONToDynamic(const Poco::Dynamic::Var& data);
DynamicVector CORE_API parsePocoJSONToDynamic(const Poco::JSON::Array::Ptr& val);
DynamicVar CORE_API parsePocoJSONToDynamic(const Poco::JSON::Object::Ptr& val);

DynamicVar CORE_API parsePocoVarToDynamic(const DynamicVar& var);
DynamicVar CORE_API parsePocoVarToDynamic(const Poco::Dynamic::Var& var);

} // namespace moja

#endif // MOJA_CORE_POCOUTILS_H_
#endif // MOJA_CORE_POCOUTILS_H_
4 changes: 2 additions & 2 deletions Source/moja.core/src/pocojsonutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ DynamicVar parsePocoJSONToDynamic(const Poco::JSON::Object::Ptr& val) {

// --------------------------------------------------------------------------------------------

DynamicVar parsePocoJSONToDynamic(const DynamicVar& data) {
DynamicVar parsePocoJSONToDynamic(const Poco::Dynamic::Var& data) {
if (data.isEmpty()) return DynamicVar();
if (data.type() == typeid(Poco::JSON::Object::Ptr)) {
const auto& object = data.extract<Poco::JSON::Object::Ptr>();
Expand Down Expand Up @@ -191,7 +191,7 @@ DynamicVar parsePocoJSONToDynamic(const DynamicVar& data) {

// --------------------------------------------------------------------------------------------

DynamicVar parsePocoVarToDynamic(const DynamicVar& var) {
DynamicVar parsePocoVarToDynamic(const Poco::Dynamic::Var& var) {
if (var.isEmpty()) {
return DynamicVar();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SQLiteStatement {

class ProviderRelationalSQLite::impl {
public:
impl(DynamicObject settings) : _path(settings["path"].convert<std::string>()), _conn(_path), _cache(10000) {}
impl(DynamicObject settings) : _path(settings["path"].extract<std::string>()), _conn(_path), _cache(10000) {}

DynamicVar GetDataSet(const std::string& query) const {
auto cachedValue = _cache.get(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ class CONFIGURATION_API JSON2ConfigurationProvider : public IConfigurationProvid

static bool fileExists(const std::string& path);

void createLocalDomain(DynamicVar& parsedJSON, Configuration& config) const;
void createSpinup(DynamicVar& parsedJSON, Configuration& config) const;
void createLibraries(DynamicVar& parsedJSON, Configuration& config) const;
void createProviders(DynamicVar& parsedJSON, Configuration& config) const;
void createPools(DynamicVar& parsedJSON, Configuration& config) const;
void createLocalDomain(Poco::Dynamic::Var& parsedJSON, Configuration& config) const;
void createSpinup(Poco::Dynamic::Var& parsedJSON, Configuration& config) const;
void createLibraries(Poco::Dynamic::Var& parsedJSON, Configuration& config) const;
void createProviders(Poco::Dynamic::Var& parsedJSON, Configuration& config) const;
void createPools(Poco::Dynamic::Var& parsedJSON, Configuration& config) const;
bool createSpecialPools(const std::string& poolName, const Poco::DynamicStruct& poolSettings,
Configuration& config) const;
bool createSpecialVariables(const std::pair<const std::string, DynamicVar>& keyValPair, Configuration& config,
bool isSpinup) const;
void createVariables(DynamicVar& parsedJSON, Configuration& config, bool isSpinup = false) const;
void createModules(DynamicVar& parsedJSON, Configuration& config) const;
void createSpinupModules(DynamicVar& parsedJSON, Configuration& config) const;

void mergeJsonConfigFile(std::string fileName, DynamicVar parsedResult);
void mergeJsonProviderConfigFile(std::string fileName, DynamicVar parsedResult);
bool createSpecialVariables(const std::pair<const std::string, Poco::Dynamic::Var>& keyValPair,
Configuration& config, bool isSpinup) const;
void createVariables(Poco::Dynamic::Var& parsedJSON, Configuration& config, bool isSpinup = false) const;
void createModules(Poco::Dynamic::Var& parsedJSON, Configuration& config) const;
void createSpinupModules(Poco::Dynamic::Var& parsedJSON, Configuration& config) const;

void mergeJsonConfigFile(std::string fileName, Poco::Dynamic::Var parsedResult);
void mergeJsonProviderConfigFile(std::string fileName, Poco::Dynamic::Var parsedResult);
};

} // namespace configuration
} // namespace flint
} // namespace moja

#endif // MOJA_FLINT_CONFIGURATION_JSON2CONFIGURATIONPROVIDER_H_
#endif // MOJA_FLINT_CONFIGURATION_JSON2CONFIGURATIONPROVIDER_H_
Loading