OpenM++ runtime library (libopenm)
omHelper.h File Reference

OpenM++ common helper utilities. More...

Include dependency graph for omHelper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  openm::LessNoCase
 case neutral less comparator for strings More...
 
struct  openm::IRowBase
 db-row abstract base More...
 
struct  openm::IFinalState
 final model run state public interface: thread safe More...
 
class  openm::exit_guard< ResourceHolder >
 simple resource exit guard implementation More...
 

Namespaces

namespace  openm
 openM++ namespace
 

Macros

#define OM_PATH_MAX   (FILENAME_MAX < 4096 ? FILENAME_MAX : 4096)
 
#define OM_STRLEN_MAX   INT_MAX /** max string length supported */
 
#define OM_STR_DB_MAX   32000 /** max database string length: notes varchar (clob, text) */
 
#define OM_CODE_DB_MAX   32 /** max database length for codes: language code, digests, date-time string */
 
#define OM_NAME_DB_MAX   255 /** max database length for names: parameter name, table name, etc. */
 
#define OM_DESCR_DB_MAX   255 /** max database length for description: parameter description, table description, etc. */
 
#define OM_OPTION_DB_MAX   32000 /** max database length for option value: profile_option, run_option */
 
#define OM_SQL_EXPR_DB_MAX   2048 /** max database length for sql expression: accumulator or output table expression */
 
#define OM_MAX_BUILTIN_TYPE_ID   100 /** max type id for built-int types, ie: int, double, logical */
 
#define OM_STATE_SAVE_TIME   1811L /** msec, interval between run state save if any changes in run status */
 
#define OM_STATE_BEAT_TIME   1823L /** msec, interval between run state heart beats update */
 

Typedefs

typedef std::map< std::string, std::string, LessNoCase > openm::NoCaseMap
 map of key-value strings with case neutral key search
 
typedef std::set< std::string, LessNoCase > openm::NoCaseSet
 set of strings with case neutral key search
 
typedef std::unique_ptr< IRowBase > openm::IRowBaseUptr
 unique pointer to db row
 
typedef std::vector< IRowBaseUptr > openm::IRowBaseVec
 db rows: vector of unique pointers to db row
 
typedef std::list< IRowBaseUptr > openm::IRowBaseList
 db rows: list of unique pointers to db row
 

Functions

void openm::toLower (std::string &io_str, const std::locale &i_locale=std::locale(""))
 convert string to lower case
 
void openm::toLower (char *io_str, const std::locale &i_locale=std::locale(""))
 convert string to lower case
 
void openm::toUpper (std::string &io_str, const std::locale &i_locale=std::locale(""))
 convert string to upper case
 
void openm::toUpper (char *io_str, const std::locale &i_locale=std::locale(""))
 convert string to upper case
 
int openm::compareNoCase (const char *i_left, const char *i_right, size_t i_length=0)
 case neutral string comparison
 
bool openm::equalNoCase (const char *i_left, const char *i_right, size_t i_length=0)
 case neutral string equal comparison
 
bool openm::startWithNoCase (const std::string &i_str, const char *i_start)
 check if string start with i_start, using case neutral string comparison
 
bool openm::endWithNoCase (const std::string &i_str, const char *i_end)
 check if string end with i_end, using case neutral string comparison
 
std::string openm::trimLeft (const std::string &i_str, const std::locale &i_locale=std::locale(""))
 trim leading blank and space characters
 
std::string openm::trimRight (const std::string &i_str, const std::locale &i_locale=std::locale(""))
 trim trailing blank and space characters
 
std::string openm::trim (const std::string &i_str, const std::locale &i_locale=std::locale(""))
 trim leading and trailing blank and space characters
 
void openm::blankCrLf (std::string &io_str)
 replace all <cr> or <lf> with blank space character
 
const std::string openm::toQuoted (const std::string &i_str, char i_quote='\'')
 make quoted string using sql single ' quote by default, ie: 'O''Brien'
 
const std::string openm::toUnQuoted (const std::string &i_str, char i_quote='\'', const std::locale &i_locale=std::locale(""))
 make unquoted string using sql single ' quote by default, ie: 'O''Brien' into O'Brien
 
const std::string openm::toString (double i_val)
 convert float type to string: exist to fix std::to_string conversion losses.
 
