Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

lyx::string::Srep Struct Reference

List of all members.

Public Methods

 Srep (string::size_type nsz, const string::value_type *p)
 Srep (string::size_type nsz, string::value_type ch)
 ~Srep ()
Srep * get_own_copy ()
void assign (string::size_type nsz, const string::value_type *p)
void assign (string::size_type nsz, string::value_type ch)
void append (string::size_type asz, const string::value_type *p)
void push_back (string::value_type c)
void insert (string::size_type pos, const string::value_type *p, string::size_type n)
void resize (string::size_type n, string::value_type c)
void reserve (string::size_type res_arg)
void replace (string::size_type i, string::size_type n, string::value_type const *p, string::size_type n2)

Public Attributes

size_t sz
 size. More...

size_t ref
 Reference count. More...

size_t res
 The total amount of data reserved for this representaion. More...

string::value_types
 Data. At least 1 char for trailing null. More...


Private Methods

 Srep (const Srep &)
Srep & operator= (const Srep &)

Constructor & Destructor Documentation

Srep::Srep string::size_type    nsz,
const string::value_type   p
 

Definition at line 120 of file lyxstring.C.

References ref, res, s, and sz.

00121 {
00122         // can be called with p == 0 by
00123         // string::assign(const value_type *, size_type)
00124 
00125         sz = nsz;
00126         ref = 1;
00127         res = sz ? sz : 1;
00128         s = new value_type[res + 1]; // add space for terminator
00129         if (p && sz) {
00130                 // if sz = 0 nothing gets copied and we have an error
00131                 memcpy(s, p, sz);
00132         } else {
00133                 // possibly allows for large but empty string
00134                 sz = 0;  // this line should be redundant
00135                 s[0] = '\0';
00136         }
00137 }

Srep::Srep string::size_type    nsz,
string::value_type    ch
 

Definition at line 140 of file lyxstring.C.

References ref, res, s, sz, and lyx::string::value_type.

00141 {
00142         sz = nsz;
00143         ref = 1;
00144         res = sz ? sz : 1;
00145         s = new value_type[res + 1]; // add space for terminator
00146         memset(s, ch, sz);
00147         if (!ch) {
00148                 // if ch == '\0' strlen(string.c_str()) == 0 so sz = 0
00149                 // allows for large but empty string
00150                 sz = 0;
00151         }
00152 }

Srep::~Srep   [inline]
 

Definition at line 87 of file lyxstring.C.

References lyx::string::Srep.

00087 { delete[] s; }

Srep::Srep const Srep &    [private]
 


Member Function Documentation

void Srep::append string::size_type    asz,
const string::value_type   p
 

Definition at line 196 of file lyxstring.C.

References res, s, sz, and lyx::string::value_type.

Referenced by lyx::string::append.

00197 {
00198         register unsigned int const len = sz + asz;
00199         if (res < len) {
00200                 do {
00201                         res *= 2;
00202                 } while (res < len);
00203                 value_type * tmp = new value_type[res + 1];
00204                 memcpy(tmp, s, sz);
00205                 memcpy(tmp + sz, p, asz);
00206                 sz += asz;
00207                 delete[] s;
00208                 s = tmp;
00209         } else {
00210                 memcpy(s + sz, p, asz);
00211                 sz += asz;
00212         }
00213 }

void Srep::assign string::size_type    nsz,
string::value_type    ch
 

Definition at line 179 of file lyxstring.C.

References res, s, sz, and lyx::string::value_type.

00180 {
00181         sz = nsz;
00182         if (res < nsz) {
00183                 delete[] s;
00184                 res = sz ? sz : 1;
00185                 s = new value_type[res + 1]; // add space for terminator
00186         }
00187         memset(s, ch, sz);
00188         if (!ch) {
00189                 // if ch == '\0' strlen(string.c_str()) == 0 so sz = 0
00190                 // allows for a large empty string
00191                 sz = 0;
00192         }
00193 }

void Srep::assign string::size_type    nsz,
const string::value_type   p
 

Definition at line 155 of file lyxstring.C.

References res, s, sz, and lyx::string::value_type.

Referenced by lyx::string::assign, and lyx::string::operator=.

00156 {
00157         // can be called with p == 0
00158         // by string::assign(const value_type *, size_type)
00159 
00160         if (res < nsz) {
00161                 delete[] s;
00162                 sz = nsz;
00163                 res = sz ? sz : 1;
00164                 s = new value_type[res + 1]; // add space for terminator
00165         } else {
00166                 sz = nsz;
00167         }
00168         if (p && sz) {
00169                 // if sz = 0 nothing gets copied and we have an error
00170                 memcpy(s, p, sz);
00171         } else {
00172                 // stops segfaults
00173                 sz = 0;  // this line should be redundant
00174                 s[0] = '\0';
00175         }
00176 }

Srep* Srep::get_own_copy   [inline]
 

Definition at line 89 of file lyxstring.C.

References lyx::string::Srep.

Referenced by lyx::string::append, lyx::string::assign, lyx::string::at, lyx::string::begin, lyx::string::end, lyx::string::erase, lyx::string::insert, lyx::string::operator[], lyx::string::push_back, lyx::string::replace, lyx::string::reserve, and lyx::string::resize.

00089                               {
00090                 if (ref == 1) return this;
00091                 --ref;
00092                 return new Srep(sz, s);
00093         }

