class Convert
Convert-derived classes serve as bidirectional Value-Value converters. One direction is represented by Format method and usually converts the Value to the textual representation. Reverse direction is represented by the Scan method.
If the conversion is not possible (e.g. due to invalid textual representation), convert methods should return "ErrorValue" to indicate the problem.
virtual Value Format(const Value& q) const
Converts the Value. Default implementation uses Value::ToString to convert the Value.
|
Return value |
Converted Value. |
virtual Value Scan(const Value& text) const
Converts the Value in reverse direction. Default implementation returns text (no conversion is performed).
|
Return value |
Converted Value. |
virtual int Filter(int chr) const
Adjusts characters allowed in textual representation of Value.
|
Return value |
Adjusted character. Zero indicates that character is rejected. Filter is allowed to alter the input character (e.g. by upper-casing it, changing ',' to '.' etc..). Default implementation returns unaltered chr. |
Value operator()(const Value& q) const
Invokes the Format method. Helper functor-like syntax.
|
Return value |
Converted Value. |
class ConvertDate : public Convert
Date Converter. Textual date format depends on actual regional settings.
Derived from Convert
ConvertDate(Date minval = Date::Low(), Date maxval = Date::High(), bool notnull = false)
Constructor.
|
minval |
Minimum Date allowed. |
|
maxval |
Maximum Date allowed. |
~ConvertDate()
Default destructor.
ConvertDate& MinMax(Date _min, Date _max)
Sets the range of Dates allowed.
ConvertDate& Min(Date _min)
Sets minimal allowed Date.
ConvertDate& Max(Date _max)
Sets maximal allowed Date.
ConvertDate& NotNull(bool b = true)
Allows/disallows Null dates. (Null dates are represented by the empty text).
|
b |
true to disallow Null dates. |
ConvertDate& NoNotNull()
Same as NotNull(false).
ConvertDate& Default(Date d)
When the text is empty, Scan returns this value.
Date GetMin() const
Returns minimal allowed date. This is maximum of value set by Min and default minimum (GetDefaultMin).
Date GetMax() const
Returns upper limit of allowed dates. This is minimum of value set by Max and default maximum (GetDefaultMax).
static Date GetDefaultMin()
Returns default minimum.
static Date GetDefaultMax()
Returns default maximum.
void SetDefaultMinMax(Date min, Date max)
Sets values for default minimum and maximum. Default values are Date::Low() and Date::Hight().
bool IsNotNull() const
|
Return value |
true is Nulls are disallowed. |
class ConvertTime : public Convert
Time converter.
Derived from Convert
ConvertTime(Time minval = ToTime(Date::Low()), Time maxval = ToTime(Date::High()), bool notnull = false)
Constructor.
|
minval |
Lower limit. Default means there is no limit. |
|
maxval |
Upper limit. Default means there is no limit. |
|
notnull |
true disallows Nulls. |
~ConvertTime()
Default destructor.
ConvertTime& MinMax(Time _min, Time _max)
Time limeits.
ConvertTime& Min(Time _min)
Sets lower limit.
ConvertTime& Max(Time _max)
Sets upper limit.
ConvertTime& NotNull(bool b = true)
Disallows empty Strings.
ConvertTime& NoNotNull()
Same as NotNull(false).
ConvertTime& Seconds(bool b = true)
If true (which is default), Format returns time with seconds.
ConvertTime& NoSeconds()
Same as Seconds(fale)
bool IsSeconds() const
Returns the value set by Seconds.,
ConvertTime& TimeAlways(bool b = true)
If active, Format always shows time, even if the Value is Date or is at midnight. Default is false.
bool IsTimeAlways() const
Returns the value set by TimeAlways.
ConvertTime& DayEnd(bool b = true)
If active, when Scan encounters date without time, it sets the time to 23:59:59. Default is false.
bool IsDayEnd() const
Returns the value set by DayEnd.
ConvertTime& Default(Time d)
Sets default time returned by Scan when input is empty.
Time GetMin() const
Returns minimal allowed time. This is maximum of value set by Min and default minimum (GetDefaultMin).
Time GetMax() const
Returns upper limit of allowed times. This is minimum of value set by Max and default maximum (GetDefaultMax).
static Time GetDefaultMin()
Returns Date::GetDefaultMin converted to Time.
static Time GetDefaultMax()
Returns Date::GetDefaultMax converted to Time.
bool IsNotNull() const
|
Return value |
true means Nulls are disallowed. |
class ConvertDouble : public Convert
Floating point number converter.
Derived from Convert
ConvertDouble(double minval = -std::numeric_limits<double>::max(), double maxval = std::numeric_limits<double>::max(), bool notnull = false)
Constructor.
|
minval |
Lower limit - default value means there is no limit. |
|
maxval |
Upper limit - default value means there is no limit. |
|
notnull |
If true, Nulls are not allowed. |
~ConvertDouble()
Default destructor.
ConvertDouble& Pattern(const char *p)
Formatting tag used for conversion to textual representation (includes standard printf formatting tags, see Format function for description). Default tag is %.10g. After setting a new pattern, ConvertDouble formats simple example number (Format(1.1)) and if it detects character ',' in resulting string, Filter method forces ',' to be used instead of '.' for decimal point.
ConvertDouble& MinMax(double _min, double _max)
Sets minimal and maximal allowed numbers.
ConvertDouble& Min(double _min)
Sets minimal allowed number.
ConvertDouble& Max(double _max)
Sets maximal allowed number.
ConvertDouble& NotNull(bool b = true)
Allows/disallows Nulls. (Nulls are represented by the empty text).
ConvertDouble& NoNotNull()
Equivalent to NotNull(false).
double GetMin() const
|
Return value |
Lower limit. |
double GetMax() const
|
Return value |
Upper limit. |
bool IsNotNull() const
|
Return value |
true is Nulls are disallowed. |
struct ConvertFloat : public ConvertDouble
This helper class changes precision of double->text conversion to 7 digits to reflect the precision of float type.
static double GetDefaultMin()
Returns the minimal number representable by float.
static double GetDefaultMax()
Returns the maximal number representable by float.
ConvertFloat(double minval = GetDefaultMin(), double maxval = GetDefaultMax(), bool notnull = false)
minval maxval notnull .
class ConvertInt : public Convert
Integer converter.
Derived from Convert
ConvertInt(int minval = -INT_MAX, int maxval = INT_MAX, bool notnull = false)
Constructor.
|
minval |
Lower limit. Default value results in no limit. |
|
maxval |
Upper limit. Default value results in no limit. |
|
notnull |
If true, Nulls are not allowed. |
~ConvertInt()
Default destructor.
ConvertInt& MinMax(int _min, int _max)
Sets minimal and maximal allowed numbers.
ConvertInt& Min(int _min)
Sets minimal allowed number.
ConvertInt& Max(int _max)
Sets maximal allowed number.
ConvertInt& NotNull(bool b = true)
Allows/disallows Nulls. (Nulls are represented by the empty text).
ConvertInt& NoNotNull()
Equivalent to NotNull(false).
int GetMin() const
|
Return value |
Lower limit. |
int GetMax() const
|
Return value |
Upper limit. |
bool IsNotNull() const
|
Return value |
true if null are not allowed. |
class ConvertString : public Convert
String "converter". Of course, String already is textual representation of itself, the real purpose of this class is to introduce constraints of String value.
Derived from Convert
ConvertString(int maxlen = INT_MAX, bool notnull = false)
Constructor.
|
maxlen |
Maximum length - default is unlimited. |
|
notnull |
If true, empty strings are not allowed. |
~ConvertString()
Default destructor.
ConvertString& MaxLen(int _maxlen)
Sets maximum length of String allowed.
int GetMaxLength() const
|
Return value |
Maximum length of String allowed. |
ConvertString& NotNull(bool b = true)
Disallows empty Strings.
ConvertString& NoNotNull()
Same as NotNull(false).
bool IsNotNull() const
|
Return value |
true mean empty Strings are not allowed. |
ConvertString& TrimLeft(bool b = true)
ConvertString& TrimRight(bool b = true)
ConvertString& TrimBoth(bool b = true)
Whitechars on the left/right/both side(s) are removed before checking count of characters or nullness.
bool IsTrimLeft() const
bool IsTrimRight() const
Checks whether TrimLeft or TrimRight (or both) is active.
class FormatConvert : public Convert
This unidirectional Convert class (only Format direction implemented) converts single Value or ValueArray using Format function and specified formatter pattern.
Derived from Convert
void SetFormat(const char *fmt)
Sets formatting pattern.
class JoinConvert : public Convert
This unidirectional Convert class (only Format direction is implemented) converts ValueArray using a set of other Convert instances. Resulting textual representation is created by joining a set of defined elements - some of them static texts, others referring to elements of input ValueArray, converted using specified Convert.
Derived from Convert
JoinConvert& Add(const char *text)
Adds static text to the list of elements.
JoinConvert& Add(int pos, const Convert& cv)
Add element referring to input value, to be converted using specified Convert.
|
pos |
Index of input ValueArray element. |
JoinConvert& Add(int pos)
Add element referring to input value, to be converted using default Convert.
|
pos |
Index of input ValueArray element. |
JoinConvert& Add(const Convert& cv)
Add element referring to input value, to be converted using specified Convert. Index of input element is the index of previous input element plus 1.
JoinConvert& Add()
Add element referring to input value, to be converted using default Convert. Index of input element is the index of previous input element plus 1.
Standard converts are simple global functions returning a constant reference to the single global variable representing the particular Convert class. Following table lists names of these functions and respective constructors of Convert classes used to create global variable:
const Convert& StdConvert()
Convert
const ConvertInt& StdConvertInt()
ConvertInt
const ConvertInt& StdConvertIntNotNull()
ConvertInt(-INT_MAX, INT_MAX, true)
const ConvertDouble& StdConvertDouble()
ConvertDouble
const ConvertDouble& StdConvertDoubleNotNull()
ConvertDouble(-DOUBLE_NULL_LIM, DOUBLE_NULL_LIM, true)
const ConvertDate& StdConvertDate()
ConvertDate
const ConvertDate& StdConvertDateNotNull()
ConvertDate(Date(0, 0, 0), Date(3000, 12, 31), true)
const ConvertTime& StdConvertTime()
ConvertTime
const ConvertTime& StdConvertTimeNotNull()
ConvertTime(Null, Null, true)
const ConvertString& StdConvertString()
ConvertString
const ConvertString& StdConvertStringNotNull()
ConvertString(INT_MAX, true)
template <typename F, typename S, class R>
const auto& LambdaConvert(F format, S scan, R filter)
template <typename F, typename S>
const auto& LambdaConvert(F format, S scan)
template <typename F>
const auto& LambdaConvert(F format)
Returns a reference to a static Convert instance that has Format/Scan/Filter defined as lambda expressions.
|