#include <text.hpp>
Public Types | |
| typedef std::string | string_type |
| String type used in chunks. | |
| typedef string_type::size_type | size_type |
| Size type. | |
| typedef ptr_iterator< const chunk, list_type, list_type::const_iterator > | chunk_iterator |
| Iterator type to iterate over the chunks of a text. | |
Public Member Functions | |
| text (size_type initial_chunk_size=npos) | |
| text (const text &other) | |
| text (const string_type &string, const user *author, size_type initial_chunk_size=npos) | |
| text (const net6::packet &pack, unsigned int &index, const user_table &table) | |
| Reads a text from a net6::packet. | |
| text (const serialise::object &obj, const user_table &table) | |
| Reads a text from a serialisation object. | |
| ~text () | |
| text & | operator= (const text &other) |
| void | serialise (serialise::object &obj) const |
| Writes the text to a serialisation object. | |
| void | append_packet (net6::packet &pack) const |
| Appends the text to a net6 packet. | |
| void | clear () |
| Removes any chunks in the text. | |
| text | substr (size_type pos, size_type len=npos) const |
| Extracts a subtext from this text. | |
| void | insert (size_type pos, const string_type &str, const user *author) |
| Inserts a string into the text. | |
| void | insert (size_type pos, const text &str) |
| Inserts another text into this one. | |
| void | erase (size_type pos, size_type len=npos) |
| Erases a substring from the text. | |
| void | append (const string_type &str, const user *author) |
| Appends a string to the text. | |
| void | append (const text &str) |
| Appends another text to this text. | |
| void | prepend (const string_type &str, const user *author) |
| Prepends a string to this text. | |
| void | prepend (const text &str) |
| Prepends another text to this text. | |
| size_type | length () const |
| Returns the length of this text, in bytes. | |
| bool | operator== (const text &other) const |
| Returns TRUE if the text's contents are equal to other's and if the same users wrote the same chunks. | |
| bool | operator!= (const text &other) const |
| Returns TRUE if the text's contents differ from other's or if a chunk has been written by another user. | |
| bool | operator< (const text &other) const |
| Relational operator, ignores chunk ownership. | |
| bool | operator> (const text &other) const |
| Relational operator, ignores chunk ownership. | |
| bool | operator<= (const text &other) const |
| Relational operator, ignores chunk ownership. | |
| bool | operator>= (const text &other) const |
| Relational operator, ignores chunk ownership. | |
| bool | operator== (const string_type &other) const |
| Checks whether this text's content matches other. | |
| bool | operator!= (const string_type &other) const |
| Checks whether this text's content differs from other. | |
| bool | operator< (const string_type &other) const |
| Relational operator. | |
| bool | operator> (const string_type &other) const |
| Relational operator. | |
| bool | operator<= (const string_type &other) const |
| Relational operator. | |
| bool | operator>= (const string_type &other) const |
| Relational operator. | |
| bool | empty () const |
| Returns TRUE if the text is empty e.g. has no chunks. | |
| chunk_iterator | chunk_begin () const |
| Returns the beginning of tho chunk list. | |
| chunk_iterator | chunk_end () const |
| Returns the end of tho chunk list. | |
| void | set_max_chunk_size (size_type max_chunk) |
| Changes the chunk size limitation. | |
| operator std::string () const | |
| Converts the text to a string, loosing chunk ownership. | |
Static Public Attributes | |
| static const size_type | npos = string_type::npos |
| Invalid position marker. | |
Protected Types | |
| typedef std::list< chunk * > | list_type |
Protected Attributes | |
| size_type | m_max_chunk |
| list_type | m_chunks |
Private Types | |
| enum | compare_result { GREATER, EQUAL_OWNERMATCH, EQUAL, LESS } |
| Result of a compare() call. More... | |
Private Member Functions | |
| list_type::iterator | find_chunk (size_type &pos) |
| Internal function to find the chunk at the given position in the chunk list. | |
| list_type::const_iterator | find_chunk (size_type &pos) const |
| Internal function to find the chunk at the given position in the chunk list. | |
| list_type::iterator | insert_chunk (list_type::iterator chunk_it, size_type &chunk_pos, const string_type &str, const user *author) |
| Inserts a chunk at the given position in the given chunk. | |
| list_type::iterator | erase_chunk (list_type::iterator chunk_it, size_type pos, size_type len) |
| Erases the given range from the given chunk. | |
| compare_result | compare (const text &other) const |
| compare_result | compare (const string_type &text) const |
Classes | |
| class | chunk |
| Single text chunk. More... | |
An obby text consists of a list of so-called chunks. A chunk is a part of the text that a specified user has written. It is possible to iterate through the chunks of the text to find out which user wrote what.
It is also possible to limit the maximum chunk size (in bytes) to speed up text manipulating in large text documents where a single user wrote a large part. However, chunk size limitation has currently not been tested and might be broken.
Normally, the class tries to merge chunks from the same author if the size limitation allows this. Such merging is performed when inserting or deleting text. It ensures that the text does not consist of hundreds of chunks but the algorithm is not optimal - meaning it does not find the solution which needs the least number of chunks in any case. This would require too much performance when text is inserted or deleted.
Definition at line 49 of file text.hpp.
| typedef std::string obby::text::string_type |
| typedef string_type::size_type obby::text::size_type |
typedef std::list<chunk*> obby::text::list_type [protected] |
| typedef ptr_iterator< const chunk, list_type, list_type::const_iterator > obby::text::chunk_iterator |
enum obby::text::compare_result [private] |
Result of a compare() call.
| obby::text::text | ( | const text & | other | ) |
| obby::text::text | ( | const string_type & | string, | |
| const user * | author, | |||
| size_type | initial_chunk_size = npos | |||
| ) |
| obby::text::text | ( | const net6::packet & | pack, | |
| unsigned int & | index, | |||
| const user_table & | table | |||
| ) |
| obby::text::text | ( | const serialise::object & | obj, | |
| const user_table & | table | |||
| ) |
Reads a text from a serialisation object.
Definition at line 173 of file text.cpp.
References obby::_(), obby::serialise::object::children_begin(), obby::serialise::object::children_end(), m_chunks, and obby::basic_format_string< string_type, stream_type >::str().
| obby::text & obby::text::operator= | ( | const text & | other | ) |
| void obby::text::serialise | ( | serialise::object & | obj | ) | const |
Writes the text to a serialisation object.
Definition at line 217 of file text.cpp.
References obby::serialise::object::add_child(), and m_chunks.
| void obby::text::append_packet | ( | net6::packet & | pack | ) | const |
| void obby::text::clear | ( | ) |
Removes any chunks in the text.
Definition at line 240 of file text.cpp.
References m_chunks.
Referenced by operator=(), and ~text().
| obby::text obby::text::substr | ( | size_type | pos, | |
| size_type | len = npos | |||
| ) | const |
Extracts a subtext from this text.
Definition at line 252 of file text.cpp.
References obby::text::chunk::append(), find_chunk(), obby::text::chunk::get_author(), obby::text::chunk::get_length(), obby::text::chunk::get_text(), m_chunks, m_max_chunk, and npos.
Referenced by obby::document::get_slice().
| void obby::text::insert | ( | size_type | pos, | |
| const string_type & | str, | |||
| const user * | author | |||
| ) |
Inserts a string into the text.
Definition at line 302 of file text.cpp.
References find_chunk(), and insert_chunk().
Referenced by obby::document::insert().
Inserts another text into this one.
Definition at line 310 of file text.cpp.
References find_chunk(), insert_chunk(), and m_chunks.
Erases a substring from the text.
Definition at line 327 of file text.cpp.
References erase_chunk(), find_chunk(), m_chunks, and npos.
Referenced by obby::document::erase().
| void obby::text::append | ( | const string_type & | str, | |
| const user * | author | |||
| ) |
Appends a string to the text.
This function should be used instead of insert if text is inserted at the end of the text because no lookup of the insertion point in the chunk list has to be performed.
Definition at line 374 of file text.cpp.
References obby::text::chunk::append(), obby::text::chunk::get_author(), obby::text::chunk::get_length(), m_chunks, and m_max_chunk.
Referenced by append(), and obby::document::append().
| void obby::text::append | ( | const text & | str | ) |
| void obby::text::prepend | ( | const string_type & | str, | |
| const user * | author | |||
| ) |
Prepends a string to this text.
Definition at line 413 of file text.cpp.
References obby::text::chunk::get_author(), obby::text::chunk::get_length(), m_chunks, m_max_chunk, and obby::text::chunk::prepend().
Referenced by prepend().
| void obby::text::prepend | ( | const text & | str | ) |
| obby::text::size_type obby::text::length | ( | ) | const |
Returns the length of this text, in bytes.
Definition at line 458 of file text.cpp.
References m_chunks.
Referenced by obby::document::size().
| bool obby::text::operator== | ( | const text & | other | ) | const |
Returns TRUE if the text's contents are equal to other's and if the same users wrote the same chunks.
Chunk size limitation between the texts may differ.
Definition at line 472 of file text.cpp.
References compare(), and EQUAL_OWNERMATCH.
| bool obby::text::operator!= | ( | const text & | other | ) | const |
Returns TRUE if the text's contents differ from other's or if a chunk has been written by another user.
Chunk size limitaion between the texts may differ.
Definition at line 477 of file text.cpp.
References compare(), and EQUAL_OWNERMATCH.
| bool obby::text::operator< | ( | const text & | other | ) | const |
| bool obby::text::operator> | ( | const text & | other | ) | const |
| bool obby::text::operator<= | ( | const text & | other | ) | const |
| bool obby::text::operator>= | ( | const text & | other | ) | const |
| bool obby::text::operator== | ( | const string_type & | other | ) | const |
| bool obby::text::operator!= | ( | const string_type & | other | ) | const |
| bool obby::text::operator< | ( | const string_type & | other | ) | const |
| bool obby::text::operator> | ( | const string_type & | other | ) | const |
| bool obby::text::operator<= | ( | const string_type & | other | ) | const |
| bool obby::text::operator>= | ( | const string_type & | other | ) | const |
| bool obby::text::empty | ( | ) | const |
Returns TRUE if the text is empty e.g. has no chunks.
Definition at line 532 of file text.cpp.
References m_chunks.
Referenced by obby::document::empty().
| obby::text::chunk_iterator obby::text::chunk_begin | ( | ) | const |
Returns the beginning of tho chunk list.
Definition at line 537 of file text.cpp.
References m_chunks.
Referenced by obby::document::chunk_begin().
| obby::text::chunk_iterator obby::text::chunk_end | ( | ) | const |
Returns the end of tho chunk list.
Definition at line 542 of file text.cpp.
References m_chunks.
Referenced by obby::document::chunk_end().
| void obby::text::set_max_chunk_size | ( | size_type | max_chunk | ) |
Changes the chunk size limitation.
If the limitation is decreased, chunks exceeding the new limitation are splitted up, if the limition in increased, chunks may be merged.
Definition at line 547 of file text.cpp.
References obby::text::chunk::get_author(), obby::text::chunk::get_length(), obby::text::chunk::get_text(), m_chunks, m_max_chunk, and obby::text::chunk::prepend().
| obby::text::operator std::string | ( | ) | const |
Converts the text to a string, loosing chunk ownership.
| obby::text::list_type::iterator obby::text::find_chunk | ( | size_type & | pos | ) | [private] |
| obby::text::list_type::const_iterator obby::text::find_chunk | ( | size_type & | pos | ) | const [private] |
| obby::text::list_type::iterator obby::text::insert_chunk | ( | list_type::iterator | chunk_it, | |
| size_type & | chunk_pos, | |||
| const string_type & | str, | |||
| const user * | author | |||
| ) | [private] |
Inserts a chunk at the given position in the given chunk.
The given chunk is splitten up to insert the new chunk, if necessary. Sometimes, the new text may be merged with surrounding chunks.
The function changen chunk_pos to point behind the insertion point in the returned iterater. This may or may not be a newly created chunk.
Definition at line 667 of file text.cpp.
References obby::text::chunk::append(), obby::text::chunk::erase(), obby::text::chunk::get_author(), obby::text::chunk::get_length(), obby::text::chunk::get_text(), obby::text::chunk::insert(), m_chunks, m_max_chunk, and obby::text::chunk::prepend().
Referenced by insert().
| obby::text::list_type::iterator obby::text::erase_chunk | ( | list_type::iterator | chunk_it, | |
| size_type | pos, | |||
| size_type | len | |||
| ) | [private] |
Erases the given range from the given chunk.
If the beginning and/or end is erased the function tries to merge the chunk with surrounding chunks. It returns the chunk after the chunk where text has been erased from.
Definition at line 804 of file text.cpp.
References obby::text::chunk::append(), obby::text::chunk::erase(), obby::text::chunk::get_author(), obby::text::chunk::get_length(), obby::text::chunk::get_text(), m_chunks, m_max_chunk, and obby::text::chunk::prepend().
Referenced by erase().
| obby::text::compare_result obby::text::compare | ( | const text & | other | ) | const [private] |
Definition at line 923 of file text.cpp.
References EQUAL, EQUAL_OWNERMATCH, GREATER, LESS, and m_chunks.
Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().
| obby::text::compare_result obby::text::compare | ( | const string_type & | text | ) | const [private] |
const size_type obby::text::npos = string_type::npos [static] |
size_type obby::text::m_max_chunk [protected] |
Definition at line 307 of file text.hpp.
Referenced by append(), erase_chunk(), insert_chunk(), operator=(), prepend(), set_max_chunk_size(), substr(), and text().
list_type obby::text::m_chunks [protected] |
Definition at line 308 of file text.hpp.
Referenced by append(), append_packet(), chunk_begin(), chunk_end(), clear(), compare(), empty(), erase(), erase_chunk(), find_chunk(), insert(), insert_chunk(), length(), operator=(), prepend(), serialise(), set_max_chunk_size(), substr(), and text().
1.5.1