ccontextswitcher.h Source File

API: ccontextswitcher.h Source File
API
ccontextswitcher.h
1//==========================================================================
2// CCONTEXTSWITCHER.H - part of
3// OMNeT++/OMNEST
4// Discrete System Simulation in C++
5//
6//==========================================================================
7
8/*--------------------------------------------------------------*
9 Copyright (C) 1992-2017 Andras Varga
10 Copyright (C) 2006-2017 OpenSim Ltd.
11
12 This file is distributed WITHOUT ANY WARRANTY. See the file
13 `license' for details on this and other legal matters.
14*--------------------------------------------------------------*/
15
16#ifndef __OMNETPP_CCONTEXTSWITCHER_H
17#define __OMNETPP_CCONTEXTSWITCHER_H
18
19#include <type_traits> // is_integer
20#include <limits> // numeric_limits
21#include <cstring> // for strlen, etc.
22#include <cstdarg> // for va_list
23#include <cstdio> // for sprintf
24#include <cstdlib> // for gcvt
25#include <typeinfo> // for type_info
26#include <string> // for std::string
27#include "platdep/platmisc.h" // for gcvt, etc
28#include "simkerneldefs.h"
29#include "errmsg.h"
30
31namespace omnetpp {
32
33class cObject;
34class cComponent;
35
36// logically belongs to csimulation.h but must be here because of declaration order
37enum ContextType {CTX_NONE, CTX_BUILD, CTX_INITIALIZE, CTX_EVENT, CTX_SCHEDULER, CTX_REFRESHDISPLAY, CTX_FINISH, CTX_CLEANUP};
38
39
61#define Enter_Method(...) omnetpp::cMethodCallContextSwitcher __ctx(this); __ctx.methodCall(__VA_ARGS__)
62
82#define Enter_Method_Silent(...) omnetpp::cMethodCallContextSwitcher __ctx(this); __ctx.methodCallSilent(__VA_ARGS__)
83
91class SIM_API cContextSwitcher
92{
93 protected:
94 cComponent *callerContext;
95 public:
99 cContextSwitcher(const cComponent *newContext);
100
105
109 cComponent *getCallerContext() const { return callerContext; }
110};
111
117{
118 private:
119 static int depth;
120
121 public:
125 //TODO store previous frame, __FILE__, __LINE__, __FUNCTION__ too, at least in debug builds?
127
132
137 _OPP_GNU_ATTRIBUTE(format(printf, 2, 3))
138 void methodCall(const char *methodFmt,...);
139 _OPP_GNU_ATTRIBUTE(format(printf, 2, 3))
140 void methodCallSilent(const char *methodFm,...);
141 void methodCallSilent();
142
146 static int getDepth() {return depth;}
147};
148
157{
158 private:
159 ContextType savedContextType;
160
161 public:
165 cContextTypeSwitcher(ContextType contexttype);
166
171};
172
173
174} // namespace omnetpp
175
176#endif
177
178
Common base for module and channel classes.
Definition ccomponent.h:51
cComponent * getCallerContext() const
Definition ccontextswitcher.h:109
cContextSwitcher(const cComponent *newContext)
cContextTypeSwitcher(ContextType contexttype)
void methodCall(const char *methodFmt,...)
cMethodCallContextSwitcher(const cComponent *newContext)
static int getDepth()
Definition ccontextswitcher.h:146
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition cobject.h:93