ders::text Class Reference

Represents text or string as sequence of arbitrary characters. More...

#include <text.hpp>

List of all members.

Public Member Functions

 text (mem_pool &m)
 text (mem_pool &m, const ch_rng &r)
 text (const text &t)
 ~text ()
textoperator= (const text &t)
textoperator= (const ch_rng &r)
textappend (const ch_rng &r)
textappend (char byte)
int size () const
int capacity () const
void reserve (int sz)
void clear ()
void uninitialized_resize (int sz)
char * begin ()
const char * begin () const
char * end ()
const char * end () const
const char * c_str () const
char & front ()
char front () const
char & back ()
char back () const
char * find (char ch)
const char * find (char ch) const
char * rfind (char ch)
const char * rfind (char ch) const
char * find (const ch_rng &r)
const char * find (const ch_rng &r) const
char * rfind (const ch_rng &r)
const char * rfind (const ch_rng &r) const
bool starts (const ch_rng &r) const
bool ends (const ch_rng &r) const


Detailed Description

Represents text or string as sequence of arbitrary characters.

Definition at line 62 of file text.hpp.


Constructor & Destructor Documentation

ders::text::text ( mem_pool m  )  [inline, explicit]

Definition at line 71 of file text.hpp.

00071 : mp(m) { init(ch_rng(0, 0)); }

ders::text::text ( mem_pool m,
const ch_rng r 
) [inline]

Definition at line 72 of file text.hpp.

00072 : mp(m) { init(r); }

ders::text::text ( const text t  )  [inline]

Definition at line 73 of file text.hpp.

00073 : mp(t.mp) { init(ch_rng(t)); }

ders::text::~text (  )  [inline]

Definition at line 74 of file text.hpp.

00074 { mp.deallocate(buf, resd); }


Member Function Documentation

text& ders::text::operator= ( const text t  )  [inline]

Definition at line 76 of file text.hpp.

00076 { return *this=ch_rng(t); }

text & ders::text::operator= ( const ch_rng r  ) 

Definition at line 63 of file text.cpp.

00064 {
00065  int sz=r.size();
00066  reserve(sz);
00067 
00068  memcpy(buf, r.beg, sz);
00069  used=sz;
00070 
00071  return *this;
00072 }

text & ders::text::append ( const ch_rng r  ) 

Definition at line 74 of file text.cpp.

00075 {
00076  int sz=r.size(), newsz=used+sz;
00077  reserve(newsz);
00078 
00079  memcpy(buf+used, r.beg, sz);
00080  used=newsz;
00081 
00082  return *this;
00083 }

text & ders::text::append ( char  byte  ) 

Definition at line 85 of file text.cpp.

00086 {
00087  reserve(used+1);
00088  buf[used++]=byte;
00089 
00090  return *this;
00091 }

int ders::text::size (  )  const [inline]

Definition at line 82 of file text.hpp.

00082 { return used; }

int ders::text::capacity (  )  const [inline]

Definition at line 83 of file text.hpp.

00083 { return resd; }

void ders::text::reserve ( int  sz  ) 

Definition at line 93 of file text.cpp.

00094 {
00095  assert(sz>=0);
00096 
00097  sz++;
00098  if (sz<=resd) return;
00099  if (resd*2>sz) sz=resd*2;
00100 
00101  char* newbuf=static_cast<char*>(mp.allocate(sz));
00102  memcpy(newbuf, buf, used);
00103 
00104  mp.deallocate(buf, resd);
00105  buf=newbuf;
00106  resd=sz;
00107 }

void ders::text::clear (  )  [inline]

Definition at line 86 of file text.hpp.

00086 { used=0; }

void ders::text::uninitialized_resize ( int  sz  ) 

Definition at line 109 of file text.cpp.

00110 {
00111  assert(sz>=0);
00112 
00113  reserve(sz);
00114  used=sz;
00115 }

char* ders::text::begin (  )  [inline]

Definition at line 89 of file text.hpp.

00089 { return buf; }

const char* ders::text::begin (  )  const [inline]

Definition at line 90 of file text.hpp.

00090 { return buf; }

char* ders::text::end (  )  [inline]

Definition at line 91 of file text.hpp.

00091 { return buf+used; }

const char* ders::text::end (  )  const [inline]

Definition at line 92 of file text.hpp.

00092 { return buf+used; }

const char * ders::text::c_str (  )  const

Definition at line 117 of file text.cpp.

00118 {
00119  assert(resd>used);
00120  buf[used]=0;
00121 
00122  return buf;
00123 }

char& ders::text::front (  )  [inline]

Definition at line 96 of file text.hpp.

00096 { return *begin(); }

char ders::text::front (  )  const [inline]

Definition at line 97 of file text.hpp.

00097 { return *begin(); }

char& ders::text::back (  )  [inline]

Definition at line 98 of file text.hpp.

00098 { return *(end()-1); }

char ders::text::back (  )  const [inline]

Definition at line 99 of file text.hpp.

00099 { return *(end()-1); }

char * ders::text::find ( char  ch  ) 

Definition at line 125 of file text.cpp.

00126 {
00127  char* ptr=(char*)mem_find(begin(), size(), ch);
00128  return ptr ? ptr : end();
00129 }

const char * ders::text::find ( char  ch  )  const [inline]

Definition at line 160 of file text.hpp.

00161 { return const_cast<text*>(this)->find(ch); }

char * ders::text::rfind ( char  ch  ) 

Definition at line 131 of file text.cpp.

00132 {
00133  char* ptr=(char*)mem_rev_find(begin(), size(), ch);
00134  return ptr ? ptr : end();
00135 }

const char * ders::text::rfind ( char  ch  )  const [inline]

Definition at line 163 of file text.hpp.

00164 { return const_cast<text*>(this)->rfind(ch); }

char * ders::text::find ( const ch_rng r  ) 

Definition at line 137 of file text.cpp.

00138 {
00139  char* ptr=(char*)mem_find(begin(), size(), r.beg, r.size());
00140  return ptr ? ptr : end();
00141 }

const char * ders::text::find ( const ch_rng r  )  const [inline]

Definition at line 166 of file text.hpp.

00167 { return const_cast<text*>(this)->find(r); }

char * ders::text::rfind ( const ch_rng r  ) 

Definition at line 143 of file text.cpp.

00144 {
00145  char* ptr=(char*)mem_rev_find(begin(), size(), r.beg, r.size());
00146  return ptr ? ptr : end();
00147 }

const char * ders::text::rfind ( const ch_rng r  )  const [inline]

Definition at line 169 of file text.hpp.

00170 { return const_cast<text*>(this)->rfind(r); }

bool ders::text::starts ( const ch_rng r  )  const

Definition at line 149 of file text.cpp.

00150 {
00151  int sz=r.size();
00152  return size()>=sz && memcmp(begin(), r.beg, sz)==0;
00153 }

bool ders::text::ends ( const ch_rng r  )  const

Definition at line 155 of file text.cpp.

00156 {
00157  int sz=r.size();
00158  return size()>=sz && memcmp(end()-sz, r.beg, sz)==0;
00159 }


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

Generated on Tue Dec 8 11:35:33 2009 for derslib by  doxygen 1.5.5