onstartup.h Source File¶ API: onstartup.h Source File API includeomnetpp onstartup.h 1//========================================================================== 2// ONSTARTUP.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_ONSTARTUP_H 17#define __OMNETPP_ONSTARTUP_H 18 19#include <vector> 20#include <map> 21#include "simkerneldefs.h" 22#include "cownedobject.h" 23 24namespace omnetpp { 25 26 27// Generating identifiers unique for this file. See MSVC Help for __COUNTER__ for more info. 28#define __OPPCONCAT1(x,y) x##y 29#define __OPPCONCAT2(prefix,line) __OPPCONCAT1(prefix,line) 30#define MAKE_UNIQUE_WITHIN_FILE(prefix) __OPPCONCAT2(prefix,__LINE__) 31 32// helpers for EXECUTE_ON_STARTUP 33// IMPORTANT: if you change "__onstartup_func_" below, linkall.pl must also be updated! 34#define __ONSTARTUP_FUNC MAKE_UNIQUE_WITHIN_FILE(__onstartup_func_) 35#define __ONSTARTUP_OBJ MAKE_UNIQUE_WITHIN_FILE(__onstartup_obj_) 36 37// helper 38#define __FILEUNIQUENAME__ MAKE_UNIQUE_WITHIN_FILE(__uniquename_) 39 49#define EXECUTE_ON_STARTUP(CODE) \ 50 namespace { \ 51 void __ONSTARTUP_FUNC() {CODE;} \ 52 static omnetpp::CodeFragments __ONSTARTUP_OBJ(__ONSTARTUP_FUNC, #CODE, omnetpp::CodeFragments::STARTUP); \ 53 } 54 63//NOTE: implementation reuses some of the *startup* macros 64#define EXECUTE_ON_SHUTDOWN(CODE) \ 65 namespace { \ 66 void __ONSTARTUP_FUNC() {CODE;} \ 67 static omnetpp::CodeFragments __ONSTARTUP_OBJ(__ONSTARTUP_FUNC, #CODE, omnetpp::CodeFragments::SHUTDOWN); \ 68 } 69 75class SIM_API CodeFragments 76{ 77 public: 78 enum Type {STARTUP, SHUTDOWN}; 79 Type type; 80 void (*code)(); 81 const char *sourceCode; 82 CodeFragments *next; 83 static CodeFragments *head; 84 public: 85 CodeFragments(void (*code)(), const char *sourceCode, Type type); 86 ~CodeFragments() {} 87 static void executeAll(Type type); 88}; 89 90} // namespace omnetpp 91 92 93#endif 94 Generated on for API by 1.14.0