Ceylan::TextBuffer Class Reference

Stores a sequence of texts, and allows to access the overall text according to various ways, either text-by-text or line-by-line. More...

#include <CeylanTextBuffer.h>

Inheritance diagram for Ceylan::TextBuffer:

Inheritance graph
[legend]
Collaboration diagram for Ceylan::TextBuffer:

Collaboration graph
[legend]

List of all members.

Classes

class  TextBufferException
 Exception raised by text buffers. More...

Public Types

enum  TextLayout { Raw, WordWrapped, Justified }
 Describes the various modes supported for text layout. More...
typedef Ceylan::Uint8 CharAbscissa
 Abscissa index of a character in a buffer.
typedef Ceylan::Uint8 CharOrdinate
 Ordinate index of a character in a buffer.
typedef Ceylan::Uint32 TextIndex
 Index of a text in buffer list.
typedef Ceylan::Uint32 LineIndex
 Index of a preformatted line in a text.
typedef std::list< char * > TextGrid
 Records a preformatted text entry, whose escape sequences (,
) have been translated into a series of basic characters (alphanumerical and spaces) stored in a list of lines, each line being an array of width characters (char *), to fit in character grid.

Public Member Functions

 TextBuffer (CharAbscissa screenWidth, CharOrdinate screenHeight, TextLayout layout=Raw)
 Creates a new text buffer, whose sliding window (abstracted screen) is of specified size.
virtual ~TextBuffer () throw ()
 Virtual destructor.
virtual CharAbscissa getWidth () const
 Returns the width of the abstract screen associated to this buffer.
virtual CharOrdinate getHeight () const
 Returns the height of the abstract screen associated to this buffer.
virtual TextLayout getTextLayout () const
 Returns the text layout being currently used.
virtual void setTextLayout (TextLayout newLayout)
 Sets a new text layout.
virtual CharAbscissa getAlineaWidth () const
 Returns the current alinea width, in characters.
virtual void setAlineaWidth (CharAbscissa newAlineaWidth)
 Sets a new alinea width, in character.
virtual void add (const std::string &text)
 Adds specified text in the buffer.
virtual void blank ()
 Blanks this whole buffer.
virtual bool jumpNextText ()
 Centers the abstract screen on next text entry, if any.
virtual bool jumpPreviousText ()
 Centers the abstract screen on previous text, if any.
virtual bool jumpNextLine ()
 Makes the abstract screen go one line down.
virtual void jumpNextLineNoRefresh ()
 Makes the abstract screen go one line down, but does not refresh the screen lines.
virtual bool jumpPreviousLine ()
 Makes the abstract screen go one line up.
virtual const TextGridgetScreenLines () const
 Returns the list of lines that should be displayed, should this buffer be rendered.
virtual const std::string toString (Ceylan::VerbosityLevels level=Ceylan::high) const
 Returns an user-friendly description of the state of this object.

Static Public Member Functions

static const std::string ToString (std::list< TextDisplayable * > displayables, Ceylan::VerbosityLevels level=Ceylan::high)
 Returns a user-friendly description of this list of pointers to text displayable instances.
static TextOutputFormat GetOutputFormat ()
 Returns the current overall text format to be used by TextDisplayable instances.
static void SetOutputFormat (TextOutputFormat newOutputFormat)
 Sets the current overall text format to be used by TextDisplayable instances.

Static Public Attributes

static const CharAbscissa TabSpacing = 4
 Number of spaces corresponding to one tabulation.

Protected Types

typedef std::pair< std::string,
TextGrid * > 
TextEntry
 A text entry is made of a chunk of text and its precomputed lines (if any).
typedef std::list< TextEntryListOfTexts
 A list of text entries.

Protected Member Functions

virtual void recomputeGrids ()
 Recomputes cached grid lines with current settings.
void updateScreenLines ()
 Updates screen lines according to current buffer text and line index.
TextGridcreateTextGridFrom (const std::string &text)
 Translates specified text entry into a list of lines of buffer width, according to current screen dimensions and layout.
void deleteTextGrid (TextGrid *grid)
 Deletes a TextGrid.
TextGridcreateRawGridFrom (const std::string &text)
 Translates specified text entry into a list of lines of buffer width, with no special concern for layout: text written letter by letter.
