class PP_String

A String Class for ParmParse

Inheritance:

PP_String


public members:

PP_String ()
PP_String (char c)
PP_String (int len)
PP_String (const char* s)
PP_String (const PP_String& rhs)
PP_String& operator= (const PP_String& rhs)
PP_String& operator+= (const PP_String& right)
PP_String& operator+= (const char* right)
PP_String& operator+= (char c)
PP_String& toUpper ()
PP_String& toLower ()
std::istream& getline (std::istream& strm)
int length () const
bool isNull () const
char& operator [] (int k)
char operator[] (int k) const
const char* c_str () const
double toDouble () const
int toInteger () const
long toLong () const
friend std::ostream& operator<< (std::ostream& os, const PP_String& str)
friend std::istream& operator>> (std::istream& is, PP_String& str)

Documentation

The class PP_String is used to store and manipulate character strings. It has an efficient underlying storage mechanism and some useful string manipulation operations.

The PP_String class is implemented using a character array and reference count. Two PP_Strings may reference the same underlying character array with a reference count of two. When an PP_String copy constructor or copy operator is applied the reference count on the underlying character array is incremented but the actual string is not copied. That is, copying an PP_String is an inexpensive operation. When an PP_String is destructed, the reference count is decremented. The underlying character array is deleted only when the reference count goes to zero. Any operator that modifies an PP_String will make its own copy of the character array before the modification, unless it's the sole owner of the character array in the PP_String.

This is a convenience class for ParmParse and will not be in any way supported by anyone at ANAG.

PP_String ()
Constructs an empty string.

PP_String (char c)
Constructs an PP_String containing the single character c. If c is the null character then this will be the empty string.

PP_String (int len)
Constructs an empty PP_String but allocates enough space to hold a character string of length len. This may be useful when reading in very long lines with the `getline' function; i.e. it may be slightly more efficient to allocate a very large PP_String once and then use `getline' than to use `getline' on an empty string. In general though, you won't notice any difference and you really shouldn't use this constructor.

PP_String (const char* s)
Constructs an PP_String initialized to the character string s. It is an error is `s' is the null string.

PP_String (const PP_String& rhs)
The copy constructor.

PP_String& operator= (const PP_String& rhs)
The assignment operator

PP_String& operator+= (const PP_String& right)
Catenate PP_String right onto end of this PP_String. Return a reference to self to allow for operator chaining.

PP_String& operator+= (const char* right)
Catenate character string right onto end of this PP_String. Returns a reference to self to allow for operator chaining. It is an error is `right' is the null string.

PP_String& operator+= (char c)
Catenate character c onto end of this PP_String. Returns a reference to self to allow for operator chaining. This does nothing if c is the null character.

PP_String& toUpper ()
Converts all characters in this PP_String to upper case. Returns a reference to self to allow for operator chaining.

PP_String& toLower ()
Converts all characters in this PP_String to lower case. Returns a reference to self to allow for operator chaining.

std::istream& getline (std::istream& strm)
Read the next line from the input stream strm and store it as the value of the string. The delimiter for a line of text is the newline character. The newline is extracted from the istream, but it is NOT stored in the PP_String. There is no limit to the length of string that can be extracted.

int length () const
Returns the number of characters stored in this PP_String. This does not include the terminating null character.

bool isNull () const
Returns true if this is the null string.

char& operator [] (int k)
Returns a reference to the kth character in the string. An error occurs if k < 0 or k >= length().

char operator[] (int k) const
Returns kth character in the string. An error occurs if k < 0 or k >= length().

const char* c_str () const
Convert an PP_String to a const char *. This allows an PP_String to be used in any context where a const char* type is needed.

double toDouble () const
Returns the value of the string as a double. In the case when the string is empty or when the initial characters in the string are strictly alphabetic characters, this returns zero. It's equivalent to `atof(c_str())'.

int toInteger () const
Returns the value of the string as a integer. In the case when the string is empty or when the initial characters in the string are strictly alphabetic characters, this returns zero. It's equivalent to `atoi(c_str())'.

long toLong () const
Returns the value of the string as a long. In the case when the string is empty or when the initial characters in the string are strictly alphabetic characters, this returns zero. It's equivalent to `atol(c_str())'.

friend std::ostream& operator<< (std::ostream& os, const PP_String& str)
Write to an ostream in ASCII format.

friend std::istream& operator>> (std::istream& is, PP_String& str)
Read a whitespace delimited string from an istream. This function discards leading whitespace and then reads in non-whitespace character until the next whitespace character or end-of-file. Note that there is no limit, on the length of the character that can be read in, except that dictated by the resources of the machine. Note also that operator>> and operator<< are not completely symmetrical in the case where operator<< writes out a string that contains whitespace. If you're trying to read in a string that contains whitespace, you might want to use getline() instead.


this class has no child classes.

alphabetic index hierarchy of classes


Chombo

Copyright Notice

This software is copyright (C) by the Lawrence Berkeley National Laboratory. Permission is granted to reproduce this software for non-commercial purposes provided that this notice is left intact.

It is acknowledged that the U.S. Government has rights to this software under Contract DE-AC03-765F00098 between the U.S. Department of Energy and the University of California.

This software is provided as a professional and academic contribution for joint exchange. Thus it is experimental, is provided ``as is'', with no warranties of any kind whatsoever, no support, no promise of updates, or printed documentation. By using this software, you acknowledge that the Lawrence Berkeley National Laboratory and Regents of the University of California shall have no liability with respect to the infringement of other copyrights by any part of this software.