cdisplaystring.h Source File

API: cdisplaystring.h Source File
API
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
23namespace omnetpp {
24
25
68class 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
139
145
148
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
Common base for module and channel classes.
Definition ccomponent.h:51
cDisplayString & operator=(const char *s)
Definition cdisplaystring.h:156
int getNumArgs(const char *tagname) const
cDisplayString(const char *dispstr)
int getNumArgs(int tagindex) const
bool setTagArg(const char *tagname, int index, long value)
bool containsTag(const char *tagname) const
cDisplayString(const cDisplayString &ds)
bool removeTag(int tagindex)
bool removeTag(const char *tagname)
void parse(const char *displaystr)
const char * getTagArg(const char *tagname, int index) const
void set(const char *displaystr)
Definition cdisplaystring.h:175
void updateWith(const cDisplayString &ds)
int getTagIndex(const char *tagname) const
bool setTagArg(const char *tagname, int index, const char *value)
const char * getTagName(int tagindex) const
cDisplayString()
Definition cdisplaystring.h:126
int insertTag(const char *tagname, int atindex=0)
void updateWith(const char *s)
const char * str() const
bool setTagArg(int tagindex, int index, const char *value)
const char * getTagArg(int tagindex, int index) const
cDisplayString & operator=(const cDisplayString &ds)