cproperties.h

00001 //==========================================================================
00002 //  CPROPERTIES.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //==========================================================================
00007 
00008 /*--------------------------------------------------------------*
00009   Copyright (C) 1992-2008 Andras Varga
00010   Copyright (C) 2006-2008 OpenSim Ltd.
00011 
00012   This file is distributed WITHOUT ANY WARRANTY. See the file
00013   `license' for details on this and other legal matters.
00014 *--------------------------------------------------------------*/
00015 
00016 #ifndef __CPROPERTIES_H
00017 #define __CPROPERTIES_H
00018 
00019 #include "simkerneldefs.h"
00020 #include "globals.h"
00021 #include "cobject.h"
00022 #include <vector>
00023 
00024 NAMESPACE_BEGIN
00025 
00026 class cProperty;
00027 
00028 
00034 class SIM_API cProperties : public cObject
00035 {
00036   protected:
00037     bool islocked;
00038     int refcount;
00039     std::vector<cProperty *> propv;
00040 
00041   private:
00042     void copy(const cProperties& other);
00043 
00044   public:
00045     // internal: locks the object and all contained properties against modifications.
00046     // The object cannot be unlocked -- one must copy contents to an unlocked
00047     // object, or call dup() (new objects are created in unlocked state).
00048     virtual void lock();
00049 
00050     // internal: increment/decrement reference count
00051     int addRef()  {return ++refcount;}
00052     int removeRef()  {return --refcount;}
00053 
00054   public:
00060     explicit cProperties();
00061 
00065     cProperties(const cProperties& other) : cObject(other) {refcount=0; islocked=false; copy(other);}
00066 
00070     virtual ~cProperties();
00071 
00075     cProperties& operator=(const cProperties& other);
00077 
00083     virtual cProperties *dup() const  {return new cProperties(*this);}
00084 
00088     virtual const char *getName() const  {return "properties";}
00089 
00093     virtual std::string info() const;
00094 
00098     virtual void parsimPack(cCommBuffer *buffer);
00099 
00103     virtual void parsimUnpack(cCommBuffer *buffer);
00105 
00111     virtual int getNumProperties() const  {return propv.size();}
00112 
00118     virtual const std::vector<const char *> getNames() const;
00119 
00123     virtual cProperty *get(int k) const;
00124 
00131     virtual cProperty *get(const char *name, const char *index=NULL) const;
00132 
00149     virtual bool getAsBool(const char *name, const char *index=NULL) const;
00150 
00157     virtual std::vector<const char *> getIndicesFor(const char *name) const;
00158 
00162     virtual void add(cProperty *p);
00163 
00167     virtual void remove(int k);
00169 };
00170 
00171 NAMESPACE_END
00172 
00173 
00174 #endif
00175 
00176 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3