cclassdescriptor.h

00001 //==========================================================================
00002 //  CCLASSDESCRIPTOR.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cClassDescriptor  : metainfo about structs and classes
00009 //
00010 //==========================================================================
00011 
00012 /*--------------------------------------------------------------*
00013   Copyright (C) 1992-2008 Andras Varga
00014   Copyright (C) 2006-2008 OpenSim Ltd.
00015 
00016   This file is distributed WITHOUT ANY WARRANTY. See the file
00017   `license' for details on this and other legal matters.
00018 *--------------------------------------------------------------*/
00019 
00020 #ifndef __CCLASSDESCRIPTOR_H
00021 #define __CCLASSDESCRIPTOR_H
00022 
00023 #include <string>
00024 #include "cownedobject.h"
00025 #include "simtime.h"
00026 
00027 NAMESPACE_BEGIN
00028 
00029 
00047 class SIM_API cClassDescriptor : public cNoncopyableOwnedObject
00048 {
00049   public:
00051     enum {
00052         FD_ISARRAY = 0x01,    
00053         FD_ISCOMPOUND = 0x02, 
00054         FD_ISPOINTER = 0x04,  
00055         FD_ISCOBJECT = 0x08,  
00056         FD_ISCOWNEDOBJECT = 0x10, 
00057         FD_ISEDITABLE = 0x20, 
00058         FD_NONE = 0x0
00059     };
00060 
00061   private:
00062     std::string baseclassname;
00063     cClassDescriptor *baseclassdesc;
00064     int inheritancechainlength;
00065     int extendscobject;
00066 
00067   protected:
00068     // utility functions for converting from/to strings
00069     static std::string long2string(long l);
00070     static long string2long(const char *s);
00071     static std::string ulong2string(unsigned long l);
00072     static unsigned long string2ulong(const char *s);
00073     static std::string int642string(int64 l);
00074     static int64 string2int64(const char *s);
00075     static std::string uint642string(uint64 l);
00076     static uint64 string2uint64(const char *s);
00077     static std::string bool2string(bool b);
00078     static bool string2bool(const char *s);
00079     static std::string double2string(double d);
00080     static std::string double2string(SimTime t) {return t.str();}
00081     static double string2double(const char *s);
00082     static std::string enum2string(long e, const char *enumname);
00083     static long string2enum(const char *s, const char *enumname);
00084     static std::string oppstring2string(const char *s) {return s?s:"";}
00085     static std::string oppstring2string(const opp_string& s) {return s.c_str();}
00086     static std::string oppstring2string(const std::string& s)  {return s;}
00087     static void string2oppstring(const char *s, opp_string& str) {str = s?s:"";}
00088     static void string2oppstring(const char *s, std::string& str) {str = s?s:"";}
00089 
00090   public:
00093 
00097     cClassDescriptor(const char *classname, const char *_baseclassname=NULL);
00098 
00102     virtual ~cClassDescriptor();
00104 
00107 
00112     static cClassDescriptor *getDescriptorFor(const char *classname);
00113 
00119     static cClassDescriptor *getDescriptorFor(cObject *object);
00121 
00124 
00130     virtual bool doesSupport(cObject *obj) const {return false;}
00131 
00135     virtual cClassDescriptor *getBaseClassDescriptor() const;
00136 
00140     bool extendsCObject() const;
00141 
00146     int getInheritanceChainLength() const;
00147 
00154     virtual const char *getProperty(const char *propertyname) const = 0;
00155 
00160     virtual int getFieldCount(void *object) const = 0;
00161 
00167     virtual const char *getFieldName(void *object, int field) const = 0;
00168 
00174     virtual int findField(void *object, const char *fieldName) const;
00175 
00182     virtual unsigned int getFieldTypeFlags(void *object, int field) const = 0;
00183 
00186     bool getFieldIsArray(void *object, int field) const {return getFieldTypeFlags(object, field) & FD_ISARRAY;}
00187     bool getFieldIsCompound(void *object, int field) const {return getFieldTypeFlags(object, field) & FD_ISCOMPOUND;}
00188     bool getFieldIsPointer(void *object, int field) const {return getFieldTypeFlags(object, field) & FD_ISPOINTER;}
00189     bool getFieldIsCObject(void *object, int field) const {return getFieldTypeFlags(object, field) & (FD_ISCOBJECT|FD_ISCOWNEDOBJECT);}
00190     bool getFieldIsCOwnedObject(void *object, int field) const {return getFieldTypeFlags(object, field) & FD_ISCOWNEDOBJECT;}
00191     bool getFieldIsEditable(void *object, int field) const {return getFieldTypeFlags(object, field) & FD_ISEDITABLE;}
00193 
00197     virtual const char *getFieldDeclaredOn(void *object, int field) const;
00198 
00204     virtual const char *getFieldTypeString(void *object, int field) const = 0;
00205 
00212     virtual const char *getFieldProperty(void *object, int field, const char *propertyname) const = 0;
00213 
00218     virtual int getArraySize(void *object, int field) const = 0;
00219 
00225     virtual std::string getFieldAsString(void *object, int field, int i) const = 0;
00226 
00230     _OPPDEPRECATED virtual bool getFieldAsString(void *object, int field, int i, char *buf, int bufsize) const;
00231 
00238     virtual bool setFieldAsString(void *object, int field, int i, const char *value) const = 0;
00239 
00245     virtual const char *getFieldStructName(void *object, int field) const = 0;
00246 
00251     virtual void *getFieldStructPointer(void *object, int field, int i) const = 0;
00253 };
00254 
00255 NAMESPACE_END
00256 
00257 
00258 #endif
00259 
00260 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3