24#include <initializer_list>
135 operator std::string();
136 operator const char *();
165 m_string =
new std::string(std::to_string(v));
167 mthrow(
"Invalid type ID " + std::to_string(
m_tid));
183 mthrow(
"Subkey can only be assigned to ODB key");
189 mthrow(
"Subkey can only be assigned to ODB key");
223 mthrow(
"Invalid type ID " + std::to_string(
m_tid));
237 void mult(
double f,
bool push =
true);
277 mthrow(
"Division by zero");
340 mthrow(
"Subkey not found");
342 mthrow(
"Invalid type ID %s" + std::to_string(
m_tid));
364 void get(std::string &
s);
369 mthrow(
"odb_get() called for non-key object");
375 mthrow(
"odb_get() called for non-key object");
484 "]\" contains array. Please assign to std::vector.");
494 mthrow(
"ODB key \"" +
get_full_path() +
"\" contains array. Please assign to std::vector.");
501 void get(std::string &
s,
bool quotes =
false,
bool refresh =
true);
508 bool read_key(
const std::string &path);
565 odb(std::initializer_list<std::pair<const char *, midas::odb>>
list) :
odb() {
572 for (
int j=0 ;
j<
i ;
j++) {
577 mthrow(
"ODB key \"" + std::string(
element.first) +
"\" exists already as \"" +
609 template<
typename T,
size_t SIZE>
623 template<
size_t SIZE>
651 mthrow(
"ODB key \"" +
str +
"\" not found in ODB");
687 if (std::is_same<T, uint8_t>::value)
689 else if (std::is_same<T, int8_t>::value)
691 else if (std::is_same<T, uint16_t>::value)
693 else if (std::is_same<T, int16_t>::value)
695 else if (std::is_same<T, uint32_t>::value)
697 else if (std::is_same<T, unsigned long>::value &&
sizeof(
long) == 4)
699 else if (std::is_same<T, int32_t>::value)
701 else if (std::is_same<T, long>::value &&
sizeof(
long) == 4)
703 else if (std::is_same<T, uint64_t>::value)
705 else if (std::is_same<T, unsigned long>::value &&
sizeof(
long) == 8)
707 else if (std::is_same<T, int64_t>::value)
709 else if (std::is_same<T, long>::value &&
sizeof(
long) == 8)
711 else if (std::is_same<T, bool>::value)
713 else if (std::is_same<T, float>::value)
715 else if (std::is_same<T, double>::value)
728 if (m_num_values == 0) {
750 const std::vector<T> &
operator=(
const std::vector<T> &v) {
755 if (m_num_values == 0) {
758 if (std::is_same<T, bool>::value) {
795 template<
typename T,
size_t SIZE>
801 if (m_num_values == 0) {
828 operator std::string() {
839 operator std::vector<T>() {
848 operator std::vector<std::string>() {
858 template<
typename T,
typename std::enable_if<
859 std::is_same<T, uint8_t>::value ||
860 std::is_same<T, int8_t>::value ||
861 std::is_same<T, uint16_t>::value ||
862 std::is_same<T, int16_t>::value ||
863 std::is_same<T, uint32_t>::value ||
864 std::is_same<T, int32_t>::value ||
865 std::is_same<T, uint64_t>::value ||
866 std::is_same<T, int64_t>::value ||
867 std::is_same<T, bool>::value ||
868 std::is_same<T, float>::value ||
869 std::is_same<T, double>::value, T>
::type * =
nullptr>
893 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) +
"]\"");
910 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)");
931 template <
typename T>
967 "\" contains array which cannot be used in basic arithmetic operation.");
968 if (std::is_same<T, midas::odb>::value) {
974 double s1 =
static_cast<double>(
m_data[0]);
975 double s2 =
static_cast<double>(
i.m_data[0]);
989 "\" contains array which cannot be used in basic arithmetic operation.");
990 if (std::is_same<T, midas::odb>::value) {
996 double s1 =
static_cast<double>(
m_data[0]);
997 double s2 =
static_cast<double>(
i.m_data[0]);
1007 template<
typename T>
1011 "\" contains array which cannot be used in basic arithmetic operation.");
1018 template<
typename T>
1022 "\" contains array which cannot be used in basic arithmetic operation.");
1107 mthrow(
"Division by zero");
1116 template<
typename T>
1118 template<
typename T>
1120 template<
typename T>
1122 template<
typename T>
1124 template<
typename T>
1126 template<
typename T>
1128 template<
typename T>
1130 template<
typename T>
1132 template<
typename T>
1134 template<
typename T>
1136 template<
typename T>
1138 template<
typename T>
1145 unsigned int tid = 0;
1149 for (tid = 0; tid <
TID_LAST; tid++) {
1155 mthrow(
"Wrong key type in XML file");
1162 mthrow(
"No \"handle\" attribute found in XML data");
1165 if (
type ==
"key") {
1168 }
else if (
type ==
"keyarray") {
1170 o->set_num_values(
n);
1171 for (
int i=0 ;
i<
n ;
i++) {
1175 }
else if (
type ==
"dir") {
1177 o->set_num_values(
n);
1178 for (
int i = 0;
i <
n;
i++) {
1244 static void load(
const std::string &filename,
const std::string &odb_path);
1256 std::string
print();
1260 void save(
const std::string &filename);
1267 void set(std::string
str);
1268 void set(std::string
s,
int i);
1298 template<
typename T>
1308 template<
typename T>
1316 template<
typename T>
1324 template<
typename T>
1332 template<
typename T>
1340 template<
typename T>
1348 template<
typename T>
1356 template<
typename T>
1364 template<
typename T>
1372 template<
typename T>
1380 template<
typename T>
1388 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()
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)
bool is_auto_refresh_read() const
static void unwatch_all()
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)
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)
void set_trigger_hotlink(bool f)
void set_flags(uint32_t f)
void set_auto_refresh_write(bool f)
void set_auto_create(bool f)
void resize_mdata(int size)
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 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)
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)
odb(const std::string &str, bool init_via_xml=false)
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)
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)
midas::odb * odb_from_xml(PMXML_NODE node, odb *o)
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)
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)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
static te_expr * list(state *s)