Convert
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
virtual Value Scan(const Value& text) const
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).
Date GetMin() const
|
Return value |
Minimal allowed date. |
Date GetMax() const
|
Return value |
Maximal allowed date. |
bool IsNotNull() const
|
Return value |
true is Nulls are disallowed. |
ConvertDate(Date minval = Date(0, 0, 0), Date maxval = Date(9999, 12, 31), bool notnull = false)
Constructor.
|
minval |
Minimum Date allowed. |
|
maxval |
Maximum Date allowed. |
class ConvertDouble : public Convert
Floating point number converter.
Derived from Convert
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.
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. |
ConvertDouble(double minval = DOUBLE_NULL_LIM, double maxval = -DOUBLE_NULL_LIM, 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. |
class ConvertInt : public Convert
Integer converter.
Derived from Convert
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. |
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. |
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& 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(int maxlen = INT_MAX, bool notnull = false)
Constructor.
|
maxlen |
Maximum length - default is unlimited. |
|
notnull |
If true, empty strings are not allowed. |
class ConvertTime : public Convert
Time converter.
Derived from Convert
ConvertTime& MinMax(Time _min, Time _max)
Time limeits.
ConvertTime& NotNull(bool b = true)
Disallows empty Strings.
ConvertTime& NoNotNull()
Same as NotNull(false).
Time GetMin() const
|
Return value |
Lower limit. |
Time GetMax() const
|
Return value |
Upper limit. |
bool IsNotNull() const
|
Return value |
true means Nulls are disallowed. |
ConvertTime(Time minval = Null, Time maxval = Null, 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. |
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
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
|
Function name
|
Definition
|
StdConvert
|
Convert
|
StdConvertInt
|
ConvertInt
|
StdConvertIntNotNull
|
ConvertInt(-INT_MAX, INT_MAX, true)
|
StdConvertDouble
|
ConvertDouble
|
StdConvertDoubleNotNull
|
ConvertDouble(-DOUBLE_NULL_LIM, DOUBLE_NULL_LIM, true)
|
StdConvertDate
|
ConvertDate
|
StdConvertDateNotNull
|
ConvertDate(Date(0, 0, 0), Date(3000, 12, 31), true)
|
StdConvertTime
|
ConvertTime
|
StdConvertTimeNotNull
|
ConvertTime(Null, Null, true)
|
StdConvertString
|
ConvertString
|
StdConvertStringNotNull
|
ConvertString(INT_MAX, true)
|
|
|
|