Project

General

Profile

Statistics
| Branch: | Revision:

root / include / cnullenvir.h @ 2f5cc443

History | View | Annotate | Download (6.16 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CNULLENVIR.H - part of
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//
8
//  Declaration of the following classes:
9
//    cNullEnvir : a cEnvir implementation with empty member functions
10
//
11
//==========================================================================
12
13
/*--------------------------------------------------------------*
14
  Copyright (C) 1992-2008 Andras Varga
15
  Copyright (C) 2006-2008 OpenSim Ltd.
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20
21
#ifndef __CNULLENVIR_H
22
#define __CNULLENVIR_H
23
24
#include "cenvir.h"
25
#include "cexception.h"
26
#include "ccomponent.h"
27
#include "cmersennetwister.h"
28
29
NAMESPACE_BEGIN
30
31
32
/**
33
 * A cEnvir implementation with all pure virtual methods defined with an
34
 * empty body, with a trivial implementation, or to throw an exception
35
 * with the "unsupported method" text.
36
 *
37
 * This class is not used by \opp, it is provided for convenience of
38
 * writing standlone programs that embed the simulation kernel as a library.
39
 *
40
 * You may want to subclass from cNullEnvir, and redefine some the following
41
 * methods:
42
 * <ul>
43
 *   <li> sputn() to print module log messages instead of discarding
44
 *        them (<tt>::fwrite(s,1,n,stdout);</tt>);
45
 *   <li> readParameter() to set module parameters, or at least apply the
46
 *        NED default value;
47
 *   <li> the RNG methods (getNumRNGs(), getRNG()) to provide more than one
48
 *        random number generator
49
 *   <li> recordScalar() and other statistics recording methods to store
50
 *        simulation results instead of discarding them
51
 * </ul>
52
 *
53
 * @ingroup Envir
54
 * @ingroup EnvirExtensions
55
 */
56
class SIM_API cNullEnvir : public cEnvir
57
{
58
  protected:
59
    int argc;
60
    char **argv;
61
    cConfiguration *cfg;
62
    cRNG *rng;
63
    unsigned long lastnum;
64
65
  protected:
66
    void unsupported() const {throw cRuntimeError("cNullEnvir: unsupported method called");}
67
68
    virtual void sputn(const char *s, int n) {}
69
    virtual void putsmsg(const char *msg) {::printf("\n<!> %s\n\n", msg);}
70
    virtual bool askyesno(const char *msg)  {unsupported(); return false;}
71
72
  public:
73
    // constructor, destructor
74
    cNullEnvir(int ac, char **av, cConfiguration *c) {argc=ac; argv=av; cfg=c; rng=new cMersenneTwister(); lastnum=0;}
75
    virtual ~cNullEnvir() {delete cfg; delete rng;}
76
77
    // eventlog callback interface
78
    virtual void objectDeleted(cObject *object) {}
79
    virtual void simulationEvent(cMessage *msg)  {}
80
    virtual void messageSent_OBSOLETE(cMessage *msg, cGate *directToGate=NULL)  {}
81
    virtual void messageScheduled(cMessage *msg)  {}
82
    virtual void messageCancelled(cMessage *msg)  {}
83
    virtual void beginSend(cMessage *msg)  {}
84
    virtual void messageSendDirect(cMessage *msg, cGate *toGate, simtime_t propagationDelay, simtime_t transmissionDelay)  {}
85
    virtual void messageSendHop(cMessage *msg, cGate *srcGate)  {}
86
    virtual void messageSendHop(cMessage *msg, cGate *srcGate, simtime_t propagationDelay, simtime_t transmissionDelay)  {}
87
    virtual void endSend(cMessage *msg)  {}
88
    virtual void messageDeleted(cMessage *msg)  {}
89
    virtual void moduleReparented(cModule *module, cModule *oldparent)  {}
90
    virtual void componentMethodBegin(cComponent *from, cComponent *to, const char *methodFmt, va_list va, bool silent)  {}
91
    virtual void componentMethodEnd()  {}
92
    virtual void moduleCreated(cModule *newmodule)  {}
93
    virtual void moduleDeleted(cModule *module)  {}
94
    virtual void gateCreated(cGate *newgate)  {}
95
    virtual void gateDeleted(cGate *gate)  {}
96
    virtual void connectionCreated(cGate *srcgate)  {}
97
    virtual void connectionDeleted(cGate *srcgate)  {}
98
    virtual void displayStringChanged(cComponent *component)  {}
99
    virtual void undisposedObject(cObject *obj) {}
100
101
    // configuration, model parameters
102
    virtual void configure(cComponent *component) {}
103
    virtual void readParameter(cPar *par)  {unsupported();}
104
    virtual bool isModuleLocal(cModule *parentmod, const char *modname, int index)  {return true;}
105
    virtual cXMLElement *getXMLDocument(const char *filename, const char *path=NULL)  {unsupported(); return NULL;}
106
    virtual void forgetXMLDocument(const char *filename) {}
107
    virtual void flushXMLDocumentCache() {}
108
    virtual unsigned getExtraStackForEnvir() const  {return 0;}
109
    virtual cConfiguration *getConfig()  {return cfg;}
110
    virtual bool isGUI() const  {return false;}
111
112
    // UI functions (see also protected ones)
113
    virtual void bubble(cComponent *component, const char *text)  {}
114
    virtual std::string gets(const char *prompt, const char *defaultreply=NULL)  {unsupported(); return "";}
115
    virtual cEnvir& flush()  {::fflush(stdout); return *this;}
116
117
    // RNGs
118
    virtual int getNumRNGs() const {return 1;}
119
    virtual cRNG *getRNG(int k)  {return rng;}
120
    virtual void getRNGMappingFor(cComponent *component)  {component->setRNGMap(0,NULL);}
121
122
    // output vectors
123
    virtual void *registerOutputVector(const char *modulename, const char *vectorname)  {return (void *)1;}
124
    virtual void deregisterOutputVector(void *vechandle)  {}
125
    virtual void setVectorAttribute(void *vechandle, const char *name, const char *value)  {}
126
    virtual bool recordInOutputVector(void *vechandle, simtime_t t, double value)  {return false;}
127
128
    // output scalars
129
    virtual void recordScalar(cComponent *component, const char *name, double value, opp_string_map *attributes=NULL)  {}
130
    virtual void recordStatistic(cComponent *component, const char *name, cStatistic *statistic, opp_string_map *attributes=NULL)  {}
131
132
    // snapshot file
133
    virtual std::ostream *getStreamForSnapshot()  {unsupported(); return NULL;}
134
    virtual void releaseStreamForSnapshot(std::ostream *os)  {unsupported();}
135
136
    // misc
137
    virtual int getArgCount() const  {return argc;}
138
    virtual char **getArgVector() const  {return argv;}
139
    virtual int getParsimProcId() const {return 0;}
140
    virtual int getParsimNumPartitions() const {return 1;}
141
    virtual unsigned long getUniqueNumber()  {return ++lastnum;}
142
    virtual bool idle()  {return false;}
143
};
144
145
146
NAMESPACE_END
147
148
#endif
149