TextGridcreateAdvancedGridFrom (const std::string &text)
 Translates specified text entry into a list of lines of buffer width, with word-wrapped or justified (i.e.
LineIndex getHeightFromCurrentPosition () const
 Tells how many lines spread from the current position to the end of text.
LineIndex getHeightFromEntry (ListOfTexts::const_iterator textIterator) const
 Tells how many lines spread from the beggining of specified text entry to the end of text.
char * getNewLine ()
 Creates a new blank line of the appropriate width (length).

Protected Attributes

ListOfTexts _textEntries
 Records the text stored by this buffer and its precomputed lines.
CharAbscissa _width
 The width of the character grid.
CharOrdinate _height
 The ordinate of the character grid.
TextLayout _layout
 Records the current text layout being used.
CharAbscissa _alineaWidth
 The width, in characters, of a paragraph alinea.
ListOfTexts::const_iterator _currentText
 The index of the text entry being rendered.
TextGrid::const_iterator _currentLine
 Index of a preformatted line in current rendered text grid.
TextGrid _screenLines
 The current screen, seen as a list of (at most _height) lines.

Static Protected Attributes

static TextOutputFormat _OutputFormat = rawText
 The text format to be used currently by TextDisplayable instances.

Private Member Functions

 TextBuffer (const TextBuffer &source)
 Copy constructor made private to ensure that it will be never called.
TextBufferoperator= (const TextBuffer &source)
 Assignment operator made private to ensure that it will be never called.


Detailed Description

Stores a sequence of texts, and allows to access the overall text according to various ways, either text-by-text or line-by-line.

Computes the corresponding character layout for onscreen rendering, depending on the specified abstract screen dimensions (expressed in characters, not in pixels, as character look-up and rendering are uncoupled here).

The abstract screen is a kind of grid of characters, of user-specified size, that can slide over parts of the stored text.

This helps for example fixed-font text rendering.

Definition at line 60 of file CeylanTextBuffer.h.


Member Typedef Documentation

Abscissa index of a character in a buffer.

Definition at line 122 of file CeylanTextBuffer.h.

Ordinate index of a character in a buffer.

Definition at line 126 of file CeylanTextBuffer.h.

Index of a preformatted line in a text.

Definition at line 135 of file CeylanTextBuffer.h.

typedef std::list<TextEntry> Ceylan::TextBuffer::ListOfTexts [protected]

A list of text entries.

Definition at line 462 of file CeylanTextBuffer.h.

typedef std::pair<std::string, TextGrid*> Ceylan::TextBuffer::TextEntry [protected]

A text entry is made of a chunk of text and its precomputed lines (if any).

Definition at line 448 of file CeylanTextBuffer.h.

typedef std::list<char *> Ceylan::TextBuffer::TextGrid

Records a preformatted text entry, whose escape sequences (,
) have been translated into a series of basic characters (alphanumerical and spaces) stored in a list of lines, each line being an array of width characters (char *), to fit in character grid.

Definition at line 323 of file CeylanTextBuffer.h.

Index of a text in buffer list.

Definition at line 131 of file CeylanTextBuffer.h.


Member Enumeration Documentation

Describes the various modes supported for text layout.

Enumerator:
Raw  Letters displayed on after the other with no regards for words.
WordWrapped  Words are wrapped (not cut), but text is not justified.
Justified  Words are wrapped (not cut), and text is justified.

Definition at line 95 of file CeylanTextBuffer.h.

Defines what text output formats for TextDisplayable instances are available.

Enumerator:
rawText 
html 

Definition at line 124 of file CeylanTextDisplayable.h.


Constructor & Destructor Documentation

TextBuffer::TextBuffer ( CharAbscissa  screenWidth,
CharOrdinate  screenHeight,
TextLayout  layout = Raw 
)

Creates a new text buffer, whose sliding window (abstracted screen) is of specified size.

Parameters:
width the width of the character grid.
height the width of the character grid.
layout the desired text layout for this buffer.
See also:
TextLayout
By default, an alinea is 2-character wide.

See also:
setAlineaWidth
Exceptions:
StringUtilsException if the operation failed.

Definition at line 64 of file CeylanTextBuffer.cc.

References _currentText, and _textEntries.

TextBuffer::~TextBuffer (  )  throw () [virtual]

Virtual destructor.

Definition at line 79 of file CeylanTextBuffer.cc.

References blank().

Ceylan::TextBuffer::TextBuffer ( const TextBuffer source  )  [private]

Copy constructor made private to ensure that it will be never called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.


Member Function Documentation

void TextBuffer::add ( const std::string &  text  )  [virtual]

Adds specified text in the buffer.

Updates the internal virtual screen accordingly.

Parameters:
text the text to add in buffer.
Exceptions:
TextBufferException if the operation failed.

Definition at line 150 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _textEntries, createTextGridFrom(), jumpNextLineNoRefresh(), and updateScreenLines().

Referenced by Ceylan::System::Console::addInBuffer().

void TextBuffer::blank (  )  [virtual]

Blanks this whole buffer.

Removes all text content.

Definition at line 183 of file CeylanTextBuffer.cc.

References _textEntries, and deleteTextGrid().

Referenced by Ceylan::System::Console::blankBuffer(), and ~TextBuffer().

TextBuffer::TextGrid & TextBuffer::createAdvancedGridFrom ( const std::string &  text  )  [protected]

Translates specified text entry into a list of lines of buffer width, with word-wrapped or justified (i.e.

word-wrapped with adapted spaces) lines, depending on current layout.

Note:
Ownership of the text grid is transferred to the caller.

Adapted from OSDL: in OSDL/trunk/src/code/video/twoDimensional/OSDLFont.cc, see OSDL::Video::Surface & Font::renderLatin1MultiLineText

Definition at line 670 of file CeylanTextBuffer.cc.

References _alineaWidth, _layout, _width, generalUtils::false, getNewLine(), Justified, Ceylan::splitIntoParagraphs(), Ceylan::splitIntoWords(), and generalUtils::true.

Referenced by createTextGridFrom().

TextBuffer::TextGrid & TextBuffer::createRawGridFrom ( const std::string &  text  )  [protected]

Translates specified text entry into a list of lines of buffer width, with no special concern for layout: text written letter by letter.

Note:
Ownership of the text grid is transferred to the caller.

Definition at line 603 of file CeylanTextBuffer.cc.

References _width, getNewLine(), and TabSpacing.

Referenced by createTextGridFrom().

TextBuffer::TextGrid & TextBuffer::createTextGridFrom ( const std::string &  text  )  [protected]

Translates specified text entry into a list of lines of buffer width, according to current screen dimensions and layout.

Note:
Ownership of the text grid is transferred to the caller.
See also:
deleteTextGrid

Definition at line 570 of file CeylanTextBuffer.cc.

References _layout, createAdvancedGridFrom(), createRawGridFrom(), Justified, Raw, and WordWrapped.

Referenced by add(), and recomputeGrids().

void TextBuffer::deleteTextGrid ( TextGrid grid  )  [protected]

Deletes a TextGrid.

Definition at line 1013 of file CeylanTextBuffer.cc.

Referenced by blank(), and recomputeGrids().

TextBuffer::CharAbscissa TextBuffer::getAlineaWidth (  )  const [virtual]

Returns the current alinea width, in characters.

Definition at line 132 of file CeylanTextBuffer.cc.

References _alineaWidth.

TextBuffer::CharOrdinate TextBuffer::getHeight (  )  const [virtual]

Returns the height of the abstract screen associated to this buffer.

Definition at line 98 of file CeylanTextBuffer.cc.

References _height.

TextBuffer::LineIndex TextBuffer::getHeightFromCurrentPosition (  )  const [protected]

Tells how many lines spread from the current position to the end of text.

Definition at line 944 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, and _textEntries.

Referenced by jumpNextLine(), and jumpNextLineNoRefresh().

TextBuffer::LineIndex TextBuffer::getHeightFromEntry ( ListOfTexts::const_iterator  textIterator  )  const [protected]

Tells how many lines spread from the beggining of specified text entry to the end of text.

Definition at line 979 of file CeylanTextBuffer.cc.

References _textEntries.

char * TextBuffer::getNewLine (  )  [protected]

Creates a new blank line of the appropriate width (length).

Note:
Ownership of the line is transferred to the caller.

Definition at line 1000 of file CeylanTextBuffer.cc.

References _width.

Referenced by createAdvancedGridFrom(), and createRawGridFrom().

TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat (  )  [static, inherited]

const TextBuffer::TextGrid & TextBuffer::getScreenLines (  )  const [virtual]

Returns the list of lines that should be displayed, should this buffer be rendered.

Depends on the stored texts and on the location of the abstract screen.

The width of each line is the one of this buffer (char[_width]). The screen list has between [0.._height] lines, missing ones mean they are blank.

Definition at line 405 of file CeylanTextBuffer.cc.

References _screenLines.

Referenced by Ceylan::System::Console::render().

TextBuffer::TextLayout TextBuffer::getTextLayout (  )  const [virtual]

Returns the text layout being currently used.

Definition at line 107 of file CeylanTextBuffer.cc.

References _layout.

Referenced by Ceylan::System::Console::getTextLayout().

TextBuffer::CharAbscissa TextBuffer::getWidth (  )  const [virtual]

Returns the width of the abstract screen associated to this buffer.

Definition at line 89 of file CeylanTextBuffer.cc.

References _width.

Referenced by Ceylan::System::Console::render().

bool TextBuffer::jumpNextLine (  )  [virtual]

Makes the abstract screen go one line down.

Does nothing if there is no text line left (already at bottom).

Returns:
true iff there was a line left indeed.

Definition at line 254 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _height, _textEntries, generalUtils::false, getHeightFromCurrentPosition(), generalUtils::true, and updateScreenLines().

Referenced by Ceylan::System::Console::jumpNextLine().

void TextBuffer::jumpNextLineNoRefresh (  )  [virtual]

Makes the abstract screen go one line down, but does not refresh the screen lines.

Note:
Useful if a series of jumpNextLine calls has to be made with only a final refresh, instead of many useless intermediate refreshs.
Does nothing if there is no text line left (already at bottom).

Returns:
true iff there was a line left indeed.

Definition at line 309 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _height, _textEntries, and getHeightFromCurrentPosition().

Referenced by add().

bool TextBuffer::jumpNextText (  )  [virtual]

Centers the abstract screen on next text entry, if any.

Does nothing if there is no text left.

Returns:
true iff there was a text entry left indeed.

Definition at line 203 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _textEntries, generalUtils::false, generalUtils::true, and updateScreenLines().

Referenced by Ceylan::System::Console::jumpNextText().

bool TextBuffer::jumpPreviousLine (  )  [virtual]

Makes the abstract screen go one line up.

Does nothing if there is no text line left (already on top).

Returns:
true iff there was a line left indeed.

Definition at line 339 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _height, _screenLines, _textEntries, generalUtils::false, and generalUtils::true.

Referenced by Ceylan::System::Console::jumpPreviousLine().

bool TextBuffer::jumpPreviousText (  )  [virtual]

Centers the abstract screen on previous text, if any.

Does nothing if there is no text left.

Returns:
true iff there was a prior text entry indeed.

Definition at line 230 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _textEntries, generalUtils::false, generalUtils::true, and updateScreenLines().

Referenced by Ceylan::System::Console::jumpPreviousText().

TextBuffer& Ceylan::TextBuffer::operator= ( const TextBuffer source  )  [private]

Assignment operator made private to ensure that it will be never called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

void TextBuffer::recomputeGrids (  )  [protected, virtual]

Recomputes cached grid lines with current settings.

Any previous ones are removed first.

Note:
The current line of text will be reset to the first line of the current text, as any change in dimension or layout will invalidate line content.

Definition at line 490 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _textEntries, createTextGridFrom(), deleteTextGrid(), and updateScreenLines().

Referenced by setTextLayout().

void TextBuffer::setAlineaWidth ( CharAbscissa  newAlineaWidth  )  [virtual]

Sets a new alinea width, in character.

Parameters:
newAlineaWidth the new alinea width, in character. It can be null for no alinea at all.

Definition at line 141 of file CeylanTextBuffer.cc.

References _alineaWidth.

void TextDisplayable::SetOutputFormat ( TextOutputFormat  newOutputFormat  )  [static, inherited]

Sets the current overall text format to be used by TextDisplayable instances.

Parameters:
newOutputFormat the new output format.

Definition at line 72 of file CeylanTextDisplayable.cc.

References Ceylan::TextDisplayable::_OutputFormat.

Referenced by Ceylan::Log::LogHolder::LogHolder().

void TextBuffer::setTextLayout ( TextLayout  newLayout  )  [virtual]

Sets a new text layout.

Triggers an update of the preformatted text.

Parameters:
newLayout the new layout to be used from now on.
Exceptions:
TextBufferException if the operation failed.

Definition at line 116 of file CeylanTextBuffer.cc.

References _layout, and recomputeGrids().

Referenced by Ceylan::System::Console::setTextLayout().

const std::string TextDisplayable::ToString ( std::list< TextDisplayable * >  displayables,
Ceylan::VerbosityLevels  level = Ceylan::high 
) [static, inherited]

Returns a user-friendly description of this list of pointers to text displayable instances.

Parameters:
displayables a list of pointers to TextDisplayable instances/
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
toString, Ceylan::VerbosityLevels

Definition at line 45 of file CeylanTextDisplayable.cc.

References Ceylan::formatStringList().

const std::string TextBuffer::toString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  const [virtual]

Returns an user-friendly description of the state of this object.

Parameters:
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
TextDisplayable

Implements Ceylan::TextDisplayable.

Definition at line 414 of file CeylanTextBuffer.cc.

References _height, _layout, _screenLines, _textEntries, _width, Ceylan::formatStringList(), Ceylan::high, Justified, Raw, Ceylan::toNumericalString(), and WordWrapped.

Referenced by Ceylan::System::Console::toString().

void TextBuffer::updateScreenLines (  )  [protected]

Updates screen lines according to current buffer text and line index.

Recreates from scratch the list of line references.

Definition at line 515 of file CeylanTextBuffer.cc.

References _currentLine, _currentText, _height, _screenLines, _textEntries, generalUtils::false, and generalUtils::true.

Referenced by add(), jumpNextLine(), jumpNextText(), jumpPreviousText(), and recomputeGrids().


Member Data Documentation

The width, in characters, of a paragraph alinea.

Definition at line 521 of file CeylanTextBuffer.h.

Referenced by createAdvancedGridFrom(), getAlineaWidth(), and setAlineaWidth().

TextGrid::const_iterator Ceylan::TextBuffer::_currentLine [protected]

Index of a preformatted line in current rendered text grid.

Definition at line 538 of file CeylanTextBuffer.h.

Referenced by add(), getHeightFromCurrentPosition(), jumpNextLine(), jumpNextLineNoRefresh(), jumpNextText(), jumpPreviousLine(), jumpPreviousText(), recomputeGrids(), and updateScreenLines().

ListOfTexts::const_iterator Ceylan::TextBuffer::_currentText [protected]

The ordinate of the character grid.

Definition at line 512 of file CeylanTextBuffer.h.

Referenced by getHeight(), jumpNextLine(), jumpNextLineNoRefresh(), jumpPreviousLine(), toString(), and updateScreenLines().

Records the current text layout being used.

Definition at line 517 of file CeylanTextBuffer.h.

Referenced by createAdvancedGridFrom(), createTextGridFrom(), getTextLayout(), setTextLayout(), and toString().

TextDisplayable::TextOutputFormat TextDisplayable::_OutputFormat = rawText [static, protected, inherited]

The text format to be used currently by TextDisplayable instances.

Note:
Defaults to raw text.

Definition at line 158 of file CeylanTextDisplayable.h.

Referenced by Ceylan::TextDisplayable::GetOutputFormat(), and Ceylan::TextDisplayable::SetOutputFormat().

The current screen, seen as a list of (at most _height) lines.

Definition at line 542 of file CeylanTextBuffer.h.

Referenced by getScreenLines(), jumpPreviousLine(), toString(), and updateScreenLines().

The width of the character grid.

Definition at line 508 of file CeylanTextBuffer.h.

Referenced by createAdvancedGridFrom(), createRawGridFrom(), getNewLine(), getWidth(), and toString().

Number of spaces corresponding to one tabulation.

Definition at line 361 of file CeylanTextBuffer.h.

Referenced by createRawGridFrom().


The documentation for this class was generated from the following files:

Generated on Thu Jun 4 20:40:09 2009 for Ceylan by  doxygen 1.5.8