my_basic_string< charT > Class Template Reference

The implementation for String, the ARTS string class. More...

#include <mystring.h>

List of all members.

Public Member Functions

 my_basic_string ()
 Default constructor.
 my_basic_string (Index n, char c=' ')
 Constructor setting size.
 my_basic_string (const basic_string< charT > &A, Index pos=0, Index npos=my_basic_string< charT >::npos)
 Construnctor from another my_basic_string.
 my_basic_string (const char A[])
 Constructor from a C-style char array.
my_basic_stringoperator= (const my_basic_string< charT > &A)
 Assignment from another my_basic_string.
Index nelem () const
 Number of elements.
const char operator[] (Index n) const
 Find function for char.
char & operator[] (Index n)
 Non-constant index operator.

Static Public Attributes

static const Index npos = static_cast<Index>(std::basic_string<charT>::npos)
 Define npos:.


Detailed Description

template<class charT>
class my_basic_string< charT >

The implementation for String, the ARTS string class.

This adds some additional functionality to the standard stl string class, notably:

a) Range checking by assert

b) nelem() member function, return the size of the String of type Index.

The type std::string is just a typedef for std::basic_string<char>. Therefore, to make everything work correctly, we have to derive our own class from std::basic_string, not from std::string directly.

Definition at line 60 of file mystring.h.


Constructor & Destructor Documentation

template<class charT>
my_basic_string< charT >::my_basic_string (  )  [inline]

Default constructor.

Definition at line 98 of file mystring.h.

template<class charT>
my_basic_string< charT >::my_basic_string ( Index  n,
char  c = ' ' 
) [inline, explicit]

Constructor setting size.

You may give as a second argument a character with which to fill the new string. Per default this is zero.

Parameters:
n Number of characters
c Optional fill character

Definition at line 109 of file mystring.h.

template<class charT>
my_basic_string< charT >::my_basic_string ( const basic_string< charT > &  A,
Index  pos = 0,
Index  npos = my_basic_string<charT>::npos 
) [inline]

Construnctor from another my_basic_string.

Construnctor from a basic_string. This is important for handling of expressions like this to work correctly:

String a = b+'.'+c

As for std::basic_string, this constructor can also be used to initialize the new string from a subrange of the original string.

Parameters:
A The original string
pos Start position (0 means from the beginning)
npos How many characters to copy

Definition at line 131 of file mystring.h.

template<class charT>
my_basic_string< charT >::my_basic_string ( const char  A[]  )  [inline]

Constructor from a C-style char array.

Definition at line 165 of file mystring.h.


Member Function Documentation

template<class charT>
my_basic_string< charT > & my_basic_string< charT >::operator= ( const my_basic_string< charT > &  A  )  [inline]

Assignment from another my_basic_string.

Note that my_basic_string behaves differently from Vector, Matrix, and Array here. The two partners do not have to have the same size. Size of the target string is adjusted automatically, just as std::string does it.

Definition at line 177 of file mystring.h.

template<class charT>
Index my_basic_string< charT >::nelem (  )  const [inline]

Number of elements.

Definition at line 185 of file mystring.h.

template<class charT>
const char my_basic_string< charT >::operator[] ( Index  n  )  const [inline]

Find function for char.

Parameters:
c What character to find.
Returns:
Position of c, or npos if not found.
Unfortunately, the std::basid_string.find() functions returns npos when the character is not found. This is -1, but assigned to a positive type! Gives a very high number. If you add 1 to this number you get zero again, so it does indeed bahave like -1 in a way. Yuck! With Index this does not work. Find function for string.

Parameters:
c What string to find.
Returns:
Position of c, or npos if not found.
Unfortunately, the std::basid_string.find() functions returns npos when the character is not found. This is -1, but assigned to a positive type! Gives a very high number. If you add 1 to this number you get zero again, so it does indeed bahave like -1 in a way. Yuck! With Index this does not work. Constant index operator. We redifine this here so that we can have range checking by assert.

Definition at line 236 of file mystring.h.

template<class charT>
char & my_basic_string< charT >::operator[] ( Index  n  )  [inline]

Non-constant index operator.

We redifine this here so that we can have range checking by assert.

Definition at line 246 of file mystring.h.


Member Data Documentation

template<class charT>
const Index my_basic_string< charT >::npos = static_cast<Index>(std::basic_string<charT>::npos) [static]

Define npos:.

Definition at line 87 of file mystring.h.


The documentation for this class was generated from the following file:

Generated on Wed Feb 4 08:17:33 2009 for ARTS by  doxygen 1.5.6