Classes | Functions

keyvalue::util Namespace Reference

Utility classes and functions are member of this namespace. More...

Classes

class  Global
 Manager of global objects. More...
struct  IsBasic
 This meta-function checks if a type is either bool, double, string, ptime or unsigned int or not. More...
struct  IsBasicOrEnum
 This meta-function checks if a type is either bool, double, string, ptime, unsigned int or enum or not. More...
class  NullDeleter
 A shared_ptr deleter that does not do anything. More...
class  Saver
 Saves a variable reference at construction time to restore/set its value at destruction time. More...

Functions

template<typename From , typename To >
To Lexical (const From &input)
 Converts from type From to type To.
ptime tenor2ptime (const ptime &start, const string &tenor)
 Convert a tenor string (from a start date) into the corresponding date.

Detailed Description

Utility classes and functions are member of this namespace.


Function Documentation

To keyvalue::util::Lexical ( const From &  input  ) 

Converts from type From to type To.

Parameters:
From : (template parameter) The input type;
To : (template parameter) The output type;
input : Data to be converted.
Return values:
For <From, To> = <double, bool> : It returns true if input != 0.0. Otherwise, it returns false.
For <From, To> = <bool, double> : It returns 1.0 if input = true and 0.0 if input = false.
For <From, To> = <string, bool> : It returns true if input is either "TRUE", "True", "true", "YES", "Yes", "yes", "Y" or "y". It returns false if input is either "FALSE", "False", "false", "NO", "No", "no", "N" or "n".
For <From, To> = <bool, string> : It returns "True" if input = true and "False" if input = false.
For <From, To> = <string, double> : It returns the double represented by string input.
For <From, To> = <double, string> : It returns the string representation of input.

throw RuntimeError : If required conversion is invalid.

ptime keyvalue::util::tenor2ptime ( const ptime &  start,
const string &  tenor 
)

Convert a tenor string (from a start date) into the corresponding date.

A tenor is a string of the form nP, where n is a positive integer and P is a char defining a period of time. Possible values for P are:

  • 'd' or 'D' for day;
  • 'w' or 'W' for week;
  • 'm' or 'M' for month; or
  • 'y' or 'Y' for year.

This function returns the date which follows start by the amount of time defined by the tenor.

Parameters:
start : The start date;
tenor : The tenor.
Returns:
A ptime value corresponding to the tenor amount of time from start date.
Exceptions:
RuntimeError : When an invalid tenor is provided.