1
1
#ifndef _META_H_59ROLBDK
2
- #include " ../kit.h"
3
2
#define _META_H_59ROLBDK
4
3
5
4
#include < boost/signals2.hpp>
@@ -54,50 +53,51 @@ struct MetaType {
54
53
return *this ;
55
54
}
56
55
57
- template <class T >
58
- MetaType (T val) {
59
-
60
- if (kit::is_shared_ptr<T>::value) {
61
- // if(typeid(val) == typeid(Storage<Meta<Mutex>>))
62
- id = ID::META;
63
- } else if (kit::is_local_shared_ptr<T>::value) {
64
- id = ID::META ;
56
+ template <class T , class U >
57
+ static MetaType create (T val) {
58
+ MetaType r;
59
+ // if(kit::is_shared_ptr<T>::value) {
60
+ if (typeid (val) == typeid (U)){
61
+ r. id = ID::META;
62
+ // else
63
+ // id = ID::USER ;
65
64
} else if (typeid (val) == typeid (std::string))
66
- id = ID::STRING;
65
+ r. id = ID::STRING;
67
66
else if (typeid (val) == typeid (bool )){
68
- id = ID::BOOL;
67
+ r. id = ID::BOOL;
69
68
}
70
69
else if (boost::is_integral<T>::value)
71
70
{
72
- id = ID::INT;
71
+ r. id = ID::INT;
73
72
// if(boost::is_signed<T>::value)
74
73
// flags |= SIGN;
75
74
}
76
75
else if (boost::is_floating_point<T>::value)
77
- id = ID::REAL;
76
+ r. id = ID::REAL;
78
77
// else if(is_pointer<char* const>::value)
79
78
// type = MetaType::STRING;
80
79
else if (typeid (val) == typeid (std::nullptr_t ))
81
80
{
82
- id = ID::EMPTY;
81
+ r. id = ID::EMPTY;
83
82
}
84
83
else if (kit::is_vector<T>::value)
85
- flags |= CONTAINER;
84
+ r. flags |= CONTAINER;
86
85
else if (typeid (val) == typeid (boost::any))
87
86
{
88
87
// if(val)
89
88
// {
90
89
WARNING (" adding raw boost::any value" );
91
- id = ID::USER;
90
+ r. id = ID::USER;
92
91
// }
93
92
// else
94
93
// id = ID::EMPTY;
95
94
}
96
95
else
97
96
{
98
97
// WARNINGf("unserializable type: %s", typeid(T).name());
99
- id = ID::USER;
98
+ r. id = ID::USER;
100
99
}
100
+ return r;
101
101
}
102
102
103
103
/*
@@ -575,8 +575,7 @@ class MetaBase:
575
575
Storage<MetaBase<Mutex,Storage,This>>& m
576
576
) {
577
577
auto l = this ->lock ();
578
- auto par = parent ();
579
- return par->first_key_of (m);
578
+ return parent ()->first_key_of (m);
580
579
}
581
580
582
581
// Storage<const MetaBase<Mutex,Storage,This>> parent_c() const {
@@ -590,7 +589,7 @@ class MetaBase:
590
589
591
590
Storage<MetaBase<Mutex,Storage,This>> parent (
592
591
unsigned lock_flags=0 ,
593
- bool recursion =false
592
+ bool root =false
594
593
){
595
594
auto l = this ->lock (std::defer_lock);
596
595
if (lock_flags & TRY_LOCK)
@@ -603,20 +602,20 @@ class MetaBase:
603
602
l.lock ();
604
603
}
605
604
606
- if (!recursion )
605
+ if (!root )
607
606
{
608
607
// auto p = m_pParent.lock();
609
608
// return p ? p : shared_from_this();
610
609
// return m_pParent.lock(); // allow null for this case
611
610
return m_pParent ?
612
611
m_pParent->shared () :
613
- this -> shared_from_this () ;
612
+ nullptr ;
614
613
}
615
614
else
616
615
{
617
616
// auto p = m_pParent.lock();
618
617
return m_pParent ?
619
- m_pParent->parent (lock_flags, recursion ) :
618
+ m_pParent->parent (lock_flags, root ) :
620
619
this ->shared_from_this ();
621
620
}
622
621
}
@@ -981,6 +980,7 @@ class MetaBase:
981
980
// // but does not overwrite a preexisting value with the given key
982
981
// ENSURE = kit::bit(0)
983
982
// };
983
+ using U = Storage<MetaBase<Mutex,Storage,This>>;
984
984
template <class T >
985
985
unsigned set (
986
986
const std::string& key,
@@ -998,10 +998,10 @@ class MetaBase:
998
998
if ((itr = m_Keys.find (key)) != m_Keys.end ()) {
999
999
// TODO: if dynamic typing is off, check type compatibility
1000
1000
auto & e = m_Elements[itr->second ];
1001
- if (e.type .id != MetaType (val).id )
1001
+ if (e.type .id != MetaType::create<T,U> (val).id )
1002
1002
{
1003
1003
// type changed
1004
- e.type = MetaType (val);
1004
+ e.type = MetaType::create<T,U> (val);
1005
1005
e.value = val;
1006
1006
e.on_change .disconnect_all_slots ();
1007
1007
}
@@ -1025,7 +1025,10 @@ class MetaBase:
1025
1025
const size_t idx = m_Elements.size ();
1026
1026
if (!key.empty ())
1027
1027
m_Keys[key] = idx;
1028
- m_Elements.emplace_back (MetaType (val), key, boost::any (val));
1028
+ {
1029
+ MetaType mt = MetaType::create<T,U>(val);
1030
+ m_Elements.emplace_back (mt, key, boost::any (val));
1031
+ }
1029
1032
1030
1033
if (
1031
1034
m_Elements[idx].type .id == MetaType::ID::META
@@ -1361,7 +1364,7 @@ class MetaBase:
1361
1364
){
1362
1365
// TODO: lock order is bad here, should be try_lock
1363
1366
auto l = this ->lock ();
1364
- return parent (lock_flags);
1367
+ return parent (lock_flags, true );
1365
1368
}
1366
1369
1367
1370
Storage<const MetaBase<Mutex,Storage,This>> root_c (
0 commit comments