Project

General

Profile

Statistics
| Branch: | Revision:

root / include / clockeddefaultlist.h @ 2f5cc443

History | View | Annotate | Download (3.96 KB)

1
//==========================================================================
2
//  CLOCKEDDEFAULTLIST.H - part of
3
//
4
//                     Horizon/OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//
8
//  Declaration of the following classes:
9
//    cLockedDefaultList : holds a set of cObjects in a thread-safe manner
10
//
11
//==========================================================================
12

    
13
/*--------------------------------------------------------------*
14
  Copyright (C) 1992-2005 Andras Varga
15
  Copyright (C) 2009      Georg Kunz
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 __CLOCKEDDEFAULTLIST_H
22
#define __CLOCKEDDEFAULTLIST_H
23

    
24
#include <pthread.h>
25

    
26
#include "cdefaultlist.h"
27
#include "clock.h"
28

    
29

    
30
/**
31
 * This is a thread safe wrapper around cDefaultList
32
 *
33
 * @ingroup Horizon
34
 */
35
template<class T>
36
class SIM_API cLockedDefaultList : public cDefaultList
37
{
38
  private:
39

    
40
    cLock* lock;    // the lock
41

    
42
    //void construct();
43
    virtual void doInsert(cOwnedObject *obj);                                // called from constructor of cObject
44
    virtual void ownedObjectDeleted(cOwnedObject *obj);                      // called from destructor of cObject
45
    virtual void yieldOwnership(cOwnedObject *obj, cObject *newOwner);
46

    
47
  public:
48
    // internal: called from module creation code in ctypes.cc
49
    void takeAllObjectsFrom(cLockedDefaultList& other);
50

    
51
  protected:
52
    /** @name Redefined cDefaultList member functions */
53
    //@{
54

    
55
    /**
56
     * Redefined.
57
     */
58
    void take(cOwnedObject *obj);
59

    
60
    /**
61
     * Redefined.
62
     */
63
    void drop(cOwnedObject *obj);
64

    
65
  public:
66
    /** @name Constructors, destructor, assignment. */
67
    //@{
68

    
69
    /**
70
     * Copy constructor. Throws exception.
71
     */
72
    cLockedDefaultList(const cLockedDefaultList& list);
73

    
74
    /**
75
     * Constructor.
76
     */
77
    explicit cLockedDefaultList(const char *name=NULL);
78

    
79
    /**
80
     * Destructor. The contained objects will be deleted.
81
     */
82
    virtual ~cLockedDefaultList();
83

    
84
    /**
85
     * Assignment operator. Throws exception.
86
     */
87
    cLockedDefaultList& operator=(const cLockedDefaultList& list);
88
    //@}
89

    
90
    /** @name Redefined cObject member functions */
91
    //@{
92

    
93
    /**
94
     * Duplication. Throws exception.
95
     */
96
    virtual cLockedDefaultList *dup() const  {return new cLockedDefaultList(*this);}
97

    
98
    /**
99
     * Returns true.
100
     */
101
    virtual bool isSoftOwner()  {return true;}
102

    
103
    /**
104
     * Produces a one-line description of object contents into the buffer passed as argument.
105
     * See cObject for more details.
106
     */
107
    virtual std::string info();
108

    
109
    /**
110
     * Calls v->visit(this) for each contained object.
111
     * See cObject for more details.
112
     */
113
    virtual void forEachChild(cVisitor *v);
114

    
115
    /**
116
     * Packing and unpacking cannot be supported with this class.
117
     * This method raises an error.
118
     */
119
    virtual void parsimPack(cCommBuffer *buffer);
120

    
121
    /**
122
     * Packing and unpacking cannot be supported with this class.
123
     * This method raises an error.
124
     */
125
    virtual void parsimUnpack(cCommBuffer *buffer);
126
    //@}
127

    
128
    /** @name Container functions. */
129
    // Note: we need long method names here because cModule subclasses from this class
130
    //@{
131

    
132
    /**
133
     * Returns the number of elements stored.
134
     */
135
    int defaultListItems() const {return cDefaultList::defaultListSize();}
136

    
137
    /**
138
     * Get the element at the given position. k must be between 0 and
139
     * items()-1 (inclusive). Note that elements may move as the result
140
     * of add() and remove() operations. If the index is out of bounds,
141
     * NULL is returned.
142
     */
143
    cOwnedObject *defaultListGet(int k);
144

    
145
    /**
146
     * Returns true if the set contains the given object, false otherwise.
147
     */
148
    // Note: we need a long name here because cModule subclasses from this
149
    bool defaultListContains(cOwnedObject *obj);
150
    //@}
151
};
152

    
153
#endif