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< DBId > | SId |
Set of database indexes. More... | |
typedef std::set< std::string > | SStr |
Set of strings, automatically sorted alphabetically. More... | |
typedef std::vector< DBId > | VId |
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... | |
Common methods and functionality easily shared between projects.
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<std::string> Lox::SStr |
Set of strings, automatically sorted alphabetically.
typedef std::vector<std::string> Lox::VStr |
Vector of strings.
enum Lox::EUnits |
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().
std::string Lox::approximateTime | ( | const std::string & | str | ) |
Convert a database timestamp to an easy-to-read text string.
References approximateTime(), and timeFromString().
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().
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().
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().
std::string Lox::evenWhitespace | ( | const std::string & | str | ) |
Remove all extra whitespace, such as double spaces, newlines, and tabs.
References evenWhitespace().
Lox::VStr Lox::getBacktrace | ( | int | skip = 2 | ) |
Store the backtrace in a string array.
Used by Lox::Exception.
[in] | skip | Determines 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().
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().
std::string & Lox::ltrim | ( | std::string & | str | ) |
std::string Lox::ltrim | ( | const std::string & | str | ) |
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_."
Lox::Exception | if the text is empty or composed of only special characters. |
References evenWhitespace(), and LOX_WHERE.
Referenced by makeLabel().
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().
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().
std::string Lox::nameAndVersion | ( | void | ) |
allow things like "2.0 * cost" in addition to the usual "cost * 2.0"
allow things like "2.0 * cost" in addition to the usual "cost * 2.0"
allow things like "2.0 * cost" in addition to the usual "cost * 2.0"
allow things like "2.0 * cost" in addition to the usual "cost * 2.0"
allow things like "2.0 + cost" in addition to the usual "cost + 2.0"
allow things like "2.0 + cost" in addition to the usual "cost + 2.0"
allow things like "2.0 + cost" in addition to the usual "cost + 2.0"
allow things like "2.0 + cost" in addition to the usual "cost + 2.0"
|
inline |
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.
Lox::Exception | if the file cannot be opened for input. |
Lox::Exception | if the file is empty. |
References LOX_WHERE.
Referenced by importSqlFile().
std::string & Lox::rtrim | ( | std::string & | str | ) |
std::string Lox::rtrim | ( | const std::string & | str | ) |
Lox::VStr Lox::splitOnNewlines | ( | const std::string & | str | ) |
Create a vector of strings by splitting on newline or carriage-return + newline.
References trim().
Lox::VStr Lox::splitOnWords | ( | const std::string & | str | ) |
Create a vector using individual words from the provided text.
References evenWhitespace().
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().
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().
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().
std::string Lox::trim | ( | const std::string & | str | ) |
Trim whitespace from both left and right sides.
References trim().
std::string Lox::version | ( | void | ) |
The library version number.
Referenced by nameAndVersion().