34#ifndef _UTILS_ENTRYMODEL_HXX_
35#define _UTILS_ENTRYMODEL_HXX_
55 ,
valueMin_(std::numeric_limits<T>::lowest())
56 ,
valueMax_(std::numeric_limits<T>::max())
96 void init(
unsigned max_size,
int base, T value,
bool automatic_clamp =
true)
160 push_back(c <=
'9' ? c -
'0' : c -
'A' + 10);
214 HASSERT(base == 10 || base == 16);
229 if (std::is_signed<T>::value)
231 value_ = strtoll(str.c_str(),
nullptr, base);
235 value_ = strtoull(str.c_str(),
nullptr, base);
332 if (std::is_signed<T>::value)
334 str = int64_to_string(
value_);
338 str = uint64_to_string(
value_);
342 if (std::is_signed<T>::value)
344 str = int64_to_string_hex(
value_);
348 str = uint64_to_string_hex(
value_);
351 transform(str.begin(), str.end(), str.begin(), toupper);
360 if (right_justify && str.size() <
maxSize_)
362 str.insert(0,
maxSize_ - str.size(),
' ');
400 virtual void clamp(
bool force =
false)
430 if (
value_ < std::numeric_limits<T>::max())
445 if (
value_ > std::numeric_limits<T>::lowest())
471 for (
unsigned i = 0; i <
maxSize_; ++i)
528 void init(
unsigned max_size,
int base, T value, T min, T max, T default_val,
529 bool automatic_clamp =
true)
550 void clamp(
bool force =
false)
override
Specialization of EntryModel with upper and lower bounds.
EntryModelBounded()
Constructor.
void set_default()
Set the value to the default.
void clamp(bool force=false) override
Clamp the value at the min or max.
T valueDefault_
default value
void init(unsigned max_size, int base, T value, T min, T max, T default_val, bool automatic_clamp=true)
Initialize with a value.
void set_boundaries() override
Override base class to do nothing.
Implementation of a text entry menu.
bool empty()
Test if the entry is "empty".
unsigned isAtInitialValue_
true if still has the initial value
unsigned maxSize_
maximum number of digits
string get_string(bool right_justify=false)
Get the value as a string.
void push_back_char(char c)
Append a character to the "back".
EntryModel & append_char(char c)
Append a character to the "back".
unsigned numLeadingZeros_
number of leading zeros
bool is_at_initial_value()
Determine if this object is holding an initial or modified value.
void calculate_size()
Calculate the size in digits.
T value_
present value held
void pop_back()
Removes (deletes) a character off the end.
void change_sign()
Change the sign of the data.
void clear()
Clear the entry string.
void init(unsigned max_size, int base)
Initialize empty.
void set_leading_zeros(unsigned num)
Sets the number of leading zeros without changing the value.
T valueMin_
minimum value representable by maxSize_
void set_min()
Set the value to the minimum.
T operator--()
Pre-decrement value.
T operator++()
Pre-increment value.
bool cursor_visible()
Test if cursor is visible.
EntryModel & append(uint8_t val)
Append a value to the "back".
T get_value(bool force_clamp=false)
Get the entry as an unsigned integer value.
void auto_clamp(bool force=false)
Calls clamp() only if automatic clamping is enabled (autoClamp_ = true).
virtual void clamp(bool force=false)
Clamp the value at the min or max.
unsigned autoClamp_
true to auto clamp the values
void init(unsigned max_size, int base, T value, bool automatic_clamp=true)
Initialize with a value.
virtual void set_boundaries()
Set min and max boundaries supported based on maxSize_ (digit count).
unsigned empty_
true if the value_ is "empty"
void set_base(int base, bool convert)
Set the radix base.
size_t max_size()
Get the max size (in digits).
size_t size()
Get the size (actual number of digits).
bool has_leading_zeros()
It is not always possible with get_string() to return the leading zeros.
void set_value(T value)
Set the value, keep the max number of digits and base the same.
void push_back(uint8_t val)
Append a value to the "back".
T valueMax_
maximum value representable by maxSize_
unsigned size_
actual number of digits
void set_max()
Set the value to the maximum.
void set_base(int base)
Set the radix base.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.