OMNeT++ API 6.1
Discrete Event Simulation Library
cdisplaystring.h
1 //==========================================================================
2 // CDISPLAYSTRING.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CDISPLAYSTRING_H
17 #define __OMNETPP_CDISPLAYSTRING_H
18 
19 #include "cobject.h"
20 #include "cgate.h"
21 #include "cmodule.h"
22 
23 namespace omnetpp {
24 
25 
67 class SIM_API cDisplayString
68 {
69  private:
70  enum { MAXARGS = 16 }; // maximum number of arguments per tag
71 
72  // holds one tag
73  struct Tag {
74  char *name;
75  int numArgs;
76  char *args[MAXARGS];
77  Tag() {name=nullptr; numArgs=0;}
78  };
79 
80  char *buffer = nullptr; // holds pieces of display string (sliced with zeroes)
81  char *bufferEnd = nullptr; // points to last byte of buffer allocated
82  Tag *tags = nullptr; // table of tags
83  int numTags = 0; // number of tags
84 
85  mutable char *assembledString = nullptr; // cached copy of assembled display string
86  mutable bool assembledStringValid = true; // if cached copy is up-to-date
87 
88  // needed for notifications
89  cComponent *ownerComponent = nullptr;
90 
91  private:
92  void copy(const cDisplayString& other) {parse(other.str());}
93 
94  // helper functions
95  void doParse(const char *s);
96  void doUpdateWith(const cDisplayString& ds);
97  bool doSetTagArg(int tagindex, int index, const char *value);
98  bool doSetTagArg(const char *tagname, int index, const char *value);
99  int doInsertTag(const char *tagname, int atindex=0);
100  bool doRemoveTag(int tagindex);
101 
102  void doParse();
103  void assemble() const;
104  void clearTags();
105  bool pointsIntoBuffer(char *s) const {return s>=buffer && s<=bufferEnd;}
106  static void strcatescaped(char *d, const char *s);
107 
108  // internal: called before the stored display string changes
109  void beforeChange();
110  // internal: called when the stored display string changes, and notifies Envir in turn.
111  void afterChange();
112 
113  public:
114  // internal:
115  void setHostObject(cComponent *o) {ownerComponent=o;}
116  void dump(std::ostream& out) const;
117 
118  public:
121 
126 
132  cDisplayString(const char *dispstr);
133 
137  cDisplayString(const cDisplayString& ds);
138 
142  ~cDisplayString();
144 
150  cDisplayString& operator=(const cDisplayString& ds);
151 
155  cDisplayString& operator=(const char *s) {parse(s); return *this;}
156 
160  operator const char *() const {return str();}
162 
165 
169  const char *str() const;
170 
174  void set(const char *displaystr) {parse(displaystr);}
175 
187  void parse(const char *displaystr);
188 
193  void updateWith(const cDisplayString& ds);
194 
199  void updateWith(const char *s);
201 
204 
208  bool containsTag(const char *tagname) const;
209 
217  int getNumArgs(const char *tagname) const;
218 
224  const char *getTagArg(const char *tagname, int index) const;
225 
235  bool setTagArg(const char *tagname, int index, const char *value);
236 
241  bool setTagArg(const char *tagname, int index, long value);
242 
248  bool removeTag(const char *tagname);
250 
253 
258  int getNumTags() const;
259 
264  const char *getTagName(int tagindex) const;
265 
270  int getTagIndex(const char *tagname) const;
271 
279  int getNumArgs(int tagindex) const;
280 
286  const char *getTagArg(int tagindex, int index) const;
287 
297  bool setTagArg(int tagindex, int index, const char *value);
298 
306  int insertTag(const char *tagname, int atindex=0);
307 
313  bool removeTag(int tagindex);
315 };
316 
317 
318 } // namespace omnetpp
319 
320 
321 #endif
322 
323 
omnetpp::cDisplayString::set
void set(const char *displaystr)
Definition: cdisplaystring.h:174
omnetpp::cDisplayString::cDisplayString
cDisplayString()
Definition: cdisplaystring.h:125
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
omnetpp::cDisplayString::str
const char * str() const
omnetpp::cDisplayString
Represents a display string.
Definition: cdisplaystring.h:67
omnetpp::cDisplayString::operator=
cDisplayString & operator=(const char *s)
Definition: cdisplaystring.h:155