Wolframe, 0.0.3

_Wolframe::utils Namespace Reference

Utility functions for parsing, handling files, allocating memory, etc. (implemented in the core library libwolframe) More...

Classes

class  ArrayDoublingAllocator
 Interface for an allocator implemented with the strategy of array doubling. More...
 
class  AsciiCharParser
 Class for parsing ascii character by character from a source in an unicode based encoding. More...
 
class  CharTable
 Character table structure for parseNextToken( std::string&,std::string::const_iterator&, std::string::const_iterator, ...);. More...
 
class  FileLineInfo
 Source line info with filename reference for error messages. More...
 
struct  FileType
 Get the file type. More...
 
class  GreedySmallChunkAllocator
 Interface for an allocator for small chunks without a free. Memory is freed in the destructor of the allocator. More...
 
class  IdentifierTable
 Identifier table structure for parseNextIdentifier( std::string::const_iterator&, std::string::const_iterator, ...);. More...
 
class  PrintFormat
 Structure with info for uniform printing for a type of message (log format as compact one liner, text as multi liner) More...
 
class  SourceLineInfo
 Line information for error messages for parser using STL string iterators as source scanners. More...
 
class  TypedArrayDoublingAllocator
 Interface for an array doubling allocator that allocates only one fixed size type of element. More...
 
class  TypeSignature
 Signature of a type for pointer constraint check (disabled) More...
 

Functions

std::string resolvePath (const std::string &path)
 Remove .. and . from a path. More...
 
std::string getFileExtension (const std::string &path)
 Get the extension of a file. More...
 
std::string getFileStem (const std::string &path)
 Get the stem of a file. More...
 
std::string getCanonicalPath (const std::string &path, const std::string &refPath)
 Get the path 'path' relative to 'refpath' if it is not absolute. More...
 
std::string getParentPath (const std::string &path, unsigned int levels=1)
 Get the parent path of 'path' (skipping /./ as parent path unlike boost::filesystem does) More...
 
std::string joinPath (const std::string &path, const std::string &item)
 Join path with an item of the path to a combined path. More...
 
bool fileExists (const std::string &path)
 Returns true, if the file with path 'path' exists. More...
 
std::string readSourceFileContent (const std::string &filename)
 Reading the content of a source file as one string in UTF-8 (with implicit conversion of other known unicode character encodings to UTF-8) More...
 
std::string readBinaryFileContent (const std::string &filename)
 Reading the content of a file as one string without any conversions applied. More...
 
types::PropertyTree readPropertyTreeFile (const std::string &filename)
 Reading the content of a source file as property tree (with property tree syntax) More...
 
types::PropertyTree readXmlPropertyTreeFile (const std::string &filename)
 Reading the content of an XML source file as property tree (with property tree syntax) More...
 
types::PropertyTree readInfoPropertyTreeFile (const std::string &filename)
 Reading the content of an Info format source file as property tree (with property tree syntax) More...
 
void writeFile (const std::string &filename, const std::string &content)
 Writing a file. More...
 
FileType getFileType (const std::string &filename)
 
const CharTableidentifierCharTable ()
 Get the default identifier character table. More...
 
const CharTableemptyCharTable ()
 Get an empty character set as table. More...
 
const CharTableanyCharTable ()
 Get the character set containing all characters as table. More...
 
char parseNextToken (std::string &tok, std::string::const_iterator &itr, std::string::const_iterator end, const CharTable &operatorTable, const CharTable &alphaTable)
 Parsing the next token in a UTF-8 or Isolatin-1 string that is either. More...
 
char parseNextToken (std::string &tok, std::string::const_iterator &itr, std::string::const_iterator end, const CharTable &operatorTable)
 See utils::parseNextToken(std::string&,std::string::const_iterator&,std::string::const_iterator,const CharTable&,const CharTable&) More...
 
char parseNextToken (std::string &tok, std::string::const_iterator &itr, std::string::const_iterator end)
 See utils::parseNextToken(std::string&,std::string::const_iterator&,std::string::const_iterator,const CharTable&,const CharTable&) More...
 
char gotoNextToken (std::string::const_iterator &itr, std::string::const_iterator end)
 Skip to next token (skip white spaces) More...
 
std::string parseLine (std::string::const_iterator &si, const std::string::const_iterator &se)
 Parse the rest of the line starting. More...
 
int parseNextIdentifier (std::string::const_iterator &si, const std::string::const_iterator &se, const IdentifierTable &idtab)
 Parse the next identifier if it is in 'idtab' or goto the next token if not. More...
 
std::pair< std::string,
std::string > 
parseTokenAssignement (std::string::const_iterator &itr, std::string::const_iterator end, const CharTable &alphaTable)
 Parse a token assignement 'identifier = token'. More...
 
