9 #ifndef RMF_INFRASTRUCTURE_MACROS_H
10 #define RMF_INFRASTRUCTURE_MACROS_H
16 #include "internal/use.h"
18 #include <boost/config.hpp>
19 #include <boost/version.hpp>
22 #define RMF_FOREACH(v, r) for (v : r)
30 #if defined(RMF_DOXYGEN)
42 #define RMF_COMPARISONS(Name)
46 #define RMF_SWIG_COMPARISONS(Name) \
47 bool __eq__(const Name& o) const; \
48 bool __ne__(const Name& o) const; \
49 bool __lt__(const Name& o) const; \
50 bool __gt__(const Name& o) const; \
51 bool __ge__(const Name& o) const; \
52 bool __le__(const Name& o) const
54 #define RMF_COMPARISONS(Name) RMF_SWIG_COMPARISONS(Name)
58 #define RMF_SWIG_COMPARISONS(Name) \
59 bool __eq__(const Name& o) const { return operator==(o); } \
60 bool __ne__(const Name& o) const { return operator!=(o); } \
61 bool __lt__(const Name& o) const { return operator<(o); } \
62 bool __gt__(const Name& o) const { return operator>(o); } \
63 bool __ge__(const Name& o) const { return operator>=(o); } \
64 bool __le__(const Name& o) const { return operator<=(o); } \
65 int __cmp__(const Name& o) const { return compare(o); }
67 #define RMF_COMPARISONS(Name) \
68 bool operator==(const Name& o) const { return compare(o) == 0; } \
69 bool operator!=(const Name& o) const { return compare(o) != 0; } \
70 bool operator<(const Name& o) const { return compare(o) < 0; } \
71 bool operator>(const Name& o) const { return compare(o) > 0; } \
72 bool operator>=(const Name& o) const { return compare(o) >= 0; } \
73 bool operator<=(const Name& o) const { return compare(o) <= 0; } \
74 RMF_SWIG_COMPARISONS(Name)
81 #define RMF_HASHABLE(name, hashret)
84 #define RMF_HASHABLE(name, hashret) \
85 std::size_t __hash__() const { hashret; }
90 #define RMF_SHOWABLE(Name, streamed) \
91 std::string __str__() const { \
92 std::ostringstream out; \
96 std::string __repr__() const { \
97 std::ostringstream out; \
102 #elif defined(RMF_DOXYGEN)
103 #define RMF_SHOWABLE(Name, streamed)
106 #define RMF_SHOWABLE(Name, streamed) \
107 operator Showable() const { \
108 std::ostringstream oss; \
110 return Showable(oss.str(), Showable::Special()); \
112 void show(std::ostream& out) const { out << streamed; } \
113 std::string __str__() const { \
114 std::ostringstream out; \
118 std::string __repr__() const { \
119 std::ostringstream out; \
126 #define RMF_UNUSED(variable) RMF::internal::use(variable);
132 #define RMF_NO_RETURN(type) return type()
139 #define RMF_FOREACH_SIMPLE_TYPE(macroname) \
140 macroname(int, Int, int, int, const Ints&, Ints); \
141 macroname(float, Float, float, float, const Floats&, Floats); \
142 macroname(index, Index, int, int, const Ints&, Ints)
153 #define RMF_FOREACH_TYPE(macroname) \
154 macroname(RMF::IntTraits, Int) macroname(RMF::FloatTraits, Float) \
155 macroname(RMF::StringTraits, String) macroname(RMF::IntsTraits, Ints) \
156 macroname(RMF::FloatsTraits, Floats) \
157 macroname(RMF::StringsTraits, Strings) \
158 macroname(RMF::Vector3Traits, Vector3) \
159 macroname(RMF::Vector4Traits, Vector4) \
160 macroname(RMF::Vector3sTraits, Vector3s)
162 #define RMF_DECORATOR_CATCH(extra_info) \
163 catch (Exception& e) { \
164 RMF_RETHROW(Decorator(get_decorator_type_name()) extra_info, e); \
169 #define RMF_VALIDATOR(Type) RMF::Registrar<Type> Type##Reg(#Type);
175 #if !defined(RMF_DOXYGEN) && !defined(SWIG)
177 inline std::ostream& operator<<(std::ostream& out,
const Showable& t);
183 explicit Showable(
const T& t) {
184 std::ostringstream oss;
188 template <
class T,
class TT>
189 Showable(
const std::pair<T, TT>& p) {
190 std::ostringstream oss;
191 oss <<
"(" << p.first <<
", " << p.second <<
")";
194 Showable(std::string t) : t_(std::string(
"\"") + t +
"\"") {}
196 Showable(std::string t, Special) : t_(t) {}
198 Showable(
const std::vector<T>& t) {
199 std::ostringstream out;
201 for (
unsigned int i = 0; i < t.size(); ++i) {
211 Showable(
const Nullable<Tr>& t) {
212 std::ostringstream out;
221 inline std::ostream& operator<<(std::ostream& out,
const Showable& t) {
Return a possibly null value.
Various compiler workarounds.