Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

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.

 

 

Public Member List

 

virtual Value Format(const Value& qconst

Converts the Value. Default implementation uses Value::ToString to convert the Value.

q

Value.

Return value

Converted Value.

 


 

virtual Value Scan(const Value& textconst

Converts the Value in reverse direction. Default implementation returns text (no conversion is performed).

text

Value.

Return value

Converted Value.

 


 

virtual int Filter(int chrconst

Adjusts characters allowed in textual representation of Value.

chr

Character to adjust.

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& qconst

Invokes the Format method. Helper functor-like syntax.

q

Value.

Return value

Converted Value.

 

 

 

 

ConvertDate

 

class ConvertDate : public Convert

Date Converter. Textual date format depends on actual regional settings.

 

Derived from Convert

 

 

Constructor Detail

 

ConvertDate(Date minval = Date::Low(), Date maxval = Date::High(), bool notnull = false)

Constructor.

minval

Minimum Date allowed.

maxval

Maximum Date allowed.

notnull

Disallow Nulls.

 


 

~ConvertDate()

Default destructor.

 

 

Public Member List

 

ConvertDate& MinMax(Date _min, Date _max)

Sets the range of Dates allowed.

_min

Minimal Date.

_max

Maximal Date.

Return value

*this.

 


 

ConvertDate& Min(Date _min)

Sets minimal allowed Date.

_min

Minimal Date.

Return value

*this.

 


 

ConvertDate& Max(Date _max)

Sets maximal allowed Date.

_max

Maximal Date.

Return value

*this.

 


 

ConvertDate& NotNull(bool b = true)

Allows/disallows Null dates. (Null dates are represented by the empty text).

b

true to disallow Null dates.

Return value

*this.

 


 

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.

 

 

 

 

ConvertTime

 

class ConvertTime : public Convert

Time converter.

 

Derived from Convert

 

 

Constructor Detail

 

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.

 

 

Public Member List

 

ConvertTime& MinMax(Time _min, Time _max)

Time limeits.

_min

Lower limit.

_max

Upper limit.

Return value

*this.

 


 

ConvertTime& Min(Time _min)

Sets lower limit.

 


 

ConvertTime& Max(Time _max)

Sets upper limit.

 


 

ConvertTime& NotNull(bool b = true)

Disallows empty Strings.

b

true to disallow.

Return value

*this.

 


 

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.

 

 

 

ConvertDouble

 

class ConvertDouble : public Convert

Floating point number converter.

 

Derived from Convert

 

 

Constructor Detail

 

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.

 


 

~ConvertDouble()

Default destructor.

 

 

Public Member List

 

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.

p

Pattern.

Return value

*this.

 


 

ConvertDouble& MinMax(double _min, double _max)

Sets minimal and maximal allowed numbers.

_min

Lower limit.

_max

Upper limit.

Return value

*this.

 


 

ConvertDouble& Min(double _min)

Sets minimal allowed number.

_min

Lower limit.

Return value

*this.

 


 

ConvertDouble& Max(double _max)

Sets maximal allowed number.

_max

Upper limit.

Return value

*this.

 


 

ConvertDouble& NotNull(bool b = true)

Allows/disallows Nulls. (Nulls are represented by the empty text).

b

true to disallow.

Return value

*this.

 


 

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.

 

 

 

 

ConvertInt

 

class ConvertInt : public Convert

Integer converter.

 

Derived from Convert

 

 

Constructor Detail

 

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.

 

 

Public Member List

 

ConvertInt& MinMax(int _min, int _max)

Sets minimal and maximal allowed numbers.

_min

Lower limit.

_max

Upper limit.

Return value

*this.

 


 

ConvertInt& Min(int _min)

Sets minimal allowed number.

_min

Lower limit.

Return value

*this.

 


 

ConvertInt& Max(int _max)

Sets maximal allowed number.

_max

Upper limit.

Return value

*this.

 


 

ConvertInt& NotNull(bool b = true)

Allows/disallows Nulls. (Nulls are represented by the empty text).

b

true to disallow.

Return value

*this.

 


 

ConvertInt& NoNotNull()

Equivalent to NotNull(false).

Return value

*this.

 


 

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.

 

 

 

 

ConvertString

 

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

 

 

Constructor Detail

 

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.

 

 

Public Member List

 

ConvertString& MaxLen(int _maxlen)

Sets maximum length of String allowed.

_maxlen

Length.

Return value

*this.

 


 

int GetMaxLength() const

Return value

Maximum length of String allowed.

 


 

ConvertString& NotNull(bool b = true)

Disallows empty Strings.

b

true to disallow.

Return value

*this.

 


 

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.

 

 

 

FormatConvert

 

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

 

 

Public Member List

 

void SetFormat(const char *fmt)

Sets formatting pattern.

fmt

The pattern.

 

 

 

 

JoinConvert

 

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

 

 

Public Member List

 

JoinConvert& Add(const char *text)

Adds static text to the list of elements.

text

Text.

Return value

*this.

 


 

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.

cv

Convert.

Return value

*this.

 


 

JoinConvert& Add(int pos)

Add element referring to input value, to be converted using default Convert.

pos

Index of input ValueArray element.

Return value

*this.

 


 

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.

cv

Convert.

Return value

*this.

 


 

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.

Return value

*this.

 

 

 

 

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:

 

 

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)

 

 

Last edit by cxl on 07/11/2018. Do you want to contribute?. T++