00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _GLASS_CHAIN_HH_
00022 #define _GLASS_CHAIN_HH_
00023
00024 #include "msvc.h"
00025 #include "types.h"
00026 #include "exception.h"
00027 #include <string.h>
00028 #include <list>
00029 #include <iostream>
00030 #include <limits.h>
00031
00032 namespace libglass {
00033
00034 class chain;
00035
00044 class LIBGLASS_API record {
00045 #if defined(_MSC_VER)
00046 public:
00047 #else
00048 private:
00049 #endif // _MSC_VER
00050
00051 record();
00053 record *operator=(const record *s);
00054
00055 protected:
00057 struct _record {
00058 unsigned int references;
00059 bool allocated;
00060 unsigned int size;
00061 const char *data;
00062 };
00063 _record *r;
00065 int offset;
00066 int roffset;
00068 public:
00069
00079 record(const char *p, unsigned int size, bool allocated,
00080 const char *allocateddata = NULL);
00081
00089 record(const record *r, int offset = 0, int roffset = 0);
00090
00091 record(const record &r, int offset = 0, int roffset = 0);
00092
00093 ~record();
00094
00095 record &operator=(const record &s);
00096
00100 const char *getData(void) const;
00101
00105 unsigned int getLength(void) const;
00106
00110 void print() const;
00111 };
00112
00113 class chain_iterator {
00114 private:
00115 std::list<record>::iterator it;
00117 protected:
00118 friend class chain;
00119
00120 void setiterator(std::list<record>::iterator it) {
00121 this->it = it;
00122 }
00123
00124 public:
00125 chain_iterator() { }
00126
00127 const chain_iterator& operator++() {
00128 ++it;
00129 return *this;
00130 }
00131
00132 const chain_iterator operator++(int) {
00133 it++;
00134 return *this;
00135 }
00136
00137 const chain_iterator& operator--() {
00138 --it;
00139 return *this;
00140 }
00141
00142 const chain_iterator operator--(int) {
00143 it--;
00144 return *this;
00145 }
00146
00147 bool operator==(const chain_iterator &i) const {
00148 return (this->it == i.it);
00149 }
00150
00151 bool operator!=(const chain_iterator &i) const {
00152 return (this->it != i.it);
00153 }
00154
00155 const char *data(void) const {
00156 return it->getData();
00157 }
00158
00159 unsigned int size(void) const {
00160 return it->getLength();
00161 }
00162 };
00163
00176 #if defined(_MSC_VER)
00177
00178 LIBGLASS_IMP_TEMPLATE_STL_LIST(libglass::record);
00179 #endif // _MSC_VER
00180
00181
00182 class LIBGLASS_API chain {
00183 public:
00184
00185 typedef chain_iterator iterator;
00186
00187 #if defined(_MSC_VER) && (_MSC_VER < 1300) // earlier than .NET compiler (VC 7.0)
00188
00189
00190 enum{ npos = UINT_MAX };
00191 #else
00192 static const unsigned int npos = UINT_MAX;
00193 #endif
00194
00195 private:
00196 const char *getPosition(unsigned int position) const throw(Exception);
00197
00198 protected:
00199 friend class chain_iterator;
00200
00201 std::list<record> pieces;
00202
00203 public:
00207 chain();
00208
00215 chain(const char *p, unsigned int s = 0);
00216
00225 chain(std::string &s);
00226
00230 ~chain();
00231
00235 void clear(void);
00236
00241 unsigned int size(void) const;
00242
00247 unsigned int length(void) const;
00248
00256 char &operator[](unsigned int position) throw(Exception);
00257
00264 const chain &operator=(const chain &s);
00265
00279 const chain &assign(char *p, unsigned int s = 0, bool free = false,
00280 char *allocatedbegin = NULL);
00281
00282 const chain &assign(std::string &s);
00283
00284 const chain &assign(const chain &s);
00285
00292 const bool operator<(const chain &c) const;
00293
00301 const chain &operator+=(const chain &s);
00302
00310 const chain &operator+=(char *p);
00311
00319 const chain &operator+=(std::string &s);
00320
00321 #ifdef TODO
00322 const chain operator+(const chain &s) const;
00323 #endif
00324
00331 bool operator==(const chain &s) const;
00332
00339 bool operator!=(const chain &s) const;
00340
00349 void append(const chain &s);
00350
00363 void append(const char *p, unsigned int s = 0, bool free = false,
00364 char *allocatedbegin = NULL);
00365
00366 void append(std::string &s);
00367
00376 void appendcopy(chain &s);
00377
00387 void appendcopy(const char *p, unsigned int s = 0);
00388
00389 void appendcopy(std::string &s);
00390
00391 #ifdef DEPRECATED
00392
00401 chain *concatenate(int begin = 0, int end = -1) const;
00402 #endif
00403
00414 char *toArray(unsigned int begin = 0, unsigned int end = npos)
00415 const throw(Exception);
00416
00424 std::string toString(unsigned int begin = 0, unsigned int end = npos)
00425 const throw(Exception);
00426
00434 int toInt(unsigned int begin = 0) const throw(Exception);
00435
00448 chain substr(unsigned int begin, unsigned int end) const throw(Exception);
00449
00465 bool substrcopy(char *dest, unsigned int begin, unsigned int end) const
00466 throw(Exception);
00467
00478 chain duplicate(void);
00479
00488 unsigned int find(char c, unsigned int initial = 0) const;
00489
00490
00491 chain_iterator begin(void);
00492
00493 chain_iterator end(void);
00494
00495 void erase(chain_iterator it);
00496
00497 void debug(void) const;
00498
00499 friend std::ostream& operator<<(std::ostream &o, chain &p);
00500 };
00501
00502 extern std::ostream& operator<<(std::ostream &o, chain &p);
00503
00504 }
00505
00506
00507 #endif // _GLASS_CHAIN_HH_