const std::string openm::toAlphaNumeric (const std::string &i_str, int i_maxSize=0)
 replace all non [A-Z,a-z,0-9] by _ underscore and remove repetitive underscores.
 
const std::string openm::cleanPathChars (const std::string &i_str, int i_maxSize=0)
 replace all non non-printable and any of "'`$}{><:|?*&^;/\ by _ underscore.
 
const std::string openm::replaceAll (const std::string &i_src, const char *i_oldValue, const char *i_newValue)
 replace all occurence of i_oldValue by i_newValue, both old and new values must be not empty
 
bool openm::isBoolType (const char *i_typeName)
 return true if model type is boolean (logical)
 
bool openm::isStringType (const char *i_typeName)
 return true if model type is string (varchar)
 
bool openm::isBigIntType (const char *i_typeName)
 return true if model type is bigint (64 bit)
 
bool openm::isIntType (const char *i_typeName, int i_typeId)
 return true if model type is integer: not float, string, boolean, bigint (if type is not a built-in then it must be integer enums)
 
bool openm::isBuiltInType (int i_typeId)
 return true if model type id is built-in type id, ie: int, double, logical
 
bool openm::isFloatType (const char *i_typeName)
 return true if model type is float (float, real, double or time)
 
bool openm::isTimeType (const char *i_typeName)
 return true if model type is Time
 
bool openm::isIntValid (const char *i_value)
 return true if i_value string represent valid integer constant
 
bool openm::isFloatValid (const char *i_value)
 return true if i_value string represent valid floating point constant
 
bool openm::isBoolTrue (const char *i_str)
 return true if lower case of source string one of: "yes" "1" "true"
 
bool openm::isBoolValid (const char *i_str)
 return true if lower case of source string one of: "yes" "1" "true" "no" "0" "false"
 
int openm::boolStringToInt (const char *i_value)
 convert i_value string represnting boolean option and return one of:
return 1 if i_value is one of: "yes", "1", "true" or empty "" value,
return 0 if i_value is one of: "no", "0", "false",
return -1 if i_value is nullptr,
return -2 otherwise.
 
ptrdiff_t openm::memCopyTo (uint8_t *io_dst, ptrdiff_t i_offset, const void *i_src, size_t i_size)
 copy bytes source into destination and return next destination offset
 
const std::string openm::makeDateTime (const std::chrono::system_clock::time_point &i_time)
 make date-time string, ie: 2012-08-17 16:04:59.148
 
const std::string openm::makeTimeStamp (const std::chrono::system_clock::time_point &i_time)
 make timestamp string, ie: 2012_08_17_16_04_59_148
 
const std::string openm::toDateTimeString (const std::string &i_timestamp)
 make date-time string from timestamp string, ie: 2012_08_17_16_04_59_148 => 2012-08-17 16:04:59.148
 
void openm::formatTo (size_t i_size, char *io_buffer, const char *i_format, va_list io_args)
 format message into supplied buffer using vsnprintf()
 
std::string openm::formatToString (const char *i_format,...)
 format message into string result using vsnprintf()
 
const char * openm::elliptString (const char *i_src, size_t i_size, char *io_buffer)
 if source string exceed max size than return ellipted copy into the buffer
 
const std::string openm::normalizeLanguageName (const std::string &i_srcLanguage)
 normalize language name by removing encoding part, replace _ by - and lower case: "en-ca" from "en_CA.UTF-8"
 
const std::list< std::string > openm::splitLanguageName (const std::string &i_srcLanguage)
 normalize language name and split it into list of prefered languages: en_CA => [en-ca, en]
 
std::list< std::string > openm::splitCsv (const std::string &i_values, const char *i_delimiters=",", bool i_isUnquote=false, char i_quote='\'')
 split and trim comma-separated list of values (other delimiters can be used too, ie: semicolon). More...
 
void openm::splitCsv (const std::string &i_values, std::list< std::string > &io_resultLst, const char *i_delimiters=",", bool i_isUnquote=false, char i_quote='\'', const std::locale &i_locale=std::locale(""))
 split and trim comma-separated list of values (other delimiters can be used too, ie: semicolon). More...
 

Detailed Description

OpenM++ common helper utilities.