UFNumber is a UFObject that holds a number which has an allowed range of values, a specified accuracy and default value. More...
#include <ufobject.h>
Public Member Functions | |
UFNumber (UFName name, double minimum, double maximum, double defaultValue, int accuracyDigits=-1, double step=0.0, double jump=0.0) | |
Construct a UFNumber whose initial value is set to its default value. | |
const char * | StringValue () const |
Translate object to a string. | |
double | DoubleValue () const |
Return the numerical value of the object. | |
void | Set (const UFObject &object) |
void | Set (const char *string) |
Set the value of the object from the string value. | |
void | Set (double number) |
Set the value of the object to the given number. | |
bool | IsDefault () const |
Return true if object has its default value. | |
void | SetDefault () |
Set the current object value to its default value. | |
void | Reset () |
Reset the object value to its default value. | |
bool | IsEqual (double number) const |
Return true if object value is equal to number up to the prescribed accuracy. | |
double | Minimum () const |
double | Maximum () const |
int | AccuracyDigits () const |
double | Step () const |
double | Jump () const |
UFNumber is a UFObject that holds a number which has an allowed range of values, a specified accuracy and default value.
UFNumber::UFNumber | ( | UFName | name, | |
double | minimum, | |||
double | maximum, | |||
double | defaultValue, | |||
int | accuracyDigits = -1 , |
|||
double | step = 0.0 , |
|||
double | jump = 0.0 | |||
) |
Construct a UFNumber whose initial value is set to its default value.
The number of accuracy digits effects the format of the StringValue() of the number. The IsEqual() test is also controlled by accuracyDigits. step and jump have no direct effect on the object. They are useful for constructing a GtkAdjustment as in ufnumber_hscale_new() and ufnumber_spin_button_new().
accuracyDigits, step and jump are optional arguments, if they are not given they will be automatically generated. accuracyDigits will be calculated from minimum, maximum to given between 3 and 4 significant digits. step will be set to 10 times the accuracy and jump to 10 times step.
const char* UFNumber::StringValue | ( | ) | const [virtual] |
double UFNumber::DoubleValue | ( | ) | const |
Return the numerical value of the object.
This double value can have better accuracy than accuracyDigits. So, for example, after an object.Set(1.0/3.0)
command, the result of the condition (obj.DoubleValue() == 1.0/3.0)
should be true (but it is never safe to rely on such behavior for floating-point numbers).
void UFNumber::Set | ( | const UFObject & | object | ) |
void UFNumber::Set | ( | const char * | string | ) | [virtual] |
Set the value of the object from the string value.
This is the reverse of the StringValue() method. If the value changes, an uf_value_changed event is triggered.
UFException | is thrown if the the string can not be converted to the object type. This could result from a user input error. |
Implements UFObject.
void UFNumber::Set | ( | double | number | ) |
Set the value of the object to the given number.
If the number is outside of the allowed range, the number will be truncated and the Message() method will be called to report this incident.
bool UFNumber::IsDefault | ( | ) | const [virtual] |
Return true if object has its default value.
For numerical objects, the values has to the same up to the prescribed accuracy.
Implements UFObject.
void UFNumber::SetDefault | ( | ) | [virtual] |
Set the current object value to its default value.
A uf_default_changed event is triggered.
Implements UFObject.
void UFNumber::Reset | ( | ) | [virtual] |
Reset the object value to its default value.
If the value changes, a uf_value_changed event is triggered.
Implements UFObject.
bool UFNumber::IsEqual | ( | double | number | ) | const |
Return true if object value is equal to number up to the prescribed accuracy.
double UFNumber::Minimum | ( | ) | const |
double UFNumber::Maximum | ( | ) | const |
int UFNumber::AccuracyDigits | ( | ) | const |
double UFNumber::Step | ( | ) | const |
double UFNumber::Jump | ( | ) | const |