cDisplayString Class Reference
[Utility classes]

Class for storage and easy manipulation of display strings. More...

#include <cdisplaystring.h>

List of all members.

Public Member Functions

Constructors, destructor.

 cDisplayString ()
 cDisplayString (const char *dispstr)
 cDisplayString (const cDisplayString &ds)
 ~cDisplayString ()
Assignment, conversions.

cDisplayStringoperator= (const cDisplayString &ds)
cDisplayStringoperator= (const char *s)
 operator const char * () const
Getting and setting the stored display string.

const char * str () const
void set (const char *displaystr)
void parse (const char *displaystr)
void updateWith (const cDisplayString &ds)
void updateWith (const char *s)
Manipulating tags by name.

bool containsTag (const char *tagname) const
int getNumArgs (const char *tagname) const
const char * getTagArg (const char *tagname, int index) const
bool setTagArg (const char *tagname, int index, const char *value)
bool setTagArg (const char *tagname, int index, long value)
bool removeTag (const char *tagname)
Manipulating tags by index.

int getNumTags () const
const char * getTagName (int tagindex) const
int getTagIndex (const char *tagname) const
int getNumArgs (int tagindex) const
const char * getTagArg (int tagindex, int index) const
bool setTagArg (int tagindex, int index, const char *value)
int insertTag (const char *tagname, int atindex=0)
bool removeTag (int tagindex)

Detailed Description

Class for storage and easy manipulation of display strings.

Display strings are used to control the graphical presentation of network elements when a GUI execution environment is used (Tkenv).

A display string consist of several named tags, where each tag may have several arguments (parameters). The syntax: "tag1=value1,val2,val3;tag2=val4,val5".

This class facilitates tasks such as adding new tags, adding arguments to existing tags, removing tags or replacing arguments. The internal storage method allows very fast operation; it will generally be faster than direct string manipulation.

The object doesn't try to interpret the display string in any way, nor does it know the meaning of the different tags; it merely parses the string as data elements separated by semicolons, equal signs and commas.

An example:

   cDisplayString dispstr("a=1,2;p=alpha,,3");
   dispstr.insertTag("x");
   dispstr.setTagArg("x",0,"joe");
   dispstr.setTagArg("x",2,"jim");
   dispstr.setTagArg("p",0,"beta");
   ev << dispstr.str();  // result: "x=joe,,jim;a=1,2;p=beta,,3"
 

Limitation: a tag may have at most 16 arguments.


Constructor & Destructor Documentation

cDisplayString::cDisplayString ( const char *  dispstr  ) 

Constructor.

Throws an error if there was an error parsing the string.


Member Function Documentation

int cDisplayString::getNumArgs ( int  tagindex  )  const

Returns the number of arguments a tag actually has in the display string.

The count includes empty arguments too. For example, for the "x=8,,15,2;y=2" display string getNumArgs("x") returns 4, and getNumArgs("y") returns 1. If the display string doesn't contain the given tag, 0 is returned.

int cDisplayString::getNumArgs ( const char *  tagname  )  const

Returns the number of arguments a tag actually has in the display string.

The count includes empty arguments too. For example, for the "x=8,,15,2;y=2" display string getNumArgs("x") returns 4, and getNumArgs("y") returns 1. If the display string doesn't contain the given tag, 0 is returned.

int cDisplayString::getNumTags (  )  const

Returns the number of tags in the display string.

Tags are indexed starting from 0.

const char* cDisplayString::getTagArg ( int  tagindex,
int  index 
) const

Returns pointer to the indexth argument of the given tag.

If the tag doesn't exist or the index is out of range, NULL is returned.

const char* cDisplayString::getTagArg ( const char *  tagname,
int  index 
) const

Returns pointer to the indexth argument of the given tag.

If the tag doesn't exist or the index is out of range, empty string ("") is returned.

const char* cDisplayString::getTagName ( int  tagindex  )  const

Returns the name of the tag given with its index.

If the tag index is out of range, NULL is returned.

int cDisplayString::insertTag ( const char *  tagname,
int  atindex = 0 
)

Inserts a tag into the display string, optionally at the given index.

If no index is given, the tag is inserted at the beginning of the string. Return value is the index of the tag. If the display string already contains a tag with the given tagname, nothing is changed and the index of the existing tag is returned.

void cDisplayString::parse ( const char *  displaystr  ) 

Sets the display string to the given value.

Throws an error if there was an error parsing the string.

bool cDisplayString::removeTag ( int  tagindex  ) 

Removes the given tag with all its arguments from the display string.

The result is true if the tag was actually deleted (it existed before), false otherwise.

bool cDisplayString::removeTag ( const char *  tagname  ) 

Removes the given tag with all its arguments from the display string.

The result is true if the tag was actually deleted (it existed before), false otherwise.

bool cDisplayString::setTagArg ( int  tagindex,
int  index,
const char *  value 
)

Sets an argument for the given tag.

The value may be NULL pointer. If index points beyond the last argument, the list of arguments will be extended by inserting intervening empty arguments if necessary.

The result is true if the operation was successful. False is returned if the given tag doesn't exist, or index is invalid (negative or greater than the maximum numer of arguments, currently 16).

bool cDisplayString::setTagArg ( const char *  tagname,
int  index,
long  value 
)

Convenience function to set a tag argument to a numeric value.

Converts 'value' to string, then calls setTagArg(const char *, int, const char *).

bool cDisplayString::setTagArg ( const char *  tagname,
int  index,
const char *  value 
)

Sets an argument for the given tag.

The value may be NULL pointer. If index points beyond the last argument, the list of arguments will be extended by inserting intervening empty arguments if necessary.

The result is true if the operation was successful. False is returned if the given tag doesn't exist, or index is invalid (negative or greater than the maximum number of arguments, currently 16).

void cDisplayString::updateWith ( const char *  s  ) 

Update with the contents of another display string.

Corresponding elements from the new display string will overwrite existing values.

void cDisplayString::updateWith ( const cDisplayString ds  ) 

Update with the contents of another display string.

Corresponding elements from the new display string will overwrite existing values.


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:28 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3