std::pair< std::string,
std::string > 
parseTokenAssignement (std::string::const_iterator &itr, std::string::const_iterator end)
 Parse a token assignement 'identifier = token' with the standard identifier table. More...
 
std::string parseNextLine (std::string::const_iterator &itr, std::string::const_iterator end)
 
const PrintFormatlogPrintFormat ()
 Get the print format for logger output. More...
 
const PrintFormatptreePrintFormat ()
 Get the print format for readable multi line output similar to property tree format. More...
 
std::string getLogString (const types::Variant &val, std::size_t maxsize=60)
 Get a string to log out of a variant structure with a restriction of the size of the atomic elements. More...
 
SourceLineInfo getSourceLineInfo (const std::string::const_iterator &start, const std::string::const_iterator &pos)
 Get the source line info by scanning the source parsed from 'start' to 'pos', counting lines and characters inbetween. More...
 
void splitString (std::vector< std::string > &res, const std::string &inp, const char *splitchr)
 Split the string, ingoring empty parts of the result (susequent split characters treated as one) More...
 
void splitString (std::vector< std::string > &res, std::string::const_iterator begin, std::string::const_iterator end, const char *splitchr)
 Split the string, ingoring empty parts of the result (susequent split characters treated as one) More...
 

Detailed Description

Utility functions for parsing, handling files, allocating memory, etc. (implemented in the core library libwolframe)

Function Documentation

const CharTable& _Wolframe::utils::anyCharTable ( )

Get the character set containing all characters as table.

const CharTable& _Wolframe::utils::emptyCharTable ( )

Get an empty character set as table.

bool _Wolframe::utils::fileExists ( const std::string &  path)

Returns true, if the file with path 'path' exists.

std::string _Wolframe::utils::getCanonicalPath ( const std::string &  path,
const std::string &  refPath 
)

Get the path 'path' relative to 'refpath' if it is not absolute.

Parameters
[in]pathrelative part of the path or absolute path
[in]refPathabsolute part of the path if 'path' is relative
Returns
the canonical path
std::string _Wolframe::utils::getFileExtension ( const std::string &  path)

Get the extension of a file.

Parameters
[in]pathThe path to the file to get the extension from
Returns
The file extension including the extension marking dot '.'
std::string _Wolframe::utils::getFileStem ( const std::string &  path)

Get the stem of a file.

Parameters
[in]pathThe path to the file to get the stem from
Returns
The file stem without the extension marking dot '.'
FileType _Wolframe::utils::getFileType ( const std::string &  filename)
std::string _Wolframe::utils::getLogString ( const types::Variant &  val,
std::size_t  maxsize = 60 
)

Get a string to log out of a variant structure with a restriction of the size of the atomic elements.

std::string _Wolframe::utils::getParentPath ( const std::string &  path,
unsigned int  levels = 1 
)

Get the parent path of 'path' (skipping /./ as parent path unlike boost::filesystem does)

Parameters
[in]paththe path to get the parent path from
[in]levelshow many level (1 = parent, 2 = granparent, etc.)
Returns
the parent path
SourceLineInfo _Wolframe::utils::getSourceLineInfo ( const std::string::const_iterator &  start,
const std::string::const_iterator &  pos 
)

Get the source line info by scanning the source parsed from 'start' to 'pos', counting lines and characters inbetween.

char _Wolframe::utils::gotoNextToken ( std::string::const_iterator &  itr,
std::string::const_iterator  end 
)

Skip to next token (skip white spaces)

const CharTable& _Wolframe::utils::identifierCharTable ( )

Get the default identifier character table.

std::string _Wolframe::utils::joinPath ( const std::string &  path,
const std::string &  item 
)

Join path with an item of the path to a combined path.

Parameters
[in]paththe main path
[in]itemthe sub path to join to path
Returns
the joined path
const PrintFormat* _Wolframe::utils::logPrintFormat ( )

Get the print format for logger output.

std::string _Wolframe::utils::parseLine ( std::string::const_iterator &  si,
const std::string::const_iterator &  se 
)

Parse the rest of the line starting.

Parameters
[in,out]sistart of chunk to parse as input and first character after end of line if found or end of chunk to parse as output
[in]seend of chunk to parse
Returns
line parsed without end of line marker
int _Wolframe::utils::parseNextIdentifier ( std::string::const_iterator &  si,
const std::string::const_iterator &  se,
const IdentifierTable &  idtab 
)

Parse the next identifier if it is in 'idtab' or goto the next token if not.

