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-2003 Andras Varga
00014 
00015   This file is distributed WITHOUT ANY WARRANTY. See the file
00016   `license' for details on this and other legal matters.
00017 *--------------------------------------------------------------*/
00018 
00019 #ifndef __CSTRUCT_H
00020 #define __CSTRUCT_H
00021 
00022 #include "cobject.h"
00023 #include "cenum.h"
00024 class sFieldWrapper;
00025 
00026 
00039 class SIM_API cStructDescriptor : public cObject
00040 {
00041   public:
00043     enum {
00044         FT_BASIC,         
00045         FT_SPECIAL,       
00046         FT_STRUCT,        
00047         FT_BASIC_ARRAY,   
00048         FT_SPECIAL_ARRAY, 
00049         FT_STRUCT_ARRAY,  
00050         FT_INVALID        
00051     };
00052 
00053   protected:
00054     void *p;
00055 
00056   protected:
00057     // utility functions for converting from/to strings
00058     static void long2string(long l, char *buf, int bufsize);
00059     static void ulong2string(unsigned long l, char *buf, int bufsize);
00060     static long string2long(const char *s);
00061     static unsigned long string2ulong(const char *s);
00062     static void bool2string(bool b, char *buf, int bufsize);
00063     static bool string2bool(const char *s);
00064     static void double2string(double d, char *buf, int bufsize);
00065     static double string2double(const char *s);
00066     static void enum2string(long e, const char *enumname, char *buf, int bufsize);
00067     static long string2enum(const char *s, const char *enumname);
00068     static void oppstring2string(const opp_string& str, char *buf, int bufsize);
00069     static void string2oppstring(const char *s, opp_string& str);
00070 
00071   public:
00074 
00078     cStructDescriptor(void *_p=NULL) {p=_p;}
00079 
00083     cStructDescriptor(const cStructDescriptor& cs)  {setName(cs.name());operator=(cs);}
00084 
00088     virtual ~cStructDescriptor();
00089 
00093     cStructDescriptor& operator=(const cStructDescriptor&)  {copyNotSupported();return *this;}
00095 
00098 
00099     /* No dup() because this is an abstract class. */
00101 
00104 
00108     static bool hasDescriptor(const char *classname);
00109 
00115     static cStructDescriptor *createDescriptorFor(cObject *obj);
00116 
00122     static cStructDescriptor *createDescriptorFor(const char *classname, void *p);
00124 
00127 
00131     void setStruct(void *_p)  {p=_p;}
00132 
00136     void *getStruct() const  {return p;}
00138 
00141 
00146     virtual int getFieldCount() = 0;
00147 
00153     virtual const char *getFieldName(int field) = 0;
00154 
00161     virtual int getFieldType(int field) = 0;
00162 
00168     virtual const char *getFieldTypeString(int field) = 0;
00169 
00177     virtual const char *getFieldEnumName(int field) = 0;
00178 
00183     virtual int getArraySize(int field) = 0;
00184 
00191     virtual bool getFieldAsString(int field, int i, char *buf, int bufsize) = 0;
00192 
00199     virtual bool setFieldAsString(int field, int i, const char *value) = 0;
00200 
00208     virtual sFieldWrapper *getFieldWrapper(int field, int i) = 0;
00209 
00216     virtual const char *getFieldStructName(int field) = 0;
00217 
00224     virtual void *getFieldStructPointer(int field, int i) = 0;
00226 };
00227 
00228 
00236 class SIM_API sFieldWrapper
00237 {
00238   public:
00244     sFieldWrapper() {}
00245 
00249     virtual ~sFieldWrapper() {}
00250 
00255     virtual const char *fieldType() = 0;
00256 
00264     virtual void getAsString(char *buf, int bufsize) = 0;
00265 
00273     virtual void setAsString(const char *value) = 0;
00274 };
00275 
00276 #endif
00277 

Generated at Mon Jun 16 23:37:31 2003 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001