- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages

# cdispstr.h

    00001 //==========================================================================
    00002 //   CDISPSTR.H  - part of
    00003 //                     OMNeT++/OMNEST
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //
    00007 //  Declaration of the following classes:
    00008 //    cDisplayString : utility class for display string manipulation
    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 __CDISPSTR_H
    00020 #define __CDISPSTR_H
    00021
    00022 #include "cobject.h"
    00023
    00024
    00025 #define MAXARGS 16
    00026
    00027
    00060 class SIM_API cDisplayString
    00061 {
    00062   private:
    00063     struct Tag {
    00064        char *name;
    00065        int numargs;
    00066        char *args[MAXARGS];
    00067     };
    00068     char *buffer;       // holds pieces of display string (sliced with zeroes)
    00069     char *bufferend;    // points to last byte of buffer allocated
    00070     Tag *tags;          // table of tags
    00071     int numtags;        // number of tags
    00072
    00073     mutable char *dispstr; // cached copy of assembled display string
    00074     mutable bool needsassemble; // if dispstr is up-to-date
    00075
    00076     // needed to notify Envir
    00077     cObject *object;     // a cModule or cGate pointer
    00078     enum {NONE, CONNECTION, MODULE, MODULEBACKGROUND} role; // what
    00079
    00080   private:
    00081     // helper functions
    00082     bool parse();
    00083     void assemble() const;
    00084     int gettagindex(const char *tagname) const;
    00085     void cleartags();
    00086     bool isinbuffer(char *s) {return s>=buffer && s<=bufferend;}
    00087     static void strcatescaped(char *d, const char *s);
    00088
    00089   private:
    00090     // internal: called when the stored display string changes, and notifies Envir in turn.
    00091     void notify();
    00092
    00093   public:
    00094     // internal:
    00095     void setRoleToConnection(cGate *gate) {object=gate; role=CONNECTION;}
    00096     void setRoleToModule(cModule *submodule) {object=submodule; role=MODULE;}
    00097     void setRoleToModuleBackground(cModule *module) {object=module; role=MODULEBACKGROUND;}
    00098
    00099   public:
    00102
    00106     cDisplayString();
    00107
    00111     cDisplayString(const char *dispstr);
    00112
    00116     cDisplayString(const cDisplayString& ds);
    00117
    00121     ~cDisplayString();
    00123
    00129     cDisplayString& operator=(const cDisplayString& ds) {parse(ds.getString()); return *this;}
    00130
    00134     cDisplayString& operator=(const char *s)  {parse(s); return *this;}
    00135
    00139     operator const char *() const  {return getString();}
    00141
    00144
    00148     const char *getString() const;
    00149
    00154     bool parse(const char *displaystr);
    00156
    00159
    00163     bool existsTag(const char *tagname) const;
    00164
    00172     int getNumArgs(const char *tagname) const;
    00173
    00179     const char *getTagArg(const char *tagname, int index) const;
    00180
    00190     bool setTagArg(const char *tagname, int index, const char *value);
    00191
    00196     bool setTagArg(const char *tagname, int index, long value);
    00197
    00203     bool removeTag(const char *tagname);
    00205
    00208
    00213     int getNumTags() const;
    00214
    00219     const char *getTagName(int tagindex) const;
    00220
    00228     int getNumArgs(int tagindex) const;
    00229
    00235     const char *getTagArg(int tagindex, int index) const;
    00236
    00246     bool setTagArg(int tagindex, int index, const char *value);
    00247
    00255     int insertTag(const char *tagname, int atindex=0);
    00256
    00262     bool removeTag(int tagindex);
    00264 };
    00265
    00266
    00267 #endif
    00268
    00269