Returns
the index of the identifier (starting from 1) in 'idtab' or 0, if the next token does not match
Parameters
[in,out]siscanning iterator passed as start of the source to parse and returned as source position after the token parsed if it matches or start of the token not matching if not
[in]seiterator marking the end of the source
[in]idtabidentifier table
Returns
0 if not found, else index of identifier in table starting with 1
std::string _Wolframe::utils::parseNextLine ( std::string::const_iterator &  itr,
std::string::const_iterator  end 
)
Remarks
throws exception on error
Returns
line parsed
Parameters
[in,out]itrscanning iterator passed as start of the source to parse and returned as source position after the expression parsed)
[in]enditerator marking the end of the source
char _Wolframe::utils::parseNextToken ( std::string &  tok,
std::string::const_iterator &  itr,
std::string::const_iterator  end,
const CharTable &  operatorTable,
const CharTable &  alphaTable 
)

Parsing the next token in a UTF-8 or Isolatin-1 string that is either.

  • a single quoted (') string backslash escaping returned without the delimiting quotes and escaping resolved
  • a double quoted (") string backslash escaping returned without the delimiting quotes and escaping resolved
  • an identifier consisting of alphanumeric ASCII characters and characters beyond the ASCII code page (>127)
  • a single character operator from an operator table
    Remarks
    throws exception on error
    Returns
    the token as character in case of an operator, else the first character of the token parsed in the source, '\0' when no token was found (EOF)
    Parameters
    [out]toknon operator token parsed
    [in,out]itrscanning iterator passed as start of the source to parse and returned as source position after the token parsed)
    [in]enditerator marking the end of the source
    [in]operatorTable(optional) operator table
    [in]alphaTable(optional) token alphabet as character table
char _Wolframe::utils::parseNextToken ( std::string &  tok,
std::string::const_iterator &  itr,
std::string::const_iterator  end,
const CharTable &  operatorTable 
)
char _Wolframe::utils::parseNextToken ( std::string &  tok,
std::string::const_iterator &  itr,
std::string::const_iterator  end 
)
std::pair<std::string,std::string> _Wolframe::utils::parseTokenAssignement ( std::string::const_iterator &  itr,
std::string::const_iterator  end,
const CharTable &  alphaTable 
)

Parse a token assignement 'identifier = token'.

Returns
pair with assignement first = identifier, second = token
Parameters
[in,out]itrscanning iterator passed as start of the source to parse and returned as source position after the expression parsed
[in]enditerator marking the end of the source
[in]alphaTabletable with characters valid in an identifier
std::pair<std::string,std::string> _Wolframe::utils::parseTokenAssignement ( std::string::const_iterator &  itr,
std::string::const_iterator  end 
)

Parse a token assignement 'identifier = token' with the standard identifier table.

Returns
pair with assignement first = identifier, second = token
Parameters
[in,out]itrscanning iterator passed as start of the source to parse and returned as source position after the expression parsed
[in]enditerator marking the end of the source
const PrintFormat* _Wolframe::utils::ptreePrintFormat ( )

Get the print format for readable multi line output similar to property tree format.

std::string _Wolframe::utils::readBinaryFileContent ( const std::string &  filename)

Reading the content of a file as one string without any conversions applied.

Remarks
Throws on error
types::PropertyTree _Wolframe::utils::readInfoPropertyTreeFile ( const std::string &  filename)

Reading the content of an Info format source file as property tree (with property tree syntax)

Remarks
Throws on error
types::PropertyTree _Wolframe::utils::readPropertyTreeFile ( const std::string &  filename)

Reading the content of a source file as property tree (with property tree syntax)

Remarks
Throws on error
std::string _Wolframe::utils::readSourceFileContent ( const std::string &  filename)

Reading the content of a source file as one string in UTF-8 (with implicit conversion of other known unicode character encodings to UTF-8)

Remarks
Throws on error
types::PropertyTree _Wolframe::utils::readXmlPropertyTreeFile ( const std::string &  filename)

Reading the content of an XML source file as property tree (with property tree syntax)

Remarks
Throws on error
std::string _Wolframe::utils::resolvePath ( const std::string &  path)

Remove .. and . from a path.

Parameters
[in]pathPath to process
void _Wolframe::utils::splitString ( std::vector< std::string > &  res,
const std::string &  inp,
const char *  splitchr 
)

Split the string, ingoring empty parts of the result (susequent split characters treated as one)

Parameters
[out]resresult of the split
[in]inpstring to split
[in]splitchrset of characters to split with (each of them is one separating character)
void _Wolframe::utils::splitString ( std::vector< std::string > &  res,
std::string::const_iterator  begin,
std::string::const_iterator  end,
const char *  splitchr 
)

Split the string, ingoring empty parts of the result (susequent split characters treated as one)

Parameters
[out]resresult of the split
[in]beginbegin input iterator
[in]endend input iterator
[in]splitchrset of characters to split with (each of them is one separating character)
void _Wolframe::utils::writeFile ( const std::string &  filename,
const std::string &  content 
)

Writing a file.

Remarks
Throws on error