Loxahatchee  v0.0.1-1346
Lox Convenience C++ Library
Lox Namespace Reference

Common methods and functionality easily shared between projects. More...

Namespaces

 Colours
 Several simple methods to handle collections of similar colours.
 
 Measurement
 Common functions to work with and convert metric and imperial measurements.
 
 Numbers
 Common functions to work with integers and doubles.
 
 Prices
 Common functions to work with dollar amounts.
 
 Temperature
 Common functions to work with and convert metric and imperial temperatures.
 

Classes

class  Exception
 Exception class with an easy-to-use embedded backtrace. More...
 
class  Log
 Logging system, uses syslog on posix and normal logging on Windows. More...
 
class  Money
 Class to help manage currency. More...
 
class  PQDB
 PostgreSQL database class with simplified access to libpq++. More...
 

Typedefs

typedef double CELSIUS
 Celsius. More...
 
typedef std::size_t DBId
 Convenient type to use for database serial types, which is a large unsigned number starting at zero. More...
 
typedef pqxx::nontransaction DBNT
 Database non-transaction. No need to call DBNT::commit(), and calling DBNT::abort() has no effect. More...
 
typedef pqxx::result DBResult
 Database results. May represent many rows. More...
 
typedef pqxx::result::reference DBRow
 A single row from the database result. More...
 
typedef pqxx::work DBT
 Database transaction object. Must remember to call DBT::commit() before the transaction goes out of scope. More...
 
typedef double FAHRENHEIT
 Fahrenheit. More...
 
