-
Notifications
You must be signed in to change notification settings - Fork 2
/
refl++.hh
148 lines (119 loc) · 3.08 KB
/
refl++.hh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (C) 2011, 2013 Petr Machata <pmachata@redhat.com>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _REFL_HH_INCLUDED_
#define _REFL_HH_INCLUDED_
#include <stdexcept>
#include <memory>
#include <string>
#include <iosfwd>
#include <cstring>
#include <cassert>
#include "refl.h"
namespace reflpp
{
struct exception
: public std::runtime_error
{
exception (const char* what_arg)
: std::runtime_error (what_arg)
{}
};
class type;
class object;
class method;
class module;
class refl;
class type
{
friend class module;
friend class object;
friend std::ostream &operator<< (std::ostream &, type const &);
refl &__refl;
struct ::refl_type *__type;
type (refl &__r, struct ::refl_type *__t);
public:
size_t size_of ();
object create ();
bool is_pointer ();
};
std::ostream &operator<< (std::ostream &, type const &);
class object
{
friend class module;
friend class type;
refl &__refl;
struct ::refl_object *__obj;
object (refl &__r, struct ::refl_object *__o);
void check_sizeof (size_t sz);
void copy_from (void const *src, size_t sz);
void *checked_cdata ();
public:
object &operator= (object const &other);
reflpp::type type ();
object operator[] (std::string const &name);
object operator* ();
template <class T>
void
operator= (T const &other)
{
assert ((void *)this != (void *)&other);
check_sizeof (sizeof other);
void *buffer = checked_cdata ();
static_cast <T *> (buffer)->~T ();
new (buffer) T (other);
}
template <class T>
T &
as ()
{
check_sizeof (sizeof (T));
return *(T *)checked_cdata ();
}
};
class method
{
friend class module;
refl &__refl;
struct ::refl_method *__method;
method (refl &__r, struct ::refl_method *__m);
public:
};
class module
{
friend class refl;
refl &__refl;
struct ::refl_module *__mod;
module (refl &__r, struct ::refl_module *__m);
public:
type type_named (std::string const &name);
object object_named (std::string const &name);
method method_named (std::string const &name);
};
class refl
{
friend class module;
friend class type;
friend class object;
friend std::ostream &operator<< (std::ostream &, type const &);
struct ::refl *__refl;
public:
refl ();
module module_cur ();
module module_addr (void *addr);
};
}
#endif /* _REFL_HH_INCLUDED_ */