Statistics
| Branch: | Revision:

root / include / cproperties.h @ 01873262

History | View | Annotate | Download (4.39 KB)

1
//==========================================================================
2
//  CPROPERTIES.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//==========================================================================
7

    
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2008 Andras Varga
10
  Copyright (C) 2006-2008 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 __CPROPERTIES_H
17
#define __CPROPERTIES_H
18

    
19
#include "simkerneldefs.h"
20
#include "globals.h"
21
#include "cobject.h"
22
#include <vector>
23

    
24
NAMESPACE_BEGIN
25

    
26
class cProperty;
27

    
28

    
29
/**
30
 * Stores properties.
31
 *
32
 * @ingroup Internals
33
 */
34
class SIM_API cProperties : public cObject
35
{
36
  protected:
37
    bool islocked;
38
    int refcount;
39
    std::vector<cProperty *> propv;
40

    
41
  public:
42
    // internal: locks the object and all contained properties against modifications.
43
    // The object cannot be unlocked -- one must copy contents to an unlocked
44
    // object, or call dup() (new objects are created in unlocked state).
45
    virtual void lock();
46

    
47
    // internal: increment/decrement reference count
48
    int addRef()  {return ++refcount;}
49
    int removeRef()  {return --refcount;}
50

    
51
  public:
52
    /** @name Constructors, destructor, assignment. */
53
    //@{
54
    /**
55
     * Constructor.
56
     */
57
    explicit cProperties();
58

    
59
    /**
60
     * Copy constructor.
61
     */
62
    cProperties(const cProperties& other) {refcount=0; islocked=false; operator=(other);}
63

    
64
    /**
65
     * Destructor.
66
     */
67
    virtual ~cProperties();
68

    
69
    /**
70
     * Assignment operator.
71
     */
72
    cProperties& operator=(const cProperties& other);
73
    //@}
74

    
75
    /** @name Redefined cObject functions */
76
    //@{
77
    /**
78
     * Creates and returns an exact copy of this object.
79
     */
80
    virtual cProperties *dup() const  {return new cProperties(*this);}
81

    
82
    /**
83
     * Returns object name.
84
     */
85
    virtual const char *getName() const  {return "properties";}
86

    
87
    /**
88
     * Produces a one-line description of the object's contents.
89
     */
90
    virtual std::string info() const;
91

    
92
    /**
93
     * Serializes the object into a buffer.
94
     */
95
    virtual void parsimPack(cCommBuffer *buffer);
96

    
97
    /**
98
     * Deserializes the object from a buffer.
99
     */
100
    virtual void parsimUnpack(cCommBuffer *buffer);
101
    //@}
102

    
103
    /** @name Properties */
104
    //@{
105
    /**
106
     * Returns the number of properties.
107
     */
108
    virtual int getNumProperties() const  {return propv.size();}
109

    
110
    /**
111
     * Returns the names of cProperty object stored in this object.
112
     * The strings in the returned array do not need to be deallocated and
113
     * must not be modified.
114
     */
115
    virtual const std::vector<const char *> getNames() const;
116

    
117
    /**
118
     * Returns kth property, where 0 <= k < getNumProperties().
119
     */
120
    virtual cProperty *get(int k) const;
121

    
122
    /**
123
     * Returns the given property, or NULL if it does not exist.
124
     * Name and index correspond to the the NED syntax
125
     * <tt>\@propertyname[index](keys-and-values)</tt>, where "[index]"
126
     * is optional.
127
     */
128
    virtual cProperty *get(const char *name, const char *index=NULL) const;
129

    
130
    /**
131
     * Returns the property as a boolean. If the property is missing,
132
     * this method returns false; otherwise, only the first value in the
133
     * default key ("") is examined. If it is "false", this method returns
134
     * false; in all other cases (missing, empty, some other value) it
135
     * returns true.
136
     *
137
     * Examples:  @foo: true, @foo(): true, @foo(false): false,
138
     * @foo(true): true, @foo(any): true, @foo(a=x,b=y,c=z): true;
139
     * @foo(somekey=false): true (!).
140
     */
141
    virtual bool getAsBool(const char *name, const char *index=NULL) const;
142

    
143
    /**
144
     * Returns unique indices for a property. Name and index correspond to the
145
     * NED syntax <tt>\@propertyname[index](keys-and-values)</tt>.
146
     * The strings in the returned array do not need to be deallocated and
147
     * must not be modified.
148
     */
149
    virtual std::vector<const char *> getIndicesFor(const char *name) const;
150

    
151
    /**
152
     * Adds the given property to this object.
153
     */
154
    virtual void add(cProperty *p);
155

    
156
    /**
157
     * Removes the given property from this object, and deletes it.
158
     */
159
    virtual void remove(int k);
160
    //@}
161
};
162

    
163
NAMESPACE_END
164

    
165

    
166
#endif
167

    
168