24#include <initializer_list>
137 operator std::string();
138 operator const char *();
167 m_string =
new std::string(std::to_string(v));
169 mthrow(
"Invalid type ID " + std::to_string(
m_tid));
185 mthrow(
"Subkey can only be assigned to ODB key");
191 mthrow(
"Subkey can only be assigned to ODB key");
197 m_uint8 = std::stoi(v,
nullptr, 0);
199 m_int8 = std::stoi(v,
nullptr, 0);
201 m_uint16 = std::stoi(v,
nullptr, 0);
203 m_int16 = std::stoi(v,
nullptr, 0);
205 m_uint32 = std::stoul(v,
nullptr, 0);
207 m_int32 = std::stoul(v,
nullptr, 0);
209 m_uint64 = std::stoul(v,
nullptr, 0);
211 m_int64 = std::stoul(v,
nullptr, 0);
213 m_bool = std::stoi(v,
nullptr, 0);
225 mthrow(
"Invalid type ID " + std::to_string(
m_tid));
237 void add(
double inc,
bool push =
true);
239 void mult(
double f,
bool push =
true);
279 mthrow(
"Division by zero");
342 mthrow(
"Subkey not found");
344 mthrow(
"Invalid type ID " + std::to_string(
m_tid));
362 mthrow(
"Only ODB string keys support string_size()");
372 void get(std::string &
s);
377 mthrow(
"odb_get() called for non-key object");
383 mthrow(
"odb_get() called for non-key object");
504 "]\" contains array. Please assign to std::vector.");
514 mthrow(
"ODB key \"" +
get_full_path() +
"\" contains array. Please assign to std::vector.");
521 void get(std::string &
s,
bool quotes =
false,
bool refresh =
true);
528 bool read_key(
const std::string &path);
529 bool write_key(std::string &path,
bool write_defaults);
585 odb(std::initializer_list<std::pair<const char *, midas::odb>>
list) :
odb() {
592 for (
int j=0 ;
j<
i ;
j++) {
597 mthrow(
"ODB key \"" + std::string(
element.first) +
"\" exists already as \"" +
629 template<
typename T,
size_t SIZE>
630 odb(
const std::array<T, SIZE> &arr) :
odb() {
633 for (
int i = 0;
i < (int)
SIZE;
i++) {
643 template<
size_t SIZE>
644 odb(
const std::array<std::string, SIZE> &arr) :
odb() {
647 for (
int i = 0;
i < (int)
SIZE;
i++) {
648 std::string * mystring =
new std::string(arr[
i]);
658 odb(
const std::string &path,
bool init_via_xml =
false) :
odb() {
659 if (path[0] ==
'/') {
672 mthrow(
"ODB key \"" + path +
"\" not found in ODB");
680 std::stringstream ss(path.substr(1));
682 std::vector<std::string> arr;
683 while (std::getline(ss, item,
'/'))
688 for (
size_t i = 0;
i < arr.size();
i++)
709 pc->set_parent(
this);
752 if (std::is_same<T, uint8_t>::value)
754 else if (std::is_same<T, int8_t>::value)
756 else if (std::is_same<T, uint16_t>::value)
758 else if (std::is_same<T, int16_t>::value)
760 else if (std::is_same<T, uint32_t>::value)
762 else if (std::is_same<T, unsigned long>::value &&
sizeof(
long) == 4)
764 else if (std::is_same<T, int32_t>::value)
766 else if (std::is_same<T, long>::value &&
sizeof(
long) == 4)
768 else if (std::is_same<T, uint64_t>::value)
770 else if (std::is_same<T, unsigned long>::value &&
sizeof(
long) == 8)
772 else if (std::is_same<T, int64_t>::value)
774 else if (std::is_same<T, long>::value &&
sizeof(
long) == 8)
776 else if (std::is_same<T, bool>::value)
778 else if (std::is_same<T, float>::value)
780 else if (std::is_same<T, double>::value)
793 if (m_num_values == 0) {
815 const std::vector<T> &
operator=(
const std::vector<T> &v) {
820 if (m_num_values == 0) {
823 if (std::is_same<T, bool>::value) {
860 template<
typename T,
size_t SIZE>
861 const std::array<T, SIZE> &
operator=(
const std::array<T, SIZE> &arr) {
866 if (m_num_values == 0) {
893 operator std::string() {
904 operator std::vector<T>() {
913 operator std::vector<std::string>() {
923 template<
typename T,
typename std::enable_if<
924 std::is_same<T, uint8_t>::value ||
925 std::is_same<T, int8_t>::value ||
926 std::is_same<T, uint16_t>::value ||
927 std::is_same<T, int16_t>::value ||
928 std::is_same<T, uint32_t>::value ||
929 std::is_same<T, int32_t>::value ||
930 std::is_same<T, uint64_t>::value ||
931 std::is_same<T, int64_t>::value ||
932 std::is_same<T, bool>::value ||
933 std::is_same<T, float>::value ||
934 std::is_same<T, double>::value, T>
::type * =
nullptr>
958 throw std::out_of_range(
"Index \"" + std::to_string(
index) +
"\" out of range for ODB key \"" +
get_full_path() +
"[0..." + std::to_string(
m_num_values - 1) +
"]\"");
975 throw std::out_of_range(
"Index \"" + std::to_string(
index) +
"\" out of range for ODB key \"" +
get_full_path() +
"[0..." + std::to_string(
m_num_values - 1) +
"]\", please consider set_auto_enlarge_array(true)");
996 template <
typename T>
1028 template<
typename T>
1032 "\" contains array which cannot be used in basic arithmetic operation.");
1033 if (std::is_same<T, midas::odb>::value) {
1039 double s1 =
static_cast<double>(
m_data[0]);
1040 double s2 =
static_cast<double>(
i.m_data[0]);
1050 template<
typename T>
1054 "\" contains array which cannot be used in basic arithmetic operation.");
1055 if (std::is_same<T, midas::odb>::value) {
1061 double s1 =
static_cast<double>(
m_data[0]);
1062 double s2 =
static_cast<double>(
i.m_data[0]);
1072 template<
typename T>
1076 "\" contains array which cannot be used in basic arithmetic operation.");
1083 template<
typename T>
1087 "\" contains array which cannot be used in basic arithmetic operation.");
1172 mthrow(
"Division by zero");
1181 template<
typename T>
1183 template<
typename T>
1185 template<
typename T>
1187 template<
typename T>
1189 template<
typename T>
1191 template<
typename T>
1193 template<
typename T>
1195 template<
typename T>
1197 template<
typename T>
1199 template<
typename T>
1201 template<
typename T>
1203 template<
typename T>
1208 std::string
type(mxml_get_name(node));
1210 unsigned int tid = 0;
1211 if (
type ==
"dir" ||
type ==
"odb")
1214 for (tid = 0; tid <
TID_LAST; tid++) {
1220 mthrow(
"Wrong key type in XML file");
1225 if (
type ==
"odb") {
1229 o->
set_name(mxml_get_attribute(node,
"name"));
1230 if (mxml_get_attribute(node,
"handle") ==
nullptr)
1231 mthrow(
"No \"handle\" attribute found in XML data");
1232 o->
set_hkey(std::stoi(std::string(mxml_get_attribute(node,
"handle"))));
1235 if (
type ==
"key") {
1236 std::string
value(mxml_get_value(node));
1238 }
else if (
type ==
"keyarray") {
1239 int n = std::atoi(mxml_get_attribute(node,
"num_values"));
1241 for (
int i=0 ;
i<
n ;
i++) {
1242 std::string
value(mxml_get_value(mxml_subnode(node,
i)));
1245 }
else if (
type ==
"dir" ||
type ==
"odb") {
1246 int n = mxml_get_number_of_children(node);
1248 for (
int i = 0;
i <
n;
i++) {
1254 mthrow(
"Unexpected XML element " + std::string(mxml_get_name(node)));
1263 switch (node->GetType()) {
1265 value = node->GetString();
1268 value = std::to_string(node->GetInt());
1271 value = std::to_string(node->GetDouble());
1274 value = std::to_string(node->GetBool());
1277 mthrow(
"Invalid MJSON type \"" + std::to_string(node->GetType()) +
"\"");
1285 int type = node->GetType();
1287 if (
type == MJSON_OBJECT) {
1288 const MJsonStringVector* names = node->GetObjectNames();
1289 const MJsonNodeVector* nodes = node->GetObjectNodes();
1290 if (names ==
nullptr || nodes==
nullptr || names->size() != nodes->size())
1291 mthrow(
"Invalid JSON format");
1301 for (
int i=0 ;
i<(int)names->size() ;
i++) {
1302 const char *
name = (*names)[
i].c_str();
1304 if (strchr(
name,
'/'))
1310 for (
int i=
n=0 ;
i<(int)names->size() ;
i++) {
1311 const char *
name = (*names)[
i].c_str();
1313 if (strchr(
name,
'/'))
1317 auto key = node->FindObjectNode((std::string(
name) +
"/key").c_str());
1319 t =
key->FindObjectNode(
"type")->GetInt();
1340 if (node->GetType() == MJSON_ARRAY) {
1341 const MJsonNodeVector* a = node->GetArray();
1343 for (
int i=0 ;
i<(int)a->size() ;
i++) {
1344 MJsonNode *
n = (*a)[
i];
1412 static void load(
const std::string &filename,
const std::string &odb_path);
1417 void connect(
const std::string &path,
const std::string &
name,
bool write_defaults,
bool delete_keys_not_in_defaults =
false);
1418 void connect(std::string
str,
bool write_defaults =
false,
bool delete_keys_not_in_defaults =
false);
1424 mthrow1(
"ODB source STRING requires a string");
1426 mthrow1(
"ODB source FILE requires a filename");
1438 void write(
int str_size = 0);
1440 std::string
print();
1444 void save(
const std::string &filename);
1451 void set(std::string
str);
1452 void set(std::string
s,
int i);
1471 void fix_order(std::vector<std::string> target_subkey_order);
1482 template<
typename T>
1492 template<
typename T>
1500 template<
typename T>
1508 template<
typename T>
1516 template<
typename T>
1524 template<
typename T>
1532 template<
typename T>
1540 template<
typename T>
1548 template<
typename T>
1556 template<
typename T>
1564 template<
typename T>
1572 template<
typename T>
bool operator!=(const iterator &other) const
void set_string_size(std::string s, int size)
std::string get_parent_path()
odb operator=(odb &&o)=delete
odb(std::initializer_list< T > list)
odb & operator*=(double d)
std::string get_full_path()
void set(std::string str)
static std::string node_to_string(const MJsonNode *node)
static bool exists(const std::string &name)
midas::odb * get_parent()
odb & operator+=(double d)
void set_auto_refresh_read(bool f)
void set_auto_enlarge_array(bool f)
odb(const std::array< T, SIZE > &arr)
void set_odb(odb *o, int i)
void deep_copy(odb &d, const odb &s)
static void set_debug(bool flag)
static midas::odb * odb_from_xml(PMXML_NODE node, odb *o)
bool is_auto_refresh_read() const
static void unwatch_all()
static void set_odb_source(odb::odb_source s)
std::function< void(midas::odb &)> m_watch_callback
bool is_auto_create() const
bool is_preserve_string_size() const
static void watch_callback(int hDB, int hKey, int index, void *info)
odb(const std::array< std::string, SIZE > &arr)
u_odb & operator[](int index)
odb(std::initializer_list< std::pair< const char *, midas::odb > > list)
static midas::odb * odb_from_json(const MJsonNode *node, std::string name, int tid, odb *o)
bool is_auto_refresh_write() const
u_odb & get_mdata(int index=0)
friend bool operator==(const midas::odb &o, const T &d)
odb & operator[](const char *str)
bool read_key(const std::string &path)
friend bool operator>=(const midas::odb &o, const T &d)
friend bool operator<=(const midas::odb &o, const T &d)
friend bool operator<(const midas::odb &o, const T &d)
void set_preserve_string_size(bool f)
static thread_local odb_source s_odb_source
void set_trigger_hotlink(bool f)
void set_flags(uint32_t f)
void set_auto_refresh_write(bool f)
void odb_from_xml_remote(const std::string &str)
void set_auto_create(bool f)
static thread_local std::string s_odb_source_str
void odb_from_xml_string(const std::string &str, const std::string &subkey)
void resize_mdata(int size)
static odb::odb_source get_odb_source()
friend bool operator>(const midas::odb &o, const T &d)
const std::vector< T > & operator=(const std::vector< T > &v)
const T & operator=(const T &v)
odb & get_subkey(std::string str)
void set_hkey(HNDLE hKey)
odb & operator/=(double d)
void odb_from_json_string(const std::string &str, const std::string &subkey)
void set_flags_recursively(uint32_t f)
unsigned int get_last_written()
void set_name(std::string s)
int get_subkeys(std::vector< std::string > &name)
void watch(std::function< void(midas::odb &)> f)
static thread_local odb * s_odb
friend std::ostream & operator<<(std::ostream &output, odb &o)
bool is_auto_enlarge_array() const
friend bool operator!=(const midas::odb &o, const T &d)
int detect_type(const T &)
void save(const std::string &filename)
void set_last_index(int i)
static int create(const char *name, int type=TID_KEY)
bool is_subkey(std::string str)
void fix_order(std::vector< std::string > target_subkey_order)
odb(const std::string &path, bool init_via_xml=false)
void connect_and_fix_structure(std::string path)
static bool s_connected_odb
const std::array< T, SIZE > & operator=(const std::array< T, SIZE > &arr)
odb & operator-=(double d)
void set_num_values(int n)
bool is_trigger_hotlink() const
bool write_key(std::string &path, bool write_defaults)
static midas::odb * search_hkey(midas::odb *po, int hKey)
static bool is_connected_odb()
odb(std::initializer_list< const char * > list)
static std::vector< midas::odb > m_watch
odb & operator[](std::string str)
static void load(const std::string &filename, const std::string &odb_path)
void set_parent(midas::odb *p)
void set_write_protect(bool f)
bool is_write_protect() const
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
u_odb & operator/=(double d)
uint8_t operator=(uint8_t v)
void mult(double f, bool push=true)
void set_string(std::string s)
u_odb & operator+=(double d)
u_odb & operator*=(double d)
friend std::ostream & operator<<(std::ostream &output, u_odb &o)
void set_string_size(std::string s, int size)
u_odb & operator-=(double d)
void set_string_ptr(std::string *s)
size_t string_size() const
BOOL equal_ustring(const char *str1, const char *str2)
const char * rpc_tid_name(INT id)
static void output(code_int code)
#define write(n, a, f, d)
static std::string indent(int x, const char *p=" ")
static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len)
bool operator>=(const midas::odb &o, const T &d)
bool operator>(const midas::odb &o, const T &d)
bool operator==(const midas::odb &o, const T &d)
bool operator<(const midas::odb &o, const T &d)
bool operator<=(const midas::odb &o, const T &d)
bool operator!=(const midas::odb &o, const T &d)
static te_expr * list(state *s)