Skip to content

Commit d11744e

Browse files
committed
fixed typeinfo not being set correctly (reflected in last unit test)
1 parent 83d2251 commit d11744e

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

kit/kit.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <future>
1414
#include <chrono>
1515
#include <boost/algorithm/string.hpp>
16-
#include <boost/smart_ptr/local_shared_ptr.hpp>
16+
#include <kit/local_shared_ptr.hpp>
1717
#include <boost/optional.hpp>
1818
#include <boost/bimap.hpp>
1919
#include <boost/any.hpp>
@@ -71,14 +71,14 @@ namespace kit
7171
struct is_shared_ptr<std::shared_ptr<T>> {
7272
static bool const value = true;
7373
};
74-
template<class T, class _ = void>
75-
struct is_local_shared_ptr {
76-
static const bool value = false;
77-
};
7874
template<class T>
79-
struct is_local_shared_ptr<boost::local_shared_ptr<T>> {
75+
struct is_shared_ptr<kit::local_shared_ptr<T>> {
8076
static bool const value = true;
8177
};
78+
//template<class T>
79+
//struct is_shared_ptr<boost::shared_ptr<T>> {
80+
// static bool const value = true;
81+
//};
8282

8383
template<class T>
8484
T mod(T a, T b)

kit/meta/meta.h

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#ifndef _META_H_59ROLBDK
2-
#include "../kit.h"
32
#define _META_H_59ROLBDK
43

54
#include <boost/signals2.hpp>
@@ -54,50 +53,51 @@ struct MetaType {
5453
return *this;
5554
}
5655

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;
6564
} else if(typeid(val) == typeid(std::string))
66-
id = ID::STRING;
65+
r.id = ID::STRING;
6766
else if(typeid(val) == typeid(bool)){
68-
id = ID::BOOL;
67+
r.id = ID::BOOL;
6968
}
7069
else if(boost::is_integral<T>::value)
7170
{
72-
id = ID::INT;
71+
r.id = ID::INT;
7372
//if(boost::is_signed<T>::value)
7473
// flags |= SIGN;
7574
}
7675
else if(boost::is_floating_point<T>::value)
77-
id = ID::REAL;
76+
r.id = ID::REAL;
7877
//else if(is_pointer<char* const>::value)
7978
// type = MetaType::STRING;
8079
else if(typeid(val) == typeid(std::nullptr_t))
8180
{
82-
id = ID::EMPTY;
81+
r.id = ID::EMPTY;
8382
}
8483
else if(kit::is_vector<T>::value)
85-
flags |= CONTAINER;
84+
r.flags |= CONTAINER;
8685
else if(typeid(val) == typeid(boost::any))
8786
{
8887
//if(val)
8988
//{
9089
WARNING("adding raw boost::any value");
91-
id = ID::USER;
90+
r.id = ID::USER;
9291
//}
9392
//else
9493
// id = ID::EMPTY;
9594
}
9695
else
9796
{
9897
//WARNINGf("unserializable type: %s", typeid(T).name());
99-
id = ID::USER;
98+
r.id = ID::USER;
10099
}
100+
return r;
101101
}
102102

103103
/*
@@ -575,8 +575,7 @@ class MetaBase:
575575
Storage<MetaBase<Mutex,Storage,This>>& m
576576
) {
577577
auto l = this->lock();
578-
auto par = parent();
579-
return par->first_key_of(m);
578+
return parent()->first_key_of(m);
580579
}
581580

582581
//Storage<const MetaBase<Mutex,Storage,This>> parent_c() const {
@@ -590,7 +589,7 @@ class MetaBase:
590589

591590
Storage<MetaBase<Mutex,Storage,This>> parent(
592591
unsigned lock_flags=0,
593-
bool recursion=false
592+
bool root=false
594593
){
595594
auto l = this->lock(std::defer_lock);
596595
if(lock_flags & TRY_LOCK)
@@ -603,20 +602,20 @@ class MetaBase:
603602
l.lock();
604603
}
605604

606-
if(!recursion)
605+
if(!root)
607606
{
608607
//auto p = m_pParent.lock();
609608
//return p ? p : shared_from_this();
610609
//return m_pParent.lock(); // allow null for this case
611610
return m_pParent ?
612611
m_pParent->shared() :
613-
this->shared_from_this();
612+
nullptr;
614613
}
615614
else
616615
{
617616
//auto p = m_pParent.lock();
618617
return m_pParent ?
619-
m_pParent->parent(lock_flags, recursion) :
618+
m_pParent->parent(lock_flags, root) :
620619
this->shared_from_this();
621620
}
622621
}
@@ -981,6 +980,7 @@ class MetaBase:
981980
// // but does not overwrite a preexisting value with the given key
982981
// ENSURE = kit::bit(0)
983982
//};
983+
using U = Storage<MetaBase<Mutex,Storage,This>>;
984984
template<class T>
985985
unsigned set(
986986
const std::string& key,
@@ -998,10 +998,10 @@ class MetaBase:
998998
if((itr = m_Keys.find(key)) != m_Keys.end()) {
999999
// TODO: if dynamic typing is off, check type compatibility
10001000
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)
10021002
{
10031003
// type changed
1004-
e.type = MetaType(val);
1004+
e.type = MetaType::create<T,U>(val);
10051005
e.value = val;
10061006
e.on_change.disconnect_all_slots();
10071007
}
@@ -1025,7 +1025,10 @@ class MetaBase:
10251025
const size_t idx = m_Elements.size();
10261026
if(!key.empty())
10271027
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+
}
10291032

10301033
if(
10311034
m_Elements[idx].type.id == MetaType::ID::META
@@ -1361,7 +1364,7 @@ class MetaBase:
13611364
){
13621365
// TODO: lock order is bad here, should be try_lock
13631366
auto l = this->lock();
1364-
return parent(lock_flags);
1367+
return parent(lock_flags,true);
13651368
}
13661369

13671370
Storage<const MetaBase<Mutex,Storage,This>> root_c(

0 commit comments

Comments
 (0)