OMNeT++ API 6.2.0
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 
68 class SIM_API cDisplayString
69 {
70  private:
71  enum { MAXARGS = 16 }; // maximum number of arguments per tag
72 
73  // holds one tag
74  struct Tag {
75  char *name;
76  int numArgs;
77  char *args[MAXARGS];
78  Tag() {name=nullptr; numArgs=0;}
79  };
80 
81  char *buffer = nullptr; // holds pieces of display string (sliced with zeroes)
82  char *bufferEnd = nullptr; // points to last byte of buffer allocated
83  Tag *tags = nullptr; // table of tags
84  int numTags = 0; // number of tags
85 
86  mutable char *assembledString = nullptr; // cached copy of assembled display string
87  mutable bool assembledStringValid = true; // if cached copy is up-to-date
88 
89  // needed for notifications
90  cComponent *ownerComponent = nullptr;
91 
92  private:
93  void copy(const cDisplayString& other) {parse(other.str());}
94 
95  // helper functions
96  void doParse(const char *s);
97  void doUpdateWith(const cDisplayString& ds);
98  bool doSetTagArg(int tagindex, int index, const char *value);
99  bool doSetTagArg(const char *tagname, int index, const char *value);
100  int doInsertTag(const char *tagname, int atindex=0);
101  bool doRemoveTag(int tagindex);
102 
103  void doParse();
104  void assemble() const;
105  void clearTags();
106  bool pointsIntoBuffer(char *s) const {return s>=buffer && s<=bufferEnd;}
107  static void strcatescaped(char *d, const char *s);
108 
109  // internal: called before the stored display string changes
110  void beforeChange();
111  // internal: called when the stored display string changes, and notifies Envir in turn.
112  void afterChange();
113 
114  public:
115  // internal:
116  void setHostObject(cComponent *o) {ownerComponent=o;}
117  void dump(std::ostream& out) const;
118 
119  public:
122 
127 
133  cDisplayString(const char *dispstr);
134 
138  cDisplayString(const cDisplayString& ds);
139 
143  ~cDisplayString();
145 
151  cDisplayString& operator=(const cDisplayString& ds);
152 
156  cDisplayString& operator=(const char *s) {parse(s); return *this;}
157 
161  operator const char *() const {return str();}
163 
166 
170  const char *str() const;
171 
175  void set(const char *displaystr) {parse(displaystr);}
176 
188  void parse(const char *displaystr);
189 
194  void updateWith(const cDisplayString& ds);
195 
200  void updateWith(const char *s);
202 
205 
209  bool containsTag(const char *tagname) const;
210 
218  int getNumArgs(const char *tagname) const;
219 
225  const char *getTagArg(const char *tagname, int index) const;
226 
236  bool setTagArg(const char *tagname, int index, const char *value);
237 
242  bool setTagArg(const char *tagname, int index, long value);
243 
249  bool removeTag(const char *tagname);
251 
254 
259  int getNumTags() const;
260 
265  const char *getTagName(int tagindex) const;
266 
271  int getTagIndex(const char *tagname) const;
272 
280  int getNumArgs(int tagindex) const;
281 
287  const char *getTagArg(int tagindex, int index) const;
288 
298  bool setTagArg(int tagindex, int index, const char *value);
299 
307  int insertTag(const char *tagname, int atindex=0);
308 
314  bool removeTag(int tagindex);
316 };
317 
318 
319 } // namespace omnetpp
320 
321 
322 #endif
323 
324 
omnetpp::cDisplayString::set
void set(const char *displaystr)
Definition: cdisplaystring.h:175
omnetpp::cDisplayString::cDisplayString
cDisplayString()
Definition: cdisplaystring.h:126
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:68
omnetpp::cDisplayString::operator=
cDisplayString & operator=(const char *s)
Definition: cdisplaystring.h:156