All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Functions | Variables
utils Namespace Reference

Functions

bool isBlankLine (const std::string &s)
 
bool isIntegerString (const std::string &s)
 
bool isFloatString (const std::string &s)
 
bool isQuoted (const std::string &s)
 
bool isQuotedSentence (const std::string &s)
 
std::string removeSubstring (const std::string &str, const std::string substr)
 
std::string removeEndSlash (const std::string &str)
 
std::string parseUntilQuote (std::istringstream &parser, const std::string &begin)
 
template<typename T >
std::string toString (T type)
 
std::string syscallError (const std::string &syscall, int errorCode)
 
std::string getCurrentTime ()
 
std::string formatSize (size_t size)
 
std::string getMacroName (int errorCode)
 

Variables

const int ERROR_BUFF_SIZE = 2048
 
const size_t KILOBYTE = 1000
 
const size_t MEGABYTE = 1000000
 

Detailed Description

A namespace with many utility functions, both for UNIX and Win32.

Function Documentation

string utils::formatSize ( size_t  size)
Parameters
sizeA certain byte size.
Returns
String with the form "n B/KB/MB", depending on how many bytes has been provided in the argument.
string utils::getCurrentTime ( )
Returns
String representation of the current datetime, in the format dd/mm/yy hh:mm:ss.
string utils::getMacroName ( int  errorCode)
Parameters
errorCodeAn error code (POSIX or Win32)
Returns
String representation of the macro name related to the given error code. If no match are found, the string conversion of the given error code.
bool utils::isBlankLine ( const std::string &  s)

Costant to convert Bytes into Megabytes.

Parameters
sA generic string
Returns
true if the string has only spaces, false otherwise.
bool utils::isFloatString ( const std::string &  s)
Parameters
sA generic string
Returns
true if the string has only numerical digits and exactly one "point", false otherwise.
bool utils::isIntegerString ( const std::string &  s)
Parameters
sA generic string
Returns
true if the string has only numerical digits, false otherwise.
bool utils::isQuoted ( const std::string &  s)
Parameters
sA generic string
Returns
true if the string is a single quoted word (like 'apple'), false otherwise.
bool utils::isQuotedSentence ( const std::string &  s)
Parameters
sA generic string
Returns
true if the string is a single quoted sentence (like 'a sentence'), false otherwise.
std::string utils::parseUntilQuote ( std::istringstream &  parser,
const std::string &  begin 
)

Extract words from the given stream until a single quote is found, to create a sentence.

Parameters
parserThe input stream to be parsed
beginA generic string which will be used as the start of the sentence. It should start with a single quote.
Returns
A single quoted sentence extracted from the given stream.
std::string utils::removeEndSlash ( const std::string &  str)
Parameters
strA generic string
Returns
The given string without its last character, if this one is a slash or a backslash; otherwise the original string.
std::string utils::removeSubstring ( const std::string &  str,
const std::string  substr 
)
Parameters
strA generic string
substrAnother generic string, supposed to be a substring of str.
Returns
the string <str> without the substring <substr>, if <substr> is a substring of <str>; otherwise the original string <str>.
string utils::syscallError ( const std::string &  syscall,
int  errorCode 
)

Create a well-formatted string explaining the given error code returned by a failed system call.

Parameters
syscallThe name of the failed system call.
errorCodeThe error code returned by the failed system call.
Returns
A string with the form: <syscall> failed [error <errorCode>]: <platform-specific error message>
template<typename T >
std::string utils::toString ( type)
Parameters
typeA generic object to be converted into a string.
Returns
The string conversion of the given object.

Variable Documentation

const size_t utils::KILOBYTE = 1000

Max char allowed in the error message buffer.

const size_t utils::MEGABYTE = 1000000

Constat to convert Bytes into Kilobytes.