Statistics
| Branch: | Revision:

root / include / cregistrationlist.h @ ffa9279f

History | View | Annotate | Download (2.87 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CREGISTRATIONLIST.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  cRegistrationList 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 __CREGISTRATIONLIST_H
20
#define __CREGISTRATIONLIST_H
21
22
#include <vector>
23
#include <map>
24
#include "simkerneldefs.h"
25
#include "cnamedobject.h"
26
27
NAMESPACE_BEGIN
28
29
class cOwnedObject;
30
31
/**
32
 * Stores objects with a qualified name. The getName() method of objects
33
 * should return the unqualified name (without namespace or package name),
34
 * and the getFullName() method the qualified name (with namespace or package).
35
 */
36
class SIM_API cRegistrationList : public cNamedObject, noncopyable
37
{
38
  private:
39
    typedef std::map<std::string, cOwnedObject*> StringObjectMap;
40
    std::vector<cOwnedObject *> vec;  // for fast iteration
41
    StringObjectMap nameMap;   // for lookup by getName()
42
    StringObjectMap fullnameMap;  // for lookup by getFullName()
43
44
  public:
45
    cRegistrationList(const char *name) : cNamedObject(name, false) {}
46
    virtual ~cRegistrationList();
47
48
    /** @name cObject methods */
49
    //@{
50
    virtual std::string info() const;
51
    virtual void forEachChild(cVisitor *v);
52
    //@}
53
54
    /**
55
     * Adds an object to the container.
56
     */
57
    virtual void add(cOwnedObject *obj);
58
59
    /**
60
     * Returns the number of elements.
61
     */
62
    virtual int size() const {return vec.size();}
63
64
    /**
65
     * Returns the ith element, or NULL.
66
     */
67
    virtual cOwnedObject *get(int i) const;
68
69
    /**
70
     * Returns (one of) the object(s) with the given name (not fullName!).
71
     * Returns NULL if not found.
72
     */
73
    virtual cOwnedObject *get(const char *name) const;
74
75
    /**
76
     * Returns the object with exactly the given qualified name (getFullName()).
77
     * Returns NULL if not found.
78
     */
79
    virtual cOwnedObject *lookup(const char *qualifiedName) const;
80
81
    /**
82
     * Sorts the elements by qualified name (getFullName()). This affects
83
     * the order get() will return the elements.
84
     */
85
    virtual void sort();
86
87
};
88
89
/**
90
 * Singleton class, used for registration lists.
91
 * Instances are supposed to be global variables.
92
 *
93
 * @ingroup Internals
94
 */
95
class SIM_API cGlobalRegistrationList
96
{
97
  private:
98
    cRegistrationList *inst;
99
    const char *tmpname;
100
  public:
101
    cGlobalRegistrationList();
102
    cGlobalRegistrationList(const char *name);
103
    ~cGlobalRegistrationList();
104
    cRegistrationList *getInstance();
105
    void clear();
106
};
107
108
NAMESPACE_END
109
110
111
#endif