summaryrefslogtreecommitdiffstats
path: root/veslibrary/ves_cpplibrary/src/lib/encode/XInternal.h
diff options
context:
space:
mode:
Diffstat (limited to 'veslibrary/ves_cpplibrary/src/lib/encode/XInternal.h')
-rwxr-xr-xveslibrary/ves_cpplibrary/src/lib/encode/XInternal.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/veslibrary/ves_cpplibrary/src/lib/encode/XInternal.h b/veslibrary/ves_cpplibrary/src/lib/encode/XInternal.h
new file mode 100755
index 0000000..38aa1db
--- /dev/null
+++ b/veslibrary/ves_cpplibrary/src/lib/encode/XInternal.h
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "XEvent.h"
+#include "nlohmann/json.hpp"
+
+#ifndef SPDLOG_ACTIVE_LEVEL
+#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
+#endif
+
+#include "spdlog/spdlog.h"
+
+using namespace std;
+using namespace vagt::encode;
+using json = nlohmann::json;
+
+namespace vagt
+{
+ namespace encode
+ {
+ class XJsonable
+ {
+ public:
+ virtual json toJson() = 0;
+ };
+
+ class XCommonValue
+ {
+ public:
+ XCommonValue() :dataType_(XDataTypeUnknown) {}
+ XCommonValue(const std::string& val) :dataType_(XDataTypeString), strVal_(val) {}
+ XCommonValue(XInteger val) :dataType_(XDataTypeInteger), intVal_(val) {}
+ XCommonValue(XNumber val) :dataType_(XDataTypeNumber), numberVal_(val) {}
+
+ XDataType dataType_;
+ XInteger intVal_;
+ XNumber numberVal_;
+ XString strVal_;
+ };
+
+ json mergeCommonValues(json jsonObj, const std::map<std::string, XCommonValue>& values);
+
+ template <class T>
+ inline json fromArray(const T& v)
+ {
+ json jsonArray = json::array();
+ for (auto e : v)
+ {
+ jsonArray.push_back(dynamic_pointer_cast<XJsonable>(e.imp_)->toJson());
+ }
+ return jsonArray;
+ }
+ }
+}