Statistics
| Branch: | Revision:

root / include / clongparimpl.h @ master

History | View | Annotate | Download (4.4 KB)

1
//==========================================================================
2
//   CLONGPARIMPL.H  - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9

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

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

    
18
#ifndef __CLONGPARIMPL_H
19
#define __CLONGPARIMPL_H
20

    
21
#include "cparimpl.h"
22

    
23
NAMESPACE_BEGIN
24

    
25
/**
26
 * A cParImpl subclass that stores a module/channel parameter
27
 * of the type long.
28
 *
29
 * @ingroup Internals
30
 */
31
class SIM_API cLongParImpl : public cParImpl
32
{
33
  protected:
34
    // selector: flags & FL_ISEXPR
35
    union {
36
      cExpression *expr;
37
      long val;
38
    };
39

    
40
  protected:
41
    long evaluate(cComponent *context) const;
42
    void deleteOld();
43

    
44
  public:
45
    /** @name Constructors, destructor, assignment. */
46
    //@{
47

    
48
    /**
49
     * Constructor.
50
     */
51
    explicit cLongParImpl();
52

    
53
    /**
54
     * Copy constructor.
55
     */
56
    cLongParImpl(const cLongParImpl& other) {setName(other.getName()); operator=(other);}
57

    
58
    /**
59
     * Destructor.
60
     */
61
    virtual ~cLongParImpl();
62

    
63
    /**
64
     * Assignment operator.
65
     */
66
    void operator=(const cLongParImpl& otherpar);
67
    //@}
68

    
69
    /** @name Redefined cObject member functions */
70
    //@{
71

    
72
    /**
73
     * Creates and returns an exact copy of this object.
74
     */
75
    virtual cLongParImpl *dup() const  {return new cLongParImpl(*this);}
76

    
77
    /**
78
     * Serializes the object into a buffer.
79
     */
80
    virtual void parsimPack(cCommBuffer *buffer);
81

    
82
    /**
83
     * Deserializes the object from a buffer.
84
     */
85
    virtual void parsimUnpack(cCommBuffer *buffer);
86
    //@}
87

    
88
    /** @name Redefined cParImpl setter functions. */
89
    //@{
90

    
91
    /**
92
     * Raises an error: cannot convert bool to long.
93
     */
94
    virtual void setBoolValue(bool b);
95

    
96
    /**
97
     * Sets the value to the given constant.
98
     */
99
    virtual void setLongValue(long l);
100

    
101
    /**
102
     * Converts from double.
103
     */
104
    virtual void setDoubleValue(double d);
105

    
106
    /**
107
     * Raises an error: cannot convert string to long.
108
     */
109
    virtual void setStringValue(const char *s);
110

    
111
    /**
112
     * Raises an error: cannot convert XML to long.
113
     */
114
    virtual void setXMLValue(cXMLElement *node);
115

    
116
    /**
117
     * Sets the value to the given expression. This object will
118
     * assume the responsibility to delete the expression object.
119
     */
120
    virtual void setExpression(cExpression *e);
121
    //@}
122

    
123
    /** @name Redefined cParImpl getter functions. */
124
    //@{
125

    
126
    /**
127
     * Raises an error: cannot convert long to bool.
128
     */
129
    virtual bool boolValue(cComponent *context) const;
130

    
131
    /**
132
     * Returns the value of the parameter.
133
     */
134
    virtual long longValue(cComponent *context) const;
135

    
136
    /**
137
     * Converts the value to double.
138
     */
139
    virtual double doubleValue(cComponent *context) const;
140

    
141
    /**
142
     * Raises an error: cannot convert long to string.
143
     */
144
    virtual const char *stringValue(cComponent *context) const;
145

    
146
    /**
147
     * Raises an error: cannot convert long to string.
148
     */
149
    virtual std::string stdstringValue(cComponent *context) const;
150

    
151
    /**
152
     * Raises an error: cannot convert long to XML.
153
     */
154
    virtual cXMLElement *xmlValue(cComponent *context) const;
155

    
156
    /**
157
     * Returns pointer to the expression stored by the object, or NULL.
158
     */
159
    virtual cExpression *getExpression() const;
160
    //@}
161

    
162
    /** @name Type, prompt text, input flag, change flag. */
163
    //@{
164

    
165
    /**
166
     * Returns LONG.
167
     */
168
    virtual Type getType() const;
169

    
170
    /**
171
     * Returns true.
172
     */
173
    virtual bool isNumeric() const;
174
    //@}
175

    
176
    /** @name Redefined cParImpl misc functions. */
177
    //@{
178

    
179
    /**
180
     * Replaces for non-const values, replaces the stored expression with its
181
     * evaluation.
182
     */
183
    virtual void convertToConst(cComponent *context);
184

    
185
    /**
186
     * Returns the value in text form.
187
     */
188
    virtual std::string str() const;
189

    
190
    /**
191
     * Converts from text.
192
     */
193
    virtual void parse(const char *text);
194

    
195
    /**
196
     * Object comparison.
197
     */
198
    virtual int compare(const cParImpl *other) const;
199
    //@}
200
};
201

    
202
NAMESPACE_END
203

    
204

    
205
#endif
206

    
207