typedef double IN
 Decimal inches (meaning 3 1/4" will be stored as 3.25). More...
 
typedef std::map< DBId, std::string > MIdStr
 Map ID to string. More...
 
typedef double MM
 Millimeters. More...
 
typedef std::map< std::string, std::string > MStr
 Map of string-to-string. More...
 
typedef std::set< DBIdSId
 Set of database indexes. More...
 
typedef std::set< std::string > SStr
 Set of strings, automatically sorted alphabetically. More...
 
typedef std::vector< DBIdVId
 Vector of database indexes. More...
 
typedef std::vector< std::string > VStr
 Vector of strings. More...
 

Enumerations

enum  EUnits {
  kUnknown = 0,
  kMetric,
  kImperial
}
 

Functions

std::string approximateTime (const time_t &tt)
 Convert the given absolute (since epoch) time to an easy-to-read text string. More...
 
std::string approximateTime (const std::string &str)
 Convert a database timestamp to an easy-to-read text string. More...
 
std::string buildDate (void)
 Date and timestamp when this library was built. More...
 
std::string copyright (void)
 Copyright string. More...
 
std::string demangle (std::string name)
 Demangle the given C++ name. More...
 
bool endsWith (const std::string &str, const std::string &end, const bool trimFirst=true)
 Check to see if the text string ends with the given string. More...
 
std::string & evenWhitespace (std::string &str)
 Remove all extra whitespace, such as double spaces, newlines, and tabs. More...
 
std::string evenWhitespace (const std::string &str)
 Remove all extra whitespace, such as double spaces, newlines, and tabs. More...
 
VStr getBacktrace (int skip=2)
 Store the backtrace in a string array. More...
 
Lox::VStr importSqlFile (const std::string &filename)
 Import the given SQL text file. More...
 
std::string & ltrim (std::string &str)
 Left-trim whitespace. More...
 
std::string ltrim (const std::string &str)
 Left-trim whitespace. More...
 
std::string & makeLabel (std::string &str)
 Remove all special characters to create a plain text "label". Can be used to generate a filename. More...
 
std::string makeLabel (const std::string &str)
 Remove all special characters to create a plain text "label". Can be used to generate a filename. More...
 
std::string name (void)
 The library name. More...
 
std::string nameAndVersion (void)
 The library name and version strings combined. More...
 
std::ostream & operator<< (std::ostream &os, const Money &money)
 
Lox::VStr readTextFile (const std::string &filename, const bool throwIfOpenFails=true, const bool throwIfFileIsEmpty=true)
 Read all lines from a text file and store each individual line into a vector. More...
 
std::string & rtrim (std::string &str)
 Right-trim whitespace. More...
 
std::string rtrim (const std::string &str)
 Right-trim whitespace. More...
 
Lox::VStr splitOnNewlines (const std::string &str)
 Create a vector of strings by splitting on newline or carriage-return + newline. More...
 
Lox::VStr splitOnWords (const std::string &str)
 Create a vector using individual words from the provided text. More...
 
bool startsWith (const std::string &str, const std::string &start, const bool trimFirst=true)
 Check to see if the text string begins with the given string. More...
 
time_t timeFromString (const std::string &str)
 Convert a database timestamp (or other date/time string) to a time_t type. More...
 
std::string & trim (std::string &str)
 Trim whitespace from both left and right sides. More...
 
std::string trim (const std::string &str)
 Trim whitespace from both left and right sides. More...
 
std::string version (void)
 The library version number. More...
 
Money operator* (const long double lhs, const Money &rhs)
 allow things like "2.0 * cost" in addition to the usual "cost * 2.0" More...
 
Money operator* (const double lhs, const Money &rhs)
 allow things like "2.0 * cost" in addition to the usual "cost * 2.0" More...
 
Money operator* (const size_t lhs, const Money &rhs)
 allow things like "2.0 * cost" in addition to the usual "cost * 2.0" More...
 
Money operator* (const int lhs, const Money &rhs)
 allow things like "2.0 * cost" in addition to the usual "cost * 2.0" More...
 
Money operator+ (const long double lhs, const Money &rhs)
 allow things like "2.0 + cost" in addition to the usual "cost + 2.0" More...
 
Money operator+ (const double lhs, const Money &rhs)
 allow things like "2.0 + cost" in addition to the usual "cost + 2.0" More...
 
Money operator+ (const size_t lhs, const Money &rhs)
 allow things like "2.0 + cost" in addition to the usual "cost + 2.0" More...
 
Money operator+ (const int lhs, const Money &rhs)
 allow things like "2.0 + cost" in addition to the usual "cost + 2.0" More...
 

Detailed Description

Common methods and functionality easily shared between projects.

Typedef Documentation

typedef double Lox::CELSIUS

Celsius.

typedef std::size_t Lox::DBId

Convenient type to use for database serial types, which is a large unsigned number starting at zero.

PostgreSQL uses 63 bits of an 8 byte numeric type for bigserial, giving it a range of 1 to 9223372036854775807 (>9 quintillion). On 64-bit systems, size_t will give us access to all 63 bits.

typedef pqxx::nontransaction Lox::DBNT

Database non-transaction. No need to call DBNT::commit(), and calling DBNT::abort() has no effect.

typedef pqxx::result Lox::DBResult

Database results. May represent many rows.

typedef pqxx::result::reference Lox::DBRow

A single row from the database result.

typedef pqxx::work Lox::DBT

Database transaction object. Must remember to call DBT::commit() before the transaction goes out of scope.

typedef double Lox::FAHRENHEIT

Fahrenheit.

typedef double Lox::IN

Decimal inches (meaning 3 1/4" will be stored as 3.25).

typedef std::map<DBId, std::string> Lox::MIdStr

Map ID to string.

typedef double Lox::MM

Millimeters.

typedef std::map<std::string, std::string> Lox::MStr

Map of string-to-string.

typedef std::set<DBId> Lox::SId

Set of database indexes.

typedef std::set<std::string> Lox::SStr

Set of strings, automatically sorted alphabetically.

typedef std::vector<DBId> Lox::VId

Vector of database indexes.

typedef std::vector<std::string> Lox::VStr

Vector of strings.

Enumeration Type Documentation

Enumerator
kUnknown 
kMetric 

in mm

kImperial 

in inches

Function Documentation

std::string Lox::approximateTime ( const time_t &  tt)

Convert the given absolute (since epoch) time to an easy-to-read text string.

Between zero and 3 minutes, display in "seconds".

Between 3 minutes and 120 minutes, display in "minutes".

Between 2 hours and 48 hours, display in "hours".

Between 48 hours and 14 days, display in "days".

Between 14 days and 9 weeks, display in "weeks".

Between 9 weeks and 24 months, display in "months".

Anything more than 24 months, display in years.

Referenced by approximateTime().

Here is the caller graph for this function:

std::string Lox::approximateTime ( const std::string &  str)

Convert a database timestamp to an easy-to-read text string.

References approximateTime(), and timeFromString().

Here is the call graph for this function:

std::string Lox::buildDate ( void  )

Date and timestamp when this library was built.

Format the compiler macros __DATE__ and __TIME__ to make a readable timestamp showing when this project was last built.

std::string Lox::copyright ( void  )

Copyright string.

std::string Lox::demangle ( std::string  name)

Demangle the given C++ name.

References name().

Referenced by Lox::Exception::Exception(), getBacktrace(), and Lox::Exception::operator std::string().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Lox::endsWith ( const std::string &  str,
const std::string &  end,
const bool  trimFirst = true 
)

Check to see if the text string ends with the given string.

References trim().

Referenced by importSqlFile().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string & Lox::evenWhitespace ( std::string &  str)

Remove all extra whitespace, such as double spaces, newlines, and tabs.

References trim().

Referenced by evenWhitespace(), importSqlFile(), Lox::Exception::initialize(), makeLabel(), and splitOnWords().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Lox::evenWhitespace ( const std::string &  str)

Remove all extra whitespace, such as double spaces, newlines, and tabs.

References evenWhitespace().

Here is the call graph for this function:

Lox::VStr Lox::getBacktrace ( int  skip = 2)

Store the backtrace in a string array.

Used by Lox::Exception.

Parameters
[in]skipDetermines how many lines (function names) from the top of the backtrace should be ignored.

References demangle(), and name().

Referenced by Lox::Exception::initialize(), and Lox::Exception::operator std::string().

Here is the call graph for this function:

Here is the caller graph for this function:

Lox::VStr Lox::importSqlFile ( const std::string &  filename)

Import the given SQL text file.

Text lines are combined as necessary so each entry in the VStr maps to a single complete SQL command. Comments and the trailing semicolon are automatically removed so SQL commands can be immediately run using interfaces such as Lox::PQDB::exec().

References endsWith(), evenWhitespace(), and readTextFile().

Here is the call graph for this function:

std::string & Lox::ltrim ( std::string &  str)

Left-trim whitespace.

Referenced by ltrim(), and trim().

Here is the caller graph for this function:

std::string Lox::ltrim ( const std::string &  str)

Left-trim whitespace.

References ltrim().

Here is the call graph for this function:

std::string & Lox::makeLabel ( std::string &  str)

Remove all special characters to create a plain text "label". Can be used to generate a filename.

Any existing whitespace will be used as a hint to where to CamelCase the existing text.

Only the following characters will be retained: "A-Za-z0-9_."

Exceptions
Lox::Exceptionif the text is empty or composed of only special characters.

References evenWhitespace(), and LOX_WHERE.

Referenced by makeLabel().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Lox::makeLabel ( const std::string &  str)

Remove all special characters to create a plain text "label". Can be used to generate a filename.

References makeLabel().

Here is the call graph for this function:

std::string Lox::name ( void  )

The library name.

Referenced by demangle(), Lox::Exception::Exception(), getBacktrace(), Lox::Exception::initialize(), nameAndVersion(), and Lox::Exception::operator std::string().

Here is the caller graph for this function:

std::string Lox::nameAndVersion ( void  )

The library name and version strings combined.

References name(), and version().

Here is the call graph for this function:

Money Lox::operator* ( const long double  lhs,
const Money rhs 
)
inline

allow things like "2.0 * cost" in addition to the usual "cost * 2.0"

Money Lox::operator* ( const double  lhs,
const Money rhs 
)
inline

allow things like "2.0 * cost" in addition to the usual "cost * 2.0"

Money Lox::operator* ( const size_t  lhs,
const Money rhs 
)
inline

allow things like "2.0 * cost" in addition to the usual "cost * 2.0"

Money Lox::operator* ( const int  lhs,
const Money rhs 
)
inline

allow things like "2.0 * cost" in addition to the usual "cost * 2.0"

Money Lox::operator+ ( const long double  lhs,
const Money rhs 
)
inline

allow things like "2.0 + cost" in addition to the usual "cost + 2.0"

Money Lox::operator+ ( const double  lhs,
const Money rhs 
)
inline

allow things like "2.0 + cost" in addition to the usual "cost + 2.0"

Money Lox::operator+ ( const size_t  lhs,
const Money rhs 
)
inline

allow things like "2.0 + cost" in addition to the usual "cost + 2.0"

Money Lox::operator+ ( const int  lhs,
const Money rhs 
)
inline

allow things like "2.0 + cost" in addition to the usual "cost + 2.0"

std::ostream& Lox::operator<< ( std::ostream &  os,
const Money money 
)
inline

References Lox::Money::to_string().

Here is the call graph for this function:

Lox::VStr Lox::readTextFile ( const std::string &  filename,
const bool  throwIfOpenFails = true,
const bool  throwIfFileIsEmpty = true 
)

Read all lines from a text file and store each individual line into a vector.

Exceptions
Lox::Exceptionif the file cannot be opened for input.
Lox::Exceptionif the file is empty.

References LOX_WHERE.

Referenced by importSqlFile().

Here is the caller graph for this function:

std::string & Lox::rtrim ( std::string &  str)

Right-trim whitespace.

Referenced by rtrim(), and trim().

Here is the caller graph for this function:

std::string Lox::rtrim ( const std::string &  str)

Right-trim whitespace.

References rtrim().

Here is the call graph for this function:

Lox::VStr Lox::splitOnNewlines ( const std::string &  str)

Create a vector of strings by splitting on newline or carriage-return + newline.

References trim().

Here is the call graph for this function:

Lox::VStr Lox::splitOnWords ( const std::string &  str)

Create a vector using individual words from the provided text.

References evenWhitespace().

Here is the call graph for this function:

bool Lox::startsWith ( const std::string &  str,
const std::string &  start,
const bool  trimFirst = true 
)

Check to see if the text string begins with the given string.

References trim().

Here is the call graph for this function:

time_t Lox::timeFromString ( const std::string &  str)

Convert a database timestamp (or other date/time string) to a time_t type.

References Lox::Numbers::format().

Referenced by approximateTime().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string & Lox::trim ( std::string &  str)

Trim whitespace from both left and right sides.

References ltrim(), and rtrim().

Referenced by endsWith(), evenWhitespace(), getErrnoString(), Lox::Exception::initialize(), Lox::Measurement::isImperial(), Lox::Measurement::isMetric(), Lox::Exception::operator std::string(), splitOnNewlines(), startsWith(), and trim().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Lox::trim ( const std::string &  str)

Trim whitespace from both left and right sides.

References trim().

Here is the call graph for this function:

std::string Lox::version ( void  )

The library version number.

Referenced by nameAndVersion().

Here is the caller graph for this function: