NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
StyledTextFile Class Reference

This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded file and detect simple comment blocks. It defaults to NumeRe code files, however the comment character sequences can be adapted using the reStyle() method. More...

#include <styledtextfile.hpp>

Collaboration diagram for StyledTextFile:

Public Types

enum  Style {
  STYLE_ERROR = -1 , DEFAULT = 0 , COMMENT_LINE , COMMENT_DOC_LINE ,
  BLOCK_START , STRING , COMMENT_BLOCK , COMMENT_DOC_BLOCK
}
 

Public Member Functions

 StyledTextFile (const std::string &fileName)
 StyledTextFile constructor. Will load and lex the specified file using NumeRe code. More...
 
std::string getFileName () const
 Returns the filename of the respresented file in memory. More...
 
std::string getTextRange (int pos1, int pos2) const
 This method returns the text between the passed two positions (including possible line termination characters). More...
 
std::string getLine (size_t line) const
 Returns the selected line (without the line termination characters). More...
 
std::string getStrippedLine (size_t line) const
 Returns the selected line (without the line termination characters and without any comments). More...
 
int getLastPosition () const
 Returns the last printable character position in the currently loaded file. More...
 
int getLinesCount () const
 Returns the number of lines in the current loaded file. More...
 
int PositionFromLine (size_t line) const
 Returns the position of the first character in the selected line. More...
 
int LineFromPosition (size_t pos) const
 Returns the line number containing the selected character position. More...
 
int getLineEndPosition (size_t line) const
 Returns the position of the last printable character in the selected line (before any line termination characters). More...
 
int getLineStartPosition (size_t line) const
 Returns the position of the first character in the selected line. More...
 
int findDocStartLine (size_t line) const
 Finds the first line of the current documentation comment or -1, if the current line does not contain any documentation comment. More...
 
Style getStyleAt (size_t pos) const
 Returns the style at the current selected character position. More...
 
char getCharAt (size_t pos) const
 Returns the character located at the position pos. More...
 
void reStyle (const std::string &sComLine, const std::string &sDocComLine, const std::string &sComBlockStart, const std::string &sDocComBlockStart, const std::string &sComBlockEnd, const std::string &sStrMarks="", bool strings=true)
 Can be used to change the code style detection sequences and to re-apply the lexer to the currently loaded file. More...
 

Private Member Functions

void load ()
 This method loads the specified file to memory, while keeping the character positions. More...
 
void lex ()
 This method runs a lexer over the loaded document to obtain styling information. More...
 

Private Attributes

std::vector< std::pair< size_t, std::string > > vFileContents
 
std::vector< std::vector< Style > > vStyles
 
std::string sFileName
 
std::string sCommentLine
 
std::string sDocCommentLine
 
std::string sCommentBlockStart
 
std::string sDocCommentBlockStart
 
std::string sBlockEnd
 
std::string sStringMarks
 
bool useStrings
 

Detailed Description

This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded file and detect simple comment blocks. It defaults to NumeRe code files, however the comment character sequences can be adapted using the reStyle() method.

The interface resembles the wxStyledTextCtrl interface for simplified portability.

Definition at line 40 of file styledtextfile.hpp.

Member Enumeration Documentation

◆ Style

Enumerator
STYLE_ERROR 
DEFAULT 
COMMENT_LINE 
COMMENT_DOC_LINE 
BLOCK_START 
STRING 
COMMENT_BLOCK 
COMMENT_DOC_BLOCK 

Definition at line 43 of file styledtextfile.hpp.

Constructor & Destructor Documentation

◆ StyledTextFile()

StyledTextFile::StyledTextFile ( const std::string &  fileName)

StyledTextFile constructor. Will load and lex the specified file using NumeRe code.

Parameters
fileNameconst std::string&

Definition at line 174 of file styledtextfile.cpp.

References lex(), load(), sBlockEnd, sCommentBlockStart, sCommentLine, sDocCommentBlockStart, sDocCommentLine, sStringMarks, and useStrings.

Here is the call graph for this function:

Member Function Documentation

◆ findDocStartLine()

int StyledTextFile::findDocStartLine ( size_t  line) const

Finds the first line of the current documentation comment or -1, if the current line does not contain any documentation comment.

Parameters
linesize_t
Returns
int

Definition at line 394 of file styledtextfile.cpp.

References COMMENT_DOC_BLOCK, COMMENT_DOC_LINE, getCharAt(), getStyleAt(), LineFromPosition(), and vFileContents.

Here is the call graph for this function:

◆ getCharAt()

char StyledTextFile::getCharAt ( size_t  pos) const

Returns the character located at the position pos.

Parameters
possize_t
Returns
char

Definition at line 447 of file styledtextfile.cpp.

References LineFromPosition(), and vFileContents.

Referenced by findDocStartLine().

Here is the call graph for this function:

◆ getFileName()

std::string StyledTextFile::getFileName ( ) const

Returns the filename of the respresented file in memory.

Returns
std::string

Definition at line 196 of file styledtextfile.cpp.

References sFileName.

Referenced by Includer::getIncludedFileName(), DocumentationGenerator::parseDocumentation(), and resolveIncludes().

◆ getLastPosition()

int StyledTextFile::getLastPosition ( ) const

Returns the last printable character position in the currently loaded file.

Returns
int

Definition at line 296 of file styledtextfile.cpp.

References getLinesCount(), and vFileContents.

Referenced by DocumentationGenerator::convertToLaTeX(), and Includer::openIncludedFile().

Here is the call graph for this function:

◆ getLine()

std::string StyledTextFile::getLine ( size_t  line) const

Returns the selected line (without the line termination characters).

Parameters
linesize_t
Returns
std::string

Definition at line 252 of file styledtextfile.cpp.

References vFileContents.

Referenced by readFromFile().

◆ getLineEndPosition()

int StyledTextFile::getLineEndPosition ( size_t  line) const

Returns the position of the last printable character in the selected line (before any line termination characters).

Parameters
linesize_t
Returns
int

Definition at line 358 of file styledtextfile.cpp.

References vFileContents.

Referenced by DocumentationGenerator::convertToLaTeX().

◆ getLinesCount()

int StyledTextFile::getLinesCount ( ) const

Returns the number of lines in the current loaded file.

Returns
int

Definition at line 309 of file styledtextfile.cpp.

References vFileContents.

Referenced by getEventProcedures(), ProcedureLibrary::getFileContents(), getLastPosition(), Includer::getNextLine(), parseLayoutScript(), ProcedureElement::ProcedureElement(), readFromFile(), and resolveIncludes().

◆ getLineStartPosition()

int StyledTextFile::getLineStartPosition ( size_t  line) const

Returns the position of the first character in the selected line.

Parameters
linesize_t
Returns
int

Definition at line 375 of file styledtextfile.cpp.

References vFileContents.

Referenced by getStyleAt(), and PositionFromLine().

◆ getStrippedLine()

std::string StyledTextFile::getStrippedLine ( size_t  line) const

Returns the selected line (without the line termination characters and without any comments).

Parameters
linesize_t
Returns
std::string

Definition at line 270 of file styledtextfile.cpp.

References DEFAULT, STRING, vFileContents, and vStyles.

Referenced by getEventProcedures(), Includer::getNextLine(), parseLayoutScript(), ProcedureElement::ProcedureElement(), readFromFile(), and resolveIncludes().

◆ getStyleAt()

StyledTextFile::Style StyledTextFile::getStyleAt ( size_t  pos) const

Returns the style at the current selected character position.

Parameters
possize_t
Returns
StyledTextFile::Style

Definition at line 428 of file styledtextfile.cpp.

References getLineStartPosition(), LineFromPosition(), STYLE_ERROR, and vStyles.

Referenced by DocumentationGenerator::convertToLaTeX(), and findDocStartLine().

Here is the call graph for this function:

◆ getTextRange()

std::string StyledTextFile::getTextRange ( int  pos1,
int  pos2 
) const

This method returns the text between the passed two positions (including possible line termination characters).

Parameters
pos1int
pos2int
Returns
std::string

Definition at line 212 of file styledtextfile.cpp.

References LineFromPosition(), and vFileContents.

Referenced by DocumentationGenerator::convertToLaTeX(), and DocumentationGenerator::getStrippedRange().

Here is the call graph for this function:

◆ lex()

void StyledTextFile::lex ( )
private

This method runs a lexer over the loaded document to obtain styling information.

Returns
void

Definition at line 64 of file styledtextfile.cpp.