void Srep::insert string::size_type    pos,
const string::value_type   p,
string::size_type    n
 

Definition at line 232 of file lyxstring.C.

References res, s, sz, and lyx::string::value_type.

Referenced by lyx::string::insert.

00234 {
00235         if (res < n + sz) {
00236                 do {
00237                         res *= 2;
00238                 } while (res < n + sz);
00239                 value_type * tmp = new value_type[res + 1];
00240                 memcpy(tmp, s, pos);
00241                 memcpy(tmp + pos, p, n);
00242                 memcpy(tmp + pos + n, &s[pos], sz - pos);
00243                 sz += n;
00244                 delete[] s;
00245                 s = tmp;
00246         } else {
00247                 memmove(s + pos + n, &s[pos], sz - pos);
00248                 memcpy(s + pos, p, n);
00249                 sz += n;
00250         }
00251 }

Srep& Srep::operator= const Srep &    [private]
 

void Srep::push_back string::value_type    c
 

Definition at line 216 of file lyxstring.C.

References res, s, sz, and lyx::string::value_type.

Referenced by lyx::string::push_back.

00217 {
00218         s[sz] = c; // it is always room to put a value_type at the end
00219         ++sz;
00220         if (res < sz) {
00221                 do {
00222                         res *= 2;
00223                 } while (res < sz);
00224                 value_type * tmp = new value_type[res + 1];
00225                 memcpy(tmp, s, sz);
00226                 delete[] s;
00227                 s = tmp;
00228         }
00229 }

void Srep::replace string::size_type    i,
string::size_type    n,
string::value_type const *    p,
string::size_type    n2
 

Definition at line 280 of file lyxstring.C.

References res, s, lyx::string::size_type, sz, and lyx::string::value_type.

Referenced by lyx::string::replace.

00282 {
00283 // can be called with p= 0 and n2= 0
00284         n = min(sz - i, n);
00285         sz -= n;
00286         if (res >= n2 + sz) {
00287                 memmove(s + i + n2, &s[i + n], sz - i);
00288                 memcpy(s + i, p, n2);
00289                 sz += n2;
00290         } else {
00291                 do {
00292                         res *= 2;
00293                 } while (res < n2 + sz);
00294                 value_type * tmp = new value_type[res + 1];
00295                 memcpy(tmp, s, i);
00296                 memcpy(tmp + i, p, n2);
00297                 memcpy(tmp + i + n2, &s[i + n], sz - i);
00298                 delete[] s;
00299                 s = tmp;
00300                 sz += n2;
00301         }
00302 }

void Srep::reserve string::size_type    res_arg
 

Definition at line 268 of file lyxstring.C.

References res, s, and sz.

Referenced by lyx::string::reserve.

00269 {
00270         // This keeps the old sz, but
00271         // increases res with res_arg
00272         res += res_arg;
00273         value_type * tmp = new value_type[res + 1];
00274         memcpy(tmp, s, sz);
00275         delete[] s;
00276         s = tmp;
00277 }

void Srep::resize string::size_type    n,
string::value_type    c
 

Definition at line 254 of file lyxstring.C.

References res, s, lyx::string::size_type, sz, and lyx::string::value_type.

Referenced by lyx::string::resize.

00255 {
00256         // This resets sz to res_arg
00257         res = min(n, npos - 2); // We keep no xtra when we resize
00258         value_type * tmp = new value_type[res + 1];
00259         memcpy(tmp, s, min(sz, res));
00260         if (res > sz)
00261                 memset(tmp + sz, c, res - sz);
00262         delete[] s;
00263         sz = res;
00264         s = tmp;
00265 }


Member Data Documentation

size_t lyx::string::Srep::ref
 

Reference count.

Definition at line 76 of file lyxstring.C.

Referenced by lyx::string::assign, lyx::string::operator=, Srep, and lyx::string::~string.

size_t lyx::string::Srep::res
 

The total amount of data reserved for this representaion.

Definition at line 78 of file lyxstring.C.

Referenced by append, assign, lyx::string::capacity, insert, push_back, replace, reserve, resize, and Srep.

string::value_type* lyx::string::Srep::s
 

Data. At least 1 char for trailing null.

Definition at line 80 of file lyxstring.C.

Referenced by append, assign, lyx::string::at, lyx::string::begin, lyx::string::c_str, lyx::string::copy, lyx::string::data, lyx::string::end, lyx::string::erase, lyx::string::find, lyx::string::find_first_not_of, lyx::string::find_first_of, lyx::string::find_last_not_of, lyx::string::find_last_of, insert, lyx::string::internal_compare, lyx::string::operator[], push_back, replace, reserve, resize, lyx::string::rfind, and Srep.

size_t lyx::string::Srep::sz
 

size.

Definition at line 74 of file lyxstring.C.

Referenced by append, assign, lyx::string::compare, lyx::string::end, lyx::string::erase, lyx::string::find, lyx::string::find_first_not_of, lyx::string::find_first_of, lyx::string::find_last_not_of, lyx::string::find_last_of, insert, lyx::string::internal_compare, lyx::string::operator[], push_back, lyx::string::replace, replace, reserve, resize, lyx::string::rfind, lyx::string::size, and Srep.


The documentation for this struct was generated from the following file:
Generated on Fri Jul 18 01:19:06 2003 for lyx by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002