Project

General

Profile

Statistics
| Branch: | Revision:

root / include / onstartup.h @ aeae20a1

History | View | Annotate | Download (2.25 KB)

1
//==========================================================================
2
//  ONSTARTUP.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  EXECUTE_ON_STARTUP macro and supporting class
8
//
9
//==========================================================================
10

    
11
/*--------------------------------------------------------------*
12
  Copyright (C) 1992-2008 Andras Varga
13
  Copyright (C) 2006-2008 OpenSim Ltd.
14

15
  This file is distributed WITHOUT ANY WARRANTY. See the file
16
  `license' for details on this and other legal matters.
17
*--------------------------------------------------------------*/
18

    
19
#ifndef __ONSTARTUP_H
20
#define __ONSTARTUP_H
21

    
22
#include <vector>
23
#include <map>
24
#include "simkerneldefs.h"
25
#include "cownedobject.h"
26

    
27
NAMESPACE_BEGIN
28

    
29

    
30
// Generating identifiers unique for this file. See MSVC Help for __COUNTER__
31
// for more info.
32
#define __OPPCONCAT1(x,y) x##y
33
#define __OPPCONCAT2(prefix,line) __OPPCONCAT1(prefix,line)
34
#define MAKE_UNIQUE_WITHIN_FILE(prefix) __OPPCONCAT2(prefix,__LINE__)
35

    
36
// helpers for EXECUTE_ON_STARTUP
37
// IMPORTANT: if you change "__onstartup_func_" below, linkall.pl must also be updated!
38
#define __ONSTARTUP_FUNC  MAKE_UNIQUE_WITHIN_FILE(__onstartup_func_)
39
#define __ONSTARTUP_OBJ   MAKE_UNIQUE_WITHIN_FILE(__onstartup_obj_)
40

    
41
// helper
42
#define __FILEUNIQUENAME__  MAKE_UNIQUE_WITHIN_FILE(__uniquename_)
43

    
44
/**
45
 * Allows code fragments to be collected in global scope which will
46
 * then be executed from main() right after program startup. This is
47
 * used by in \opp for building global registration lists of
48
 * module types, network types, etc. Registration lists in fact
49
 * are a simple substitute for Java's Class.forName() method...
50
 *
51
 * @hideinitializer
52
 */
53
#define EXECUTE_ON_STARTUP(CODE)  \
54
  namespace { \
55
    void __ONSTARTUP_FUNC() {CODE;} \
56
    static ExecuteOnStartup __ONSTARTUP_OBJ(__ONSTARTUP_FUNC); \
57
  };
58

    
59

    
60
/**
61
 * Supporting class for EXECUTE_ON_STARTUP macro.
62
 *
63
 * @ingroup Internals
64
 */
65
class SIM_API ExecuteOnStartup
66
{
67
  private:
68
    void (*code_to_exec)();
69
    ExecuteOnStartup *next;
70
    static ExecuteOnStartup *head;
71
  public:
72
    ExecuteOnStartup(void (*code_to_exec)());
73
    ~ExecuteOnStartup();
74
    void execute();
75
    static void executeAll();
76
};
77

    
78
NAMESPACE_END
79

    
80

    
81
#endif
82