# cstruct.h

    00001 //==========================================================================
    00002 //  CSTRUCT.H - part of
    00003 //                     OMNeT++/OMNEST
    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-2005 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 <string>
    00023 #include "cobject.h"
    00024 #include "cenum.h"
    00025 class sFieldWrapper;
    00026
    00027
    00050 class SIM_API cStructDescriptor : public cObject
    00051 {
    00052   public:
    00054     enum {
    00055         FT_BASIC,
    00056         FT_SPECIAL,
    00057         FT_STRUCT,
    00058         FT_BASIC_ARRAY,
    00059         FT_SPECIAL_ARRAY,
    00060         FT_STRUCT_ARRAY,
    00061         FT_INVALID
    00062     };
    00063
    00064   protected:
    00065     std::string baseclassname;
    00066     cStructDescriptor *baseclassdesc;
    00067     void *p;
    00068
    00069   protected:
    00070     // utility functions for converting from/to strings
    00071     static void long2string(long l, char *buf, int bufsize);
    00072     static void ulong2string(unsigned long l, char *buf, int bufsize);
    00073     static long string2long(const char *s);
    00074     static unsigned long string2ulong(const char *s);
    00075     static void bool2string(bool b, char *buf, int bufsize);
    00076     static bool string2bool(const char *s);
    00077     static void double2string(double d, char *buf, int bufsize);
    00078     static double string2double(const char *s);
    00079     static void enum2string(long e, const char *enumname, char *buf, int bufsize);
    00080     static long string2enum(const char *s, const char *enumname);
    00081     static void oppstring2string(const opp_string& str, char *buf, int bufsize);
    00082     static void string2oppstring(const char *s, opp_string& str);
    00083
    00084   public:
    00087
    00091     cStructDescriptor(const char *_baseclassname=NULL);
    00092
    00096     cStructDescriptor(const cStructDescriptor& cs) : cObject() {setName(cs.name());operator=(cs);}
    00097
    00101     virtual ~cStructDescriptor();
    00102
    00106     cStructDescriptor& operator=(const cStructDescriptor&)  {copyNotSupported();return *this;}
    00108
    00111
    00112     /* No dup() because this is an abstract class. */
    00114
    00117
    00124     static cStructDescriptor *createDescriptorFor(const char *classname, void *p);
    00126
    00129
    00133     void setStruct(void *_p);
    00134
    00138     void *getStruct() const  {return p;}
    00140
    00143
    00148     virtual int getFieldCount() = 0;
    00149
    00155     virtual const char *getFieldName(int field) = 0;
    00156
    00165     virtual int getFieldType(int field) = 0;
    00166
    00172     virtual const char *getFieldTypeString(int field) = 0;
    00173
    00181     virtual const char *getFieldEnumName(int field) = 0;
    00182
    00187     virtual int getArraySize(int field) = 0;
    00188
    00195     virtual bool getFieldAsString(int field, int i, char *buf, int bufsize) = 0;
    00196
    00203     virtual bool setFieldAsString(int field, int i, const char *value) = 0;
    00204
    00212     virtual sFieldWrapper *getFieldWrapper(int field, int i) = 0;
    00213
    00220     virtual const char *getFieldStructName(int field) = 0;
    00221
    00228     virtual void *getFieldStructPointer(int field, int i) = 0;
    00230 };
    00231
    00232
    00240 class SIM_API sFieldWrapper
    00241 {
    00242   public:
    00248     sFieldWrapper() {}
    00249
    00253     virtual ~sFieldWrapper() {}
    00254
    00259     virtual const char *fieldType() = 0;
    00260
    00268     virtual void getAsString(char *buf, int bufsize) = 0;
    00269
    00277     virtual void setAsString(const char *value) = 0;
    00278 };
    00279
    00280 #endif
    00281