16#ifndef DO_NOT_DOCUMENT
33 friend std::ostream &
operator<<(std::ostream & os,
const SpartaHandler & md);
38 SpartaHandler() =
delete;
43 explicit SpartaHandler(
const char * name) :
45 clear_ptr(&do_nothing_method_stub),
49 arg_count_(std::numeric_limits<uint32_t>::max()),
56 SpartaHandler(
const SpartaHandler& rhp) =
default;
59 SpartaHandler& operator=(
const SpartaHandler&) =
default;
61 template <
class T,
void (T::*TMethod)()>
62 static SpartaHandler from_member(T* object_ptr,
const char * name =
"")
64 SpartaHandler d(name);
65 d.object_ptr = object_ptr;
66 d.stub_ptr = &method_stub<T, TMethod>;
71 template <
class T,
void (T::*TMethod)() const>
72 static SpartaHandler from_member(T* object_ptr,
const char * name =
"")
74 SpartaHandler d(name);
75 d.object_ptr = object_ptr;
76 d.stub_ptr = &method_stub<T, TMethod>;
81 template <
class T,
void (T::*TMethod)(),
void (T::*TMethodClear)()>
82 static SpartaHandler from_member_clear(T* object_ptr,
const char * name =
"")
84 SpartaHandler d(name);
85 d.object_ptr = object_ptr;
86 d.stub_ptr = &method_stub<T, TMethod>;
87 d.clear_ptr = &method_stub<T, TMethodClear>;
92 template <
class T,
void (T::*TMethod)() const,
void (T::*TMethodClear)()>
93 static SpartaHandler from_member_clear(T* object_ptr,
const char * name =
"")
95 SpartaHandler d(name);
96 d.object_ptr = object_ptr;
97 d.stub_ptr = &method_stub<T, TMethod>;
98 d.clear_ptr = &method_stub<T, TMethodClear>;
103 template <
class T,
class DataT,
void (T::*TMethod)(const DataT &)>
104 static SpartaHandler from_member_1(T* object_ptr,
const char * name =
"")
106 SpartaHandler d(name);
107 d.object_ptr = object_ptr;
108 d.stub_ptr_1 = &method_stub_1<T, DataT, TMethod>;
113 template <
class T,
class DataT,
void (T::*TMethod)(const DataT &) const>
114 static SpartaHandler from_member_1(T* object_ptr,
const char * name =
"")
116 SpartaHandler d(name);
117 d.object_ptr = object_ptr;
118 d.stub_ptr_1 = &method_stub_1<T, DataT, TMethod>;
123 template <
class T,
class DataT,
class DataTwo,
void (T::*TMethod)(const DataT &, const DataTwo&)>
124 static SpartaHandler from_member_2(T* object_ptr,
const char * name =
"")
126 SpartaHandler d(name);
127 d.object_ptr = object_ptr;
128 d.stub_ptr_2 = &method_stub_2<T, DataT, DataTwo, TMethod>;
133 template <
class T,
class DataT,
class DataTwo,
void (T::*TMethod)(const DataT &, const DataTwo&) const>
134 static SpartaHandler from_member_2(T* object_ptr,
const char * name =
"")
136 SpartaHandler d(name);
137 d.object_ptr = object_ptr;
138 d.stub_ptr_2 = &method_stub_2<T, DataT, DataTwo, TMethod>;
143 void operator()()
const
145 (*stub_ptr)(object_ptr);
150 void operator()(
const void * dat)
const
152 (*stub_ptr_1)(object_ptr, dat);
155 void operator()(
const void* dat,
const void* dat_two)
const
157 (*stub_ptr_2)(object_ptr, dat, dat_two);
161 void setObjectPtr(ObjT * obj) {
162 object_ptr = (
void *)obj;
166 ObjT* getObjectPtr() {
167 return static_cast<ObjT*
>(object_ptr);
171 (*clear_ptr)(object_ptr);
174 uint32_t argCount()
const {
178 const char * getName()
const {
182 void setName(
const char * name) {
186 bool operator==(
const SpartaHandler & rhs)
const {
187 return (std::string(name_) == rhs.name_);
190 bool operator!=(
const SpartaHandler & rhs)
const {
191 return !operator==(rhs);
195 bool operator==(ObjT* obj)
const {
196 return object_ptr ==
static_cast<void*
>(obj);
200 bool operator!=(ObjT* obj)
const {
201 return !operator==(obj);
204 operator bool()
const {
205 return (object_ptr !=
nullptr);
210 typedef void (*stub_type)(
void* object_ptr);
211 typedef void (*stub_type_1)(
void* object_ptr,
const void*);
212 typedef void (*stub_type_2)(
void* object_ptr,
const void*,
const void*);
217 stub_type_1 stub_ptr_1;
218 stub_type_2 stub_ptr_2;
224 static void do_nothing_method_stub(
void*)
227 template <
class T,
void (T::*TMethod)()>
228 static void method_stub(
void* object_ptr)
230 T* p =
static_cast<T*
>(object_ptr);
234 template <
class T,
void (T::*TMethod)() const>
235 static void method_stub(
void* object_ptr)
237 T* p =
static_cast<T*
>(object_ptr);
241 template <
class T,
class DataT,
void (T::*TMethod)(const DataT &)>
242 static void method_stub_1(
void* object_ptr,
const void * dat)
244 T* p =
static_cast<T*
>(object_ptr);
245 const DataT & data = *(
static_cast<const DataT *
>(dat));
249 template <
class T,
class DataT,
void (T::*TMethod)(const DataT &) const>
250 static void method_stub_1(
void* object_ptr,
const void * dat)
252 T* p =
static_cast<T*
>(object_ptr);
253 const DataT & data = *(
static_cast<const DataT *
>(dat));
257 template <
class T,
class DataT,
class DataTwo,
void (T::*TMethod)(const DataT &, const DataTwo&)>
258 static void method_stub_2(
void* object_ptr,
const void * dat,
const void * dat_two)
260 T* p =
static_cast<T*
>(object_ptr);
261 const DataT & data = *(
static_cast<const DataT *
>(dat));
262 const DataTwo & data_two = *(
static_cast<const DataTwo *
>(dat_two));
263 (p->*TMethod)(data, data_two);
266 template <
class T,
class DataT,
class DataTwo,
void (T::*TMethod)(const DataT &, const DataTwo&) const>
267 static void method_stub_2(
void* object_ptr,
const void * dat,
const void * dat_two)
269 T* p =
static_cast<T*
>(object_ptr);
270 const DataT & data = *(
static_cast<const DataT *
>(dat));
271 const DataTwo & data_two = *(
static_cast<const DataTwo *
>(dat_two));
272 (p->*TMethod)(data, data_two);
276 inline std::ostream &
operator<<(std::ostream & os,
const SpartaHandler & md) {
317#define CREATE_SPARTA_HANDLER(clname, meth) \
318 sparta::SpartaHandler::from_member<clname, &clname::meth> \
319 (this, #clname"::"#meth"()")
364#define CREATE_SPARTA_HANDLER_WITH_CLEAR(clname, meth, clear) \
365 sparta::SpartaHandler::from_member_clear<clname, &clname::meth, &clname::clear>\
366 (this, #clname"::"#meth"()")
401#define CREATE_SPARTA_HANDLER_WITH_OBJ(clname, obj, meth) \
402 sparta::SpartaHandler::from_member<clname, &clname::meth> \
403 (obj, #clname"::"#meth"()")
441#define CREATE_SPARTA_HANDLER_WITH_DATA(clname, meth, dataT) \
442 sparta::SpartaHandler::from_member_1<clname, dataT, &clname::meth> \
443 (this, #clname"::"#meth"("#dataT")")
480#define CREATE_SPARTA_HANDLER_WITH_TWO_DATA(clname, meth, dataOne, dataTwo) \
481 sparta::SpartaHandler::from_member_2<clname, dataOne, dataTwo, &clname::meth> \
482 (this, #clname"::"#meth"("#dataOne","#dataTwo")")
518#define CREATE_SPARTA_HANDLER_WITH_DATA_WITH_OBJ(clname, obj, meth, dataT) \
519 sparta::SpartaHandler::from_member_1<clname, dataT, &clname::meth> \
520 (obj, #clname"::"#meth"("#dataT")")
Macros for handling exponential backoff.
std::ostream & operator<<(std::ostream &o, const SimulationInfo &info)
ostream insertion operator for SimulationInfo