References BLOCK_START, COMMENT_BLOCK, COMMENT_DOC_BLOCK, COMMENT_DOC_LINE, COMMENT_LINE, DEFAULT, sBlockEnd, sCommentBlockStart, sCommentLine, sDocCommentBlockStart, sDocCommentLine, sStringMarks, STRING, useStrings, vFileContents, and vStyles.

Referenced by reStyle(), and StyledTextFile().

◆ LineFromPosition()

int StyledTextFile::LineFromPosition ( size_t  pos) const

Returns the line number containing the selected character position.

Parameters
possize_t
Returns
int

Definition at line 337 of file styledtextfile.cpp.

References vFileContents.

Referenced by DocumentationGenerator::convertToLaTeX(), findDocStartLine(), getCharAt(), getStyleAt(), and getTextRange().

◆ load()

void StyledTextFile::load ( )
private

This method loads the specified file to memory, while keeping the character positions.

Returns
void

Definition at line 32 of file styledtextfile.cpp.

References sFileName, and vFileContents.

Referenced by StyledTextFile().

◆ PositionFromLine()

int StyledTextFile::PositionFromLine ( size_t  line) const

Returns the position of the first character in the selected line.

Parameters
linesize_t
Returns
int

Definition at line 323 of file styledtextfile.cpp.

References getLineStartPosition().

Referenced by DocumentationGenerator::convertToLaTeX().

Here is the call graph for this function:

◆ reStyle()

void StyledTextFile::reStyle ( const std::string &  sComLine,
const std::string &  sDocComLine,
const std::string &  sComBlockStart,
const std::string &  sDocComBlockStart,
const std::string &  sComBlockEnd,
const std::string &  sStrMarks = "",
bool  strings = true 
)

Can be used to change the code style detection sequences and to re-apply the lexer to the currently loaded file.

Parameters
sComLineconst std::string&
sDocComLineconst std::string&
sComBlockStartconst std::string&
sDocComBlockStartconst std::string&
sComBlockEndconst std::string&
sStrMarksconst std::string&
stringsbool
Returns
void

Definition at line 473 of file styledtextfile.cpp.

References lex(), sBlockEnd, sCommentBlockStart, sCommentLine, sDocCommentBlockStart, sDocCommentLine, sStringMarks, and useStrings.

Referenced by readFromFile().

Here is the call graph for this function:

Member Data Documentation

◆ sBlockEnd

std::string StyledTextFile::sBlockEnd
private

Definition at line 65 of file styledtextfile.hpp.

Referenced by lex(), reStyle(), and StyledTextFile().

◆ sCommentBlockStart

std::string StyledTextFile::sCommentBlockStart
private

Definition at line 63 of file styledtextfile.hpp.

Referenced by lex(), reStyle(), and StyledTextFile().

◆ sCommentLine

std::string StyledTextFile::sCommentLine
private

Definition at line 61 of file styledtextfile.hpp.

Referenced by lex(), reStyle(), and StyledTextFile().

◆ sDocCommentBlockStart

std::string StyledTextFile::sDocCommentBlockStart
private

Definition at line 64 of file styledtextfile.hpp.

Referenced by lex(), reStyle(), and StyledTextFile().

◆ sDocCommentLine

std::string StyledTextFile::sDocCommentLine
private

Definition at line 62 of file styledtextfile.hpp.

Referenced by lex(), reStyle(), and StyledTextFile().

◆ sFileName

std::string StyledTextFile::sFileName
private

Definition at line 59 of file styledtextfile.hpp.

Referenced by getFileName(), and load().

◆ sStringMarks

std::string StyledTextFile::sStringMarks
private

Definition at line 66 of file styledtextfile.hpp.

Referenced by lex(), reStyle(), and StyledTextFile().

◆ useStrings

bool StyledTextFile::useStrings
private

Definition at line 68 of file styledtextfile.hpp.

Referenced by lex(), reStyle(), and StyledTextFile().

◆ vFileContents

std::vector<std::pair<size_t, std::string> > StyledTextFile::vFileContents
private

◆ vStyles

std::vector<std::vector<Style> > StyledTextFile::vStyles
private

Definition at line 57 of file styledtextfile.hpp.

Referenced by getStrippedLine(), getStyleAt(), and lex().


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