Main Page Modules Class Hierarchy Compound List File List Compound Members

# cdispstr.h

    00001 //==========================================================================
    00002 //   CDISPSTR.H   - header for
    00003 //                             OMNeT++
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //
    00007 //  Declaration of the following classes:
    00008 //    cDisplayStringParser : utility class for display string manipulation
    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 __CDISPSTR_H
    00020 #define __CDISPSTR_H
    00021
    00022 #include "cobject.h"
    00023
    00024
    00025 #define MAXARGS 16
    00026
    00027
    00060 class cDisplayStringParser
    00061 {
    00062   private:
    00063     struct Tag {
    00064        char *name;
    00065        int numargs;
    00066        char *args[MAXARGS];
    00067     };
    00068     char *dispstr;      // copy of display string
    00069     char *buffer;       // holds pieces of display string (sliced with zeroes)
    00070     char *bufferend;    // points to last byte of buffer allocated
    00071     Tag *tags;          // table of tags
    00072     int numtags;        // number of tags
    00073   private:
    00074     // helper functions
    00075     bool parse();
    00076     void assemble();
    00077     int gettagindex(const char *tagname);
    00078     void cleartags();
    00079     bool isinbuffer(char *s) {return s>=buffer && s<=bufferend;}
    00080     void strcatescaped(char *d, const char *s);
    00081
    00082   public:
    00085
    00089     cDisplayStringParser();
    00090
    00094     cDisplayStringParser(const char *dispstr);
    00095
    00099     ~cDisplayStringParser();
    00101
    00104
    00108     const char *getString();
    00109
    00113     bool parse(const char *displaystr);
    00115
    00118
    00122     bool existsTag(const char *tagname);
    00123
    00131     int getNumArgs(const char *tagname);
    00132
    00138     const char *getTagArg(const char *tagname, int index);
    00139
    00149     bool setTagArg(const char *tagname, int index, const char *value);
    00150
    00156     bool removeTag(const char *tagname);
    00158
    00161
    00166     int getNumTags();
    00167
    00172     const char *getTagName(int tagindex);
    00173
    00181     int getNumArgs(int tagindex);
    00182
    00188     const char *getTagArg(int tagindex, int index);
    00189
    00199     bool setTagArg(int tagindex, int index, const char *value);
    00200
    00206     bool insertTag(const char *tagname, int atindex=0);
    00207
    00213     bool removeTag(int tagindex);
    00215 };
    00216
    00217 #endif
    00218
    00219