The Original CHomP Software
Public Member Functions | Private Attributes | List of all members
chomp::homology::word Class Reference

A word, that is, a string with very few properties. More...

#include <words.h>

Public Member Functions

 word ()
 Default constructor of an empty word. More...
 
 word (const char *s)
 Constructor of a word based on a given C-style string. More...
 
 word (const word &w)
 Copy constructor. More...
 
 ~word ()
 Destructor. More...
 
wordoperator= (const word &w)
 Assignment operator. More...
 
int length () const
 Returns the length of the word (without the ending zero char). More...
 
const char * text () const
 Returns a pointer to the contents of the word. More...
 
 operator const char * () const
 Returns a pointer to the contents of the word. More...
 
wordoperator+= (const word &w)
 Word concatenation operator. More...
 
word operator+ (const word &w) const
 Word concatenation operator. More...
 
 operator int () const
 Returns the value of the number contained in the word; allows a preceding '+'. More...
 

Private Attributes

int len
 The length of the word (without the terminating zero character). More...
 
char * txt
 A memory buffer containing the word. More...
 

Detailed Description

A word, that is, a string with very few properties.

Definition at line 64 of file words.h.

Constructor & Destructor Documentation

◆ word() [1/3]

chomp::homology::word::word ( )
inline

Default constructor of an empty word.

Definition at line 112 of file words.h.

113{
114 len = 0;
115 txt = NULL;
116 return;
117} /* word::word */
char * txt
A memory buffer containing the word.
Definition: words.h:106
int len
The length of the word (without the terminating zero character).
Definition: words.h:103

References len, and txt.

◆ word() [2/3]

chomp::homology::word::word ( const char *  s)
inline

Constructor of a word based on a given C-style string.

Definition at line 119 of file words.h.

120{
121 len = s ? strlen (s) : 0;
122 if (!len)
123 txt = NULL;
124 else
125 {
126 txt = new char [len + 1];
127 if (!txt)
128 throw "Not enough memory to create a word.";
129 strcpy (txt, s);
130 }
131 return;
132} /* word::word */

References len, and txt.

◆ word() [3/3]

chomp::homology::word::word ( const word w)
inline

Copy constructor.

Definition at line 134 of file words.h.

135{
136 len = w. len;
137 if (!len)
138 txt = NULL;
139 else
140 {
141 txt = new char [len + 1];
142 if (!txt)
143 throw "Not enough memory to copy a word.";
144 strcpy (txt, w. txt);
145 }
146 return;
147} /* word::word */

References len, and txt.

◆ ~word()

chomp::homology::word::~word ( )
inline

Destructor.

Definition at line 149 of file words.h.

150{
151 if (txt)
152 delete [] txt;
153 return;
154} /* word::~word */

References txt.

Member Function Documentation

◆ length()

int chomp::homology::word::length ( ) const
inline

Returns the length of the word (without the ending zero char).

Definition at line 173 of file words.h.

174{
175 return len;
176} /* length */

References len.

◆ operator const char *()

chomp::homology::word::operator const char * ( ) const
inline

Returns a pointer to the contents of the word.

Definition at line 183 of file words.h.

184{
185 return txt;
186} /* operator int */

◆ operator int()

chomp::homology::word::operator int ( ) const
inline

Returns the value of the number contained in the word; allows a preceding '+'.

Definition at line 214 of file words.h.

215{
216 if (!len)
217 return 0;
218 char *s = txt;
219 if (*s == '+')
220 ++ s;
221 int num;
222 std::istringstream str (s);
223 str >> num;
224 if (!str)
225 return 0;
226 else
227 return num;
228} /* operator int */

◆ operator+()

word chomp::homology::word::operator+ ( const word w) const
inline

Word concatenation operator.

Definition at line 207 of file words.h.

208{
209 word new_w (*this);
210 new_w += w;
211 return new_w;
212} /* operator + */
word()
Default constructor of an empty word.
Definition: words.h:112

◆ operator+=()

word & chomp::homology::word::operator+= ( const word w)
inline

Word concatenation operator.

Definition at line 188 of file words.h.

189{
190 if (!len)
191 {
192 *this = w;
193 return *this;
194 }
195 if (!w. len)
196 return *this;
197 int newlen = len + w. len;
198 char *newtxt = new char [newlen + 1];
199 strcpy (newtxt, txt);
200 strcat (newtxt, w. txt);
201 delete [] txt;
202 txt = newtxt;
203 len = newlen;
204 return *this;
205} /* operator += */

References len, and txt.

◆ operator=()

word & chomp::homology::word::operator= ( const word w)
inline

Assignment operator.

Definition at line 156 of file words.h.

157{
158 if (txt)
159 delete [] txt;
160 len = w. len;
161 if (w. txt)
162 {
163 txt = new char [len + 1];
164 if (!txt)
165 throw "Not enough memory to copy a word.";
166 strcpy (txt, w. txt);
167 }
168 else
169 txt = NULL;
170 return *this;
171} /* operator = */

References len, and txt.

◆ text()

const char * chomp::homology::word::text ( ) const
inline

Returns a pointer to the contents of the word.

Definition at line 178 of file words.h.

179{
180 return txt;
181} /* text */

References txt.

Member Data Documentation

◆ len

int chomp::homology::word::len
private

The length of the word (without the terminating zero character).

Definition at line 103 of file words.h.

Referenced by length(), operator+=(), operator=(), and word().

◆ txt

char* chomp::homology::word::txt
private

A memory buffer containing the word.

Definition at line 106 of file words.h.

Referenced by operator+=(), operator=(), text(), word(), and ~word().


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