cdisplaystring.h

00001 //==========================================================================
00002 //   CDISPLAYSTRING.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-2008 Andras Varga
00014   Copyright (C) 2006-2008 OpenSim Ltd.
00015 
00016   This file is distributed WITHOUT ANY WARRANTY. See the file
00017   `license' for details on this and other legal matters.
00018 *--------------------------------------------------------------*/
00019 
00020 #ifndef __CDISPLAYSTRING_H
00021 #define __CDISPLAYSTRING_H
00022 
00023 #include "cobject.h"
00024 #include "cgate.h"
00025 #include "cmodule.h"
00026 
00027 NAMESPACE_BEGIN
00028 
00029 
00062 class SIM_API cDisplayString
00063 {
00064   private:
00065     enum { MAXARGS = 16 };  // maximum number of arguments per tag
00066 
00067     // holds one tag
00068     struct Tag {
00069        char *name;
00070        int numargs;
00071        char *args[MAXARGS];
00072        Tag() {name=NULL; numargs=0;}
00073     };
00074 
00075     char *buffer;       // holds pieces of display string (sliced with zeroes)
00076     char *bufferend;    // points to last byte of buffer allocated
00077     Tag *tags;          // table of tags
00078     int numtags;        // number of tags
00079 
00080     mutable char *dispstr; // cached copy of assembled display string
00081     mutable bool needsassemble; // if dispstr is up-to-date
00082 
00083     // needed for notifications
00084     cComponent *ownercomponent;
00085 
00086   private:
00087     void copy(const cDisplayString& other) {parse(other.str());}
00088 
00089     // helper functions
00090     void doParse(const char *s);
00091     void doUpdateWith(const cDisplayString& ds);
00092     bool doSetTagArg(int tagindex, int index, const char *value);
00093     bool doSetTagArg(const char *tagname, int index, const char *value);
00094     int doInsertTag(const char *tagname, int atindex=0);
00095     bool doRemoveTag(int tagindex);
00096 
00097     void doParse();
00098     void assemble() const;
00099     void clearTags();
00100     bool pointsIntoBuffer(char *s) const {return s>=buffer && s<=bufferend;}
00101     static void strcatescaped(char *d, const char *s);
00102 
00103     // internal: called before the stored display string changes
00104     void beforeChange();
00105     // internal: called when the stored display string changes, and notifies Envir in turn.
00106     void afterChange();
00107 
00108   public:
00109     // internal:
00110     void setHostObject(cComponent *o) {ownercomponent=o;}
00111     void dump() const;
00112 
00113   public:
00116 
00120     cDisplayString();
00121 
00125     cDisplayString(const char *dispstr);
00126 
00130     cDisplayString(const cDisplayString& ds);
00131 
00135     ~cDisplayString();
00137 
00143     cDisplayString& operator=(const cDisplayString& ds);
00144 
00148     cDisplayString& operator=(const char *s)  {parse(s); return *this;}
00149 
00153     operator const char *() const  {return str();}
00155 
00158 
00162     const char *str() const;
00163 
00167     void set(const char *displaystr)  {parse(displaystr);}
00168 
00173     void parse(const char *displaystr);
00174 
00179     void updateWith(const cDisplayString& ds);
00180 
00185     void updateWith(const char *s);
00187 
00190 
00194     bool containsTag(const char *tagname) const;
00195 
00203     int getNumArgs(const char *tagname) const;
00204 
00210     const char *getTagArg(const char *tagname, int index) const;
00211 
00221     bool setTagArg(const char *tagname, int index, const char *value);
00222 
00227     bool setTagArg(const char *tagname, int index, long value);
00228 
00234     bool removeTag(const char *tagname);
00236 
00239 
00244     int getNumTags() const;
00245 
00250     const char *getTagName(int tagindex) const;
00251 
00256     int getTagIndex(const char *tagname) const;
00257 
00265     int getNumArgs(int tagindex) const;
00266 
00272     const char *getTagArg(int tagindex, int index) const;
00273 
00283     bool setTagArg(int tagindex, int index, const char *value);
00284 
00292     int insertTag(const char *tagname, int atindex=0);
00293 
00299     bool removeTag(int tagindex);
00301 };
00302 
00303 
00304 NAMESPACE_END
00305 
00306 
00307 #endif
00308 
00309 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3