Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
macros.h
1
/*
2
* serial module macors
3
*
4
* This file is part of OTAWA
5
* Copyright (c) 2006, IRIT UPS.
6
*
7
* OTAWA is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
11
*
12
* OTAWA is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with OTAWA; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
#ifndef ELM_SERIAL2_MACROS_H
22
#define ELM_SERIAL2_MACROS_H
23
24
#include <elm/rtti/Enum.h>
25
#include <elm/serial2/serial.h>
26
27
#define ELM_SERIALIZABLE_EXTEND(name, base, fields) \
28
public: \
29
typedef base __base; \
30
static const elm::serial2::AbstractClass& __class(void); \
31
static const elm::serial2::AbstractClass& __type; \
32
virtual const elm::serial2::AbstractClass& __actual_class(void) const { return __type; } \
33
template <class T> void __visit(T& e) { e & fields; } \
34
template <class T> void __visit(T& e) const { e & fields; } \
35
private:
36
37
#define ELM_SERIALIZABLE(name, fields) ELM_SERIALIZABLE_EXTEND(name, void, fields)
38
39
#define ELM_SERIALIZE(name) \
40
const elm::serial2::AbstractClass& name::__class(void) { static elm::serial2::Class<name> _(#name); return _; } \
41
const elm::serial2::AbstractClass& name::__type = __class();
42
43
#define ELM_SERIALIZE_EXTENDED(name, ext) \
44
const elm::serial2::AbstractClass& name::__class(void) { static elm::serial2::Class<name, ext> _(#name); return _; } \
45
const elm::serial2::AbstractClass& name::__type = __class();
46
47
#define ELM_FIELD(name) elm::field(#name, name)
48
#define ELM_DFIELD(name, def) elm::field(#name, name, def)
49
#define ELM_BASE(name) elm::serial2::Base<name>(static_cast<const name *>(this))
50
51
52
#define ELM_ENUM(type) \
53
namespace elm { \
54
template <> struct type_info<type>: public enum_t<type> { \
55
static elm::rtti::Enum::Value __vals[]; \
56
static inline CString name(void) { return "<enum " #type ">"; } \
57
static inline elm::rtti::Enum::Value *values(void) { return __vals; } \
58
}; \
59
namespace rtti { template <> inline const Type& _type<type>::_(void){ static Enum _("", elm::type_info<type>::__vals); return _; } } \
60
inline elm::io::Output& operator<<(io::Output& out, type value) { out << elm::type_of<type>().asEnum().nameFor(value); return out; } \
61
}
62
#define ELM_ENUM_BEGIN(type) \
63
namespace elm { \
64
elm::rtti::Enum::Value type_info<type>::__vals[] = {
65
#define ELM_ENUM_END \
66
, rtti::value("", 0) \
67
}; \
68
}
69
#define ELM_VALUE(name) elm::rtti::Enum::Value(elm::_unqualify(#name), name)
70
71
72
#ifndef ELM_NO_SHORTCUT
73
# define SERIALIZABLE(name, fields) ELM_SERIALIZABLE(name, fields)
74
# define SERIALIZABLE_EXTEND(name, base, fields) ELM_SERIALIZABLE_EXTEND(name, base, fields)
75
# define SERIALIZE(name) ELM_SERIALIZE(name)
76
# define SERIALIZE_EXTENDED(name, ext) ELM_SERIALIZE_EXTENDED(name, ext)
77
# define FIELD(name) ELM_FIELD(name)
78
# define DFIELD(name, def) ELM_DFIELD(name, def)
79
# define BASE(name) ELM_BASE(name)
80
# define ENUM(type) ELM_ENUM(type)
81
# define VALUE(name) ELM_VALUE(name)
82
# define ENUM_BEGIN(type) ELM_ENUM_BEGIN(type)
83
# define ENUM_END ELM_ENUM_END
84
#endif
85
86
#endif // ELM_SERIAL2_MACROS_H
include
elm
serial2
macros.h
Generated on Fri Jul 23 2021 11:32:45 for Elm by
1.8.17