obby::text Class Reference

Obby text that stores which user wrote what. More...

#include <text.hpp>

List of all members.

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 ()
textoperator= (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...


Detailed Description

Obby text that stores which user wrote what.

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.


Member Typedef Documentation

typedef std::string obby::text::string_type

String type used in chunks.

Definition at line 54 of file text.hpp.

typedef string_type::size_type obby::text::size_type

Size type.

Definition at line 58 of file text.hpp.

typedef std::list<chunk*> obby::text::list_type [protected]

Definition at line 132 of file text.hpp.

typedef ptr_iterator< const chunk, list_type, list_type::const_iterator > obby::text::chunk_iterator

Iterator type to iterate over the chunks of a text.

Definition at line 144 of file text.hpp.


Member Enumeration Documentation

enum obby::text::compare_result [private]

Result of a compare() call.

Enumerator:
GREATER  This text is relationally greater than the compared one.
EQUAL_OWNERMATCH  Both texts are equal and all chunks are written by the same authers.
EQUAL  Both texts are equal, but chunk ownership differs.
LESS  This text is relationally less than the compared one.

Definition at line 354 of file text.hpp.


Constructor & Destructor Documentation

obby::text::text ( size_type  initial_chunk_size = npos  ) 

Definition at line 135 of file text.cpp.

obby::text::text ( const text other  ) 

Definition at line 140 of file text.cpp.

References m_chunks.

obby::text::text ( const string_type string,
const user author,
size_type  initial_chunk_size = npos 
)

Definition at line 151 of file text.cpp.

References m_chunks, and m_max_chunk.

obby::text::text ( const net6::packet &  pack,
unsigned int &  index,
const user_table table 
)

Reads a text from a net6::packet.

Definition at line 163 of file text.cpp.

References m_chunks.

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::~text (  ) 

Definition at line 195 of file text.cpp.

References clear().


Member Function Documentation

obby::text & obby::text::operator= ( const text other  ) 

Definition at line 200 of file text.cpp.

References clear(), m_chunks, and m_max_chunk.

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

Appends the text to a net6 packet.

Definition at line 229 of file text.cpp.

References m_chunks.

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().

void obby::text::insert ( size_type  pos,
const text str 
)

Inserts another text into this one.

Definition at line 310 of file text.cpp.

References find_chunk(), insert_chunk(), and m_chunks.

void obby::text::erase ( size_type  pos,
size_type  len = npos 
)

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  ) 

Appends another text to this 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 402 of file text.cpp.

References append(), and m_chunks.

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  ) 

Prepends another text to this text.

Definition at line 448 of file text.cpp.

References m_chunks, and prepend().

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

Relational operator, ignores chunk ownership.

Definition at line 482 of file text.cpp.

References compare(), and LESS.

bool obby::text::operator> ( const text other  )  const

Relational operator, ignores chunk ownership.

Definition at line 487 of file text.cpp.

References compare(), and GREATER.

bool obby::text::operator<= ( const text other  )  const

Relational operator, ignores chunk ownership.

Definition at line 492 of file text.cpp.

References compare(), and GREATER.

bool obby::text::operator>= ( const text other  )  const

Relational operator, ignores chunk ownership.

Definition at line 497 of file text.cpp.

References compare(), and LESS.

bool obby::text::operator== ( const string_type other  )  const

Checks whether this text's content matches other.

Definition at line 502 of file text.cpp.

References compare(), and EQUAL.

bool obby::text::operator!= ( const string_type other  )  const

Checks whether this text's content differs from other.

Definition at line 507 of file text.cpp.

References compare(), and EQUAL.

bool obby::text::operator< ( const string_type other  )  const

Relational operator.

Definition at line 512 of file text.cpp.

References compare(), and LESS.

bool obby::text::operator> ( const string_type other  )  const

Relational operator.

Definition at line 517 of file text.cpp.

References compare(), and GREATER.

bool obby::text::operator<= ( const string_type other  )  const

Relational operator.

Definition at line 522 of file text.cpp.

References compare(), and GREATER.

bool obby::text::operator>= ( const string_type other  )  const

Relational operator.

Definition at line 527 of file text.cpp.

References compare(), and LESS.

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]

Internal function to find the chunk at the given position in the chunk list.

pos is changed to point to the required position in the returned chunk.

Definition at line 649 of file text.cpp.

References m_chunks.

Referenced by erase(), insert(), and substr().

obby::text::list_type::const_iterator obby::text::find_chunk ( size_type pos  )  const [private]

Internal function to find the chunk at the given position in the chunk list.

pos is changed to point to the required position in the returned chunk.

Definition at line 658 of file text.cpp.

References m_chunks.

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]

Definition at line 974 of file text.cpp.

References EQUAL, GREATER, LESS, and m_chunks.


Member Data Documentation

const size_type obby::text::npos = string_type::npos [static]

Invalid position marker.

Definition at line 62 of file text.hpp.

Referenced by erase(), and substr().

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().


The documentation for this class was generated from the following files:
Generated on Fri Jan 11 10:01:33 2008 for obby by  doxygen 1.5.1