16 #ifndef __OMNETPP_CSTLWATCH_H
17 #define __OMNETPP_CSTLWATCH_H
26 #include "cownedobject.h"
34 class SIM_API cStdVectorWatcherBase :
public cWatchBase
37 mutable cClassDescriptor *desc;
39 cStdVectorWatcherBase(
const char *name) : cWatchBase(name) {desc =
nullptr;}
41 virtual std::string str()
const override;
42 virtual bool supportsAssignment()
const override {
return false;}
44 virtual const char *getElemTypeName()
const = 0;
45 virtual int size()
const = 0;
46 virtual std::string at(
int i)
const = 0;
47 virtual cClassDescriptor *getDescriptor()
const override;
55 class cStdVectorWatcher :
public cStdVectorWatcherBase
59 std::string classname;
61 cStdVectorWatcher(
const char *name, std::vector<T>& var) : cStdVectorWatcherBase(name), v(var) {
62 classname = std::string(
"std::vector<")+
opp_typename(
typeid(T))+
">";
64 const char *getClassName()
const override {
return classname.c_str();}
65 virtual const char *getElemTypeName()
const override {
return opp_typename(
typeid(T));}
66 virtual int size()
const override {
return v.size();}
67 virtual std::string at(
int i)
const override {std::stringstream out; out << v[i];
return out.str();}
71 void createStdVectorWatcher(
const char *varname, std::vector<T>& v)
73 new cStdVectorWatcher<T>(varname, v);
81 class cStdPointerVectorWatcher :
public cStdVectorWatcher<T>
84 cStdPointerVectorWatcher(
const char *name, std::vector<T>& var) : cStdVectorWatcher<T>(name, var) {}
85 virtual std::string at(
int i)
const {std::stringstream out; out << *(this->v[i]);
return out.str();}
89 void createStdPointerVectorWatcher(
const char *varname, std::vector<T>& v)
91 new cStdPointerVectorWatcher<T>(varname, v);
98 class cStdListWatcher :
public cStdVectorWatcherBase
102 std::string classname;
103 mutable typename std::list<T>::iterator it;
106 cStdListWatcher(
const char *name, std::list<T>& var) : cStdVectorWatcherBase(name), v(var) {
108 classname = std::string(
"std::list<")+
opp_typename(
typeid(T))+
">";
110 const char *getClassName()
const override {
return classname.c_str();}
111 virtual const char *getElemTypeName()
const override {
return opp_typename(
typeid(T));}
112 virtual int size()
const override {
return v.size();}
113 virtual std::string at(
int i)
const override {
118 it=v.begin(); itPos=0;
119 }
else if (i==itPos+1 && it!=v.end()) {
123 for (
int k=0; k<i && it!=v.end(); k++) ++it;
127 return std::string(
"out of bounds");
131 virtual std::string atIt()
const {
132 std::stringstream out;
139 void createStdListWatcher(
const char *varname, std::list<T>& v)
141 new cStdListWatcher<T>(varname, v);
149 class cStdPointerListWatcher :
public cStdListWatcher<T>
152 cStdPointerListWatcher(
const char *name, std::list<T>& var) : cStdListWatcher<T>(name, var) {}
153 virtual std::string atIt()
const {
154 std::stringstream out;
161 void createStdPointerListWatcher(
const char *varname, std::list<T>& v)
163 new cStdPointerListWatcher<T>(varname, v);
171 class cStdSetWatcher :
public cStdVectorWatcherBase
175 std::string classname;
176 mutable typename std::set<T>::iterator it;
179 cStdSetWatcher(
const char *name, std::set<T>& var) : cStdVectorWatcherBase(name), v(var) {
181 classname = std::string(
"std::set<")+
opp_typename(
typeid(T))+
">";
183 const char *getClassName()
const override {
return classname.c_str();}
184 virtual const char *getElemTypeName()
const override {
return opp_typename(
typeid(T));}
185 virtual int size()
const override {
return v.size();}
186 virtual std::string at(
int i)
const override {
191 it=v.begin(); itPos=0;
192 }
else if (i==itPos+1 && it!=v.end()) {
196 for (
int k=0; k<i && it!=v.end(); k++) ++it;
200 return std::string(
"out of bounds");
204 virtual std::string atIt()
const {
205 std::stringstream out;
212 void createStdSetWatcher(
const char *varname, std::set<T>& v)
214 new cStdSetWatcher<T>(varname, v);
222 class cStdPointerSetWatcher :
public cStdSetWatcher<T>
225 cStdPointerSetWatcher(
const char *name, std::set<T>& var) : cStdSetWatcher<T>(name, var) {}
226 virtual std::string atIt()
const {
227 std::stringstream out;
234 void createStdPointerSetWatcher(
const char *varname, std::set<T>& v)
236 new cStdPointerSetWatcher<T>(varname, v);
243 template<
class KeyT,
class ValueT,
class CmpT>
244 class cStdMapWatcher :
public cStdVectorWatcherBase
247 std::map<KeyT,ValueT,CmpT>& m;
248 mutable typename std::map<KeyT,ValueT,CmpT>::iterator it;
250 std::string classname;
252 cStdMapWatcher(
const char *name, std::map<KeyT,ValueT,CmpT>& var) : cStdVectorWatcherBase(name), m(var) {
256 const char *getClassName()
const override {
return classname.c_str();}
257 virtual const char *getElemTypeName()
const override {
return "pair<,>";}
258 virtual int size()
const override {
return m.size();}
259 virtual std::string at(
int i)
const override {
264 it=m.begin(); itPos=0;
265 }
else if (i==itPos+1 && it!=m.end()) {
269 for (
int k=0; k<i && it!=m.end(); k++) ++it;
273 return std::string(
"out of bounds");
277 virtual std::string atIt()
const {
278 std::stringstream out;
279 out << it->first <<
" ==> " << it->second;
284 template <
class KeyT,
class ValueT,
class CmpT>
285 void createStdMapWatcher(
const char *varname, std::map<KeyT,ValueT,CmpT>& m)
287 new cStdMapWatcher<KeyT,ValueT,CmpT>(varname, m);
294 template<
class KeyT,
class ValueT,
class CmpT>
295 class cStdPointerMapWatcher :
public cStdMapWatcher<KeyT,ValueT,CmpT>
298 cStdPointerMapWatcher(
const char *name, std::map<KeyT,ValueT,CmpT>& var) : cStdMapWatcher<KeyT,ValueT,CmpT>(name, var) {}
299 virtual std::string atIt()
const {
300 std::stringstream out;
301 out << this->it->first <<
" ==> " << *(this->it->second);
306 template<
class KeyT,
class ValueT,
class CmpT>
307 void createStdPointerMapWatcher(
const char *varname, std::map<KeyT,ValueT,CmpT>& m)
309 new cStdPointerMapWatcher<KeyT,ValueT,CmpT>(varname, m);
323 #define WATCH_VECTOR(variable) omnetpp::createStdVectorWatcher(#variable,(variable))
330 #define WATCH_PTRVECTOR(variable) omnetpp::createStdPointerVectorWatcher(#variable,(variable))
337 #define WATCH_LIST(variable) omnetpp::createStdListWatcher(#variable,(variable))
344 #define WATCH_PTRLIST(variable) omnetpp::createStdPointerListWatcher(#variable,(variable))
351 #define WATCH_SET(variable) omnetpp::createStdSetWatcher(#variable,(variable))
358 #define WATCH_PTRSET(variable) omnetpp::createStdPointerSetWatcher(#variable,(variable))
365 #define WATCH_MAP(m) omnetpp::createStdMapWatcher(#m,(m))
372 #define WATCH_PTRMAP(m) omnetpp::createStdPointerMapWatcher(#m,(m))