A word, that is, a string with very few properties.
More...
#include <words.h>
List of all members.
Public Member Functions |
| word () |
| Default constructor of an empty word.
|
| word (const char *s) |
| Constructor of a word based on a given C-style string.
|
| word (const word &w) |
| Copy constructor.
|
| ~word () |
| Destructor.
|
word & | operator= (const word &w) |
| Assignment operator.
|
int | length () const |
| Returns the length of the word (without the ending zero char).
|
const char * | text () const |
| Returns a pointer to the contents of the word.
|
| operator const char * () const |
| Returns a pointer to the contents of the word.
|
word & | operator+= (const word &w) |
| Word concatenation operator.
|
word | operator+ (const word &w) const |
| Word concatenation operator.
|
| operator int () const |
| Returns the value of the number contained in the word; allows a preceding '+'.
|
Private Attributes |
int | len |
| The length of the word (without the terminating zero character).
|
char * | txt |
| A memory buffer containing the word.
|
Detailed Description
A word, that is, a string with very few properties.
Definition at line 65 of file words.h.
Constructor & Destructor Documentation
chomp::homology::word::word |
( |
|
) |
[inline] |
Default constructor of an empty word.
Definition at line 113 of file words.h.
References len, and txt.
{
len = 0;
txt = NULL;
return;
}
chomp::homology::word::word |
( |
const char * |
s |
) |
[inline] |
Constructor of a word based on a given C-style string.
Definition at line 120 of file words.h.
References len, and txt.
{
len = s ? strlen (s) : 0;
if (!len)
txt = NULL;
else
{
txt = new char [len + 1];
if (!txt)
throw "Not enough memory to create a word.";
strcpy (txt, s);
}
return;
}
chomp::homology::word::word |
( |
const word & |
w |
) |
[inline] |
Copy constructor.
Definition at line 135 of file words.h.
References len, and txt.
{
len = w. len;
if (!len)
txt = NULL;
else
{
txt = new char [len + 1];
if (!txt)
throw "Not enough memory to copy a word.";
strcpy (txt, w. txt);
}
return;
}
chomp::homology::word::~word |
( |
|
) |
[inline] |
Destructor.
Definition at line 150 of file words.h.
References txt.
{
if (txt)
delete [] txt;
return;
}
Member Function Documentation
int chomp::homology::word::length |
( |
|
) |
const [inline] |
Returns the length of the word (without the ending zero char).
Definition at line 174 of file words.h.
References len.
chomp::homology::word::operator const char * |
( |
|
) |
const [inline] |
Returns a pointer to the contents of the word.
Definition at line 184 of file words.h.
References txt.
chomp::homology::word::operator int |
( |
|
) |
const [inline] |
Returns the value of the number contained in the word; allows a preceding '+'.
Definition at line 215 of file words.h.
References len, and txt.
{
if (!len)
return 0;
char *s = txt;
if (*s == '+')
++ s;
int num;
std::istringstream str (s);
str >> num;
if (!str)
return 0;
else
return num;
}
word chomp::homology::word::operator+ |
( |
const word & |
w |
) |
const [inline] |
Word concatenation operator.
Definition at line 208 of file words.h.
{
word new_w (*this);
new_w += w;
return new_w;
}
word & chomp::homology::word::operator+= |
( |
const word & |
w |
) |
[inline] |
Word concatenation operator.
Definition at line 189 of file words.h.
References len, and txt.
{
if (!len)
{
*this = w;
return *this;
}
if (!w. len)
return *this;
int newlen = len + w. len;
char *newtxt = new char [newlen + 1];
strcpy (newtxt, txt);
strcat (newtxt, w. txt);
delete [] txt;
txt = newtxt;
len = newlen;
return *this;
}
word & chomp::homology::word::operator= |
( |
const word & |
w |
) |
[inline] |
Assignment operator.
Definition at line 157 of file words.h.
References len, and txt.
{
if (txt)
delete [] txt;
len = w. len;
if (w. txt)
{
txt = new char [len + 1];
if (!txt)
throw "Not enough memory to copy a word.";
strcpy (txt, w. txt);
}
else
txt = NULL;
return *this;
}
const char * chomp::homology::word::text |
( |
|
) |
const [inline] |
Returns a pointer to the contents of the word.
Definition at line 179 of file words.h.
References txt.
Member Data Documentation
The documentation for this class was generated from the following file: