00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _OBBY_TEXT_HPP_
00020 #define _OBBY_TEXT_HPP_
00021
00022 #include <string>
00023 #include <list>
00024 #include <net6/packet.hpp>
00025 #include "ptr_iterator.hpp"
00026 #include "user.hpp"
00027
00028 namespace obby
00029 {
00030
00049 class text
00050 {
00051 public:
00054 typedef std::string string_type;
00055
00058 typedef string_type::size_type size_type;
00059
00062 static const size_type npos = string_type::npos;
00063
00064 protected:
00067 class chunk
00068 {
00069 public:
00070 chunk(const chunk& other);
00071 chunk(const string_type& string,
00072 const user* author);
00073
00078 chunk(const net6::packet& pack,
00079 unsigned int& index,
00080 const user_table& table);
00081
00086 chunk(const serialise::object& obj,
00087 const user_table& table);
00088
00092 void serialise(serialise::object& obj) const;
00093
00096 void append_packet(net6::packet& pack) const;
00097
00100 void prepend(const string_type& text);
00101
00104 void append(const string_type& text);
00105
00108 void insert(size_type pos, const string_type& text);
00109
00112 void erase(size_type pos, size_type len = npos);
00113
00116 const string_type& get_text() const;
00117
00122 size_type get_length() const;
00123
00126 const user* get_author() const;
00127 protected:
00128 string_type m_text;
00129 const user* m_author;
00130 };
00131
00132 typedef std::list<chunk*> list_type;
00133
00134 public:
00135
00136
00137
00140 typedef ptr_iterator<
00141 const chunk,
00142 list_type,
00143 list_type::const_iterator
00144 > chunk_iterator;
00145
00146 text(size_type initial_chunk_size = npos);
00147 text(const text& other);
00148 text(const string_type& string,
00149 const user* author,
00150 size_type initial_chunk_size = npos);
00151
00154 text(const net6::packet& pack,
00155 unsigned int& index,
00156 const user_table& table);
00157
00160 text(const serialise::object& obj,
00161 const user_table& table);
00162 ~text();
00163
00164 text& operator=(const text& other);
00165
00168 void serialise(serialise::object& obj) const;
00169
00172 void append_packet(net6::packet& pack) const;
00173
00176 void clear();
00177
00180 text substr(size_type pos,
00181 size_type len = npos) const;
00182
00185 void insert(size_type pos,
00186 const string_type& str,
00187 const user* author);
00188
00191 void insert(size_type pos,
00192 const text& str);
00193
00196 void erase(size_type pos,
00197 size_type len = npos);
00198
00205 void append(const string_type& str,
00206 const user* author);
00207
00214 void append(const text& str);
00215
00218 void prepend(const string_type& str,
00219 const user* author);
00220
00223 void prepend(const text& str);
00224
00227 size_type length() const;
00228
00234 bool operator==(const text& other) const;
00235
00241 bool operator!=(const text& other) const;
00242
00245 bool operator<(const text& other) const;
00246
00249 bool operator>(const text& other) const;
00250
00253 bool operator<=(const text& other) const;
00254
00257 bool operator>=(const text& other) const;
00258
00261 bool operator==(const string_type& other) const;
00262
00265 bool operator!=(const string_type& other) const;
00266
00269 bool operator<(const string_type& other) const;
00270
00273 bool operator>(const string_type& other) const;
00274
00277 bool operator<=(const string_type& other) const;
00278
00281 bool operator>=(const string_type& other) const;
00282
00285 bool empty() const;
00286
00289 chunk_iterator chunk_begin() const;
00290
00293 chunk_iterator chunk_end() const;
00294
00300 void set_max_chunk_size(size_type max_chunk);
00301
00304 operator std::string() const;
00305
00306 protected:
00307 size_type m_max_chunk;
00308 list_type m_chunks;
00309
00310 private:
00317 list_type::iterator find_chunk(size_type& pos);
00318
00325 list_type::const_iterator find_chunk(size_type& pos) const;
00326
00337 list_type::iterator insert_chunk(list_type::iterator chunk_it,
00338 size_type& chunk_pos,
00339 const string_type& str,
00340 const user* author);
00341
00348 list_type::iterator erase_chunk(list_type::iterator chunk_it,
00349 size_type pos,
00350 size_type len);
00351
00354 enum compare_result {
00358 GREATER,
00359
00363 EQUAL_OWNERMATCH,
00364
00367 EQUAL,
00368
00372 LESS
00373 };
00374
00375 compare_result compare(const text& other) const;
00376 compare_result compare(const string_type& text) const;
00377 };
00378
00379 }
00380
00381 #endif // _OBBY_TEXT_HPP_