next up previous
Next: Parameters Class Up: C++ Classes Previous: C++ Classes

DString Class

 

The DString class is a general-purpose class developed to dynamically manage strings of text. C is notoriously awkward for performing string manipulations, so this class helps to make their usage more convenient. Many of the file names, GRASS variables, labels and similar information used in LUCAS are text-based, therefore almost every instance of a string is a DString object. Instantiating a DString object will automatically claim a portion of the system heap to store the string; actually an array of characters.

Aside from automatic storage allocation and release of memory, the DString class also provides much superior operators for string manipulation. In order to concatenate strings or other objects the insertion operator << is used. To compare two strings, the intuitive == operator is used. For example:

 DString some_string;
 DString other_string = "Something else";
 int     intvalue     = 5;
  
 some_string << "X has a value of " << intvalue << " now.";
 if ( some_string == other_string ) {
   cout << "The strings are equal.\n";
 }

The only difficulty in using such objects is that the GRASS routines require char* arguments, instead of DString objects, to be passed to them. This problem is overcome by creating an operator to return the internal character array.



Michael W. Berry (berry@cs.utk.edu)
Wed Aug 16 10:48:40 EDT 1995