-
Notifications
You must be signed in to change notification settings - Fork 2
/
isa_base.h
76 lines (64 loc) · 1.81 KB
/
isa_base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
@copyright Russell Standish 2000-2013
@author Russell Standish
This file is part of Classdesc
Open source licensed under the MIT license. See LICENSE for details.
*/
/**\file
\brief inheritance relationship descriptor
This descriptor is deprecated in favour of std::tr1::::is_base_of
*/
#ifndef CLASSDESC_ISA_BASE_H
#define CLASSDESC_ISA_BASE_H
#include <typeinfo>
#include <set>
#include "classdesc.h"
namespace classdesc
{
/// data structure for storing inheritance relationships
typedef std::set<const std::type_info*> isa_t;
}
namespace classdesc_access
{
template <class T> struct access_isa
{
void operator()(classdesc::isa_t& t,const classdesc::string& d, T& x) {}
};
}
namespace classdesc
{
template <class T>
void isa(classdesc::isa_t& t,const classdesc::string& d,T& x)
{
/* descend inheritance heirarchy only */
if (d.length()==0)
{
t.insert(&typeid(x));
classdesc_access::access_isa<T>()(t,d,x);
}
}
template <class T>
void isa(classdesc::isa_t& t,const classdesc::string& d, const T& x)
{isa(t,d,const_cast<T&>(x));}
template <class T, class U>
void isa(classdesc::isa_t& t,const classdesc::string& d, const T& x, const U& y) {}
template <class T, class U, class V>
//void isa(isa_t& t,classdesc::string d,const T& x, const U& y, const V& z) {}
void isa(classdesc::isa_t& t,classdesc::string d,const T& x, const U& y, const V& z,...) {}
template <class T>
void isa_onbase(isa_t& t, const string& d,T& a)
{isa(t,d,a);}
}
using classdesc::isa;
using classdesc::isa_onbase;
/**
return whether \a trialT is derived from \a baseT
*/
template <class trialT, class baseT>
bool isa(const trialT& x,const baseT& y)
{
classdesc::isa_t db;
isa(db,classdesc::string(),const_cast<trialT&>(x));
return db.count(&typeid(y));
}
#endif