Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cstruct.h

00001 //==========================================================================
00002 //   CSTRUCT.H  - header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cStructDescriptor  : meta-info about structures
00009 //
00010 //==========================================================================
00011 
00012 /*--------------------------------------------------------------*
00013   Copyright (C) 1992,2001 Andras Varga
00014   Technical University of Budapest, Dept. of Telecommunications,
00015   Stoczek u.2, H-1111 Budapest, Hungary.
00016 
00017   This file is distributed WITHOUT ANY WARRANTY. See the file
00018   `license' for details on this and other legal matters.
00019 *--------------------------------------------------------------*/
00020 
00021 #ifndef __CSTRUCT_H
00022 #define __CSTRUCT_H
00023 
00024 #include "cobject.h"
00025 #include "cenum.h"
00026 class sFieldWrapper;
00027 
00028 
00041 class SIM_API cStructDescriptor : public cObject
00042 {
00043   public:
00045     enum {
00046         FT_BASIC,         
00047         FT_SPECIAL,       
00048         FT_STRUCT,        
00049         FT_BASIC_ARRAY,   
00050         FT_SPECIAL_ARRAY, 
00051         FT_STRUCT_ARRAY,  
00052         FT_INVALID        
00053     };
00054 
00055   protected:
00056     void *p;
00057 
00058   protected:
00059     // utility functions for converting from/to strings
00060     static void long2string(long l, char *buf, int bufsize);
00061     static void ulong2string(unsigned long l, char *buf, int bufsize);
00062     static long string2long(const char *s);
00063     static unsigned long string2ulong(const char *s);
00064     static void bool2string(bool b, char *buf, int bufsize);
00065     static bool string2bool(const char *s);
00066     static void double2string(double d, char *buf, int bufsize);
00067     static double string2double(const char *s);
00068     static void enum2string(long e, const char *enumname, char *buf, int bufsize);
00069     static long string2enum(const char *s, const char *enumname);
00070     static void oppstring2string(const opp_string& str, char *buf, int bufsize);
00071     static void string2oppstring(const char *s, opp_string& str);
00072 
00073   public:
00076 
00080     cStructDescriptor(void *_p=NULL) {p=_p;}
00081 
00085     cStructDescriptor(const cStructDescriptor& cs)  {setName(cs.name());operator=(cs);}
00086 
00090     virtual ~cStructDescriptor();
00091 
00095     cStructDescriptor& operator=(const cStructDescriptor&)  {copyNotSupported();return *this;}
00097 
00100 
00104     virtual const char *className() const {return "cStructDescriptor";}
00105 
00106     /* No dup() because this is an abstract class. */
00108 
00111 
00115     static bool hasDescriptor(const char *classname);
00116 
00122     static cStructDescriptor *createDescriptorFor(cObject *obj);
00123 
00129     static cStructDescriptor *createDescriptorFor(const char *classname, void *p);
00131 
00134 
00138     void setStruct(void *_p)  {p=_p;}
00139 
00143     void *getStruct() const  {return p;}
00145 
00148 
00153     virtual int getFieldCount() = 0;
00154 
00160     virtual const char *getFieldName(int field) = 0;
00161 
00168     virtual int getFieldType(int field) = 0;
00169 
00175     virtual const char *getFieldTypeString(int field) = 0;
00176 
00184     virtual const char *getFieldEnumName(int field) = 0;
00185 
00190     virtual int getArraySize(int field) = 0;
00191 
00198     virtual bool getFieldAsString(int field, int i, char *buf, int bufsize) = 0;
00199 
00206     virtual bool setFieldAsString(int field, int i, const char *value) = 0;
00207 
00215     virtual sFieldWrapper *getFieldWrapper(int field, int i) = 0;
00216 
00223     virtual const char *getFieldStructName(int field) = 0;
00224 
00231     virtual void *getFieldStructPointer(int field, int i) = 0;
00233 };
00234 
00235 
00243 class SIM_API sFieldWrapper
00244 {
00245   public:
00251     sFieldWrapper() {}
00252 
00256     virtual ~sFieldWrapper() {}
00257 
00262     virtual const char *fieldType() = 0;
00263 
00271     virtual void getAsString(char *buf, int bufsize) = 0;
00272 
00280     virtual void setAsString(const char *value) = 0;
00281 };
00282 
00283 #endif
00284 

Generated at Sat May 4 15:45:48 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001