Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
EntryModel< T > Class Template Reference

Implementation of a text entry menu. More...

#include <EntryModel.hxx>

Inheritance diagram for EntryModel< T >:
EntryModelBounded< T >

Public Member Functions

 EntryModel ()
 Constructor.
 
void clear ()
 Clear the entry string.
 
void init (unsigned max_size, int base)
 Initialize empty.
 
void init (unsigned max_size, int base, T value, bool automatic_clamp=true)
 Initialize with a value.
 
void push_back (uint8_t val)
 Append a value to the "back".
 
void push_back_char (char c)
 Append a character to the "back".
 
EntryModelappend (uint8_t val)
 Append a value to the "back".
 
EntryModelappend_char (char c)
 Append a character to the "back".
 
void pop_back ()
 Removes (deletes) a character off the end.
 
void set_base (int base)
 Set the radix base.
 
void set_base (int base, bool convert)
 Set the radix base.
 
void set_value (T value)
 Set the value, keep the max number of digits and base the same.
 
size_t size ()
 Get the size (actual number of digits).
 
size_t max_size ()
 Get the max size (in digits).
 
bool empty ()
 Test if the entry is "empty".
 
bool cursor_visible ()
 Test if cursor is visible.
 
bool is_at_initial_value ()
 Determine if this object is holding an initial or modified value.
 
bool has_leading_zeros ()
 It is not always possible with get_string() to return the leading zeros.
 
void set_leading_zeros (unsigned num)
 Sets the number of leading zeros without changing the value.
 
get_value (bool force_clamp=false)
 Get the entry as an unsigned integer value.
 
string get_string (bool right_justify=false)
 Get the value as a string.
 
void set_min ()
 Set the value to the minimum.
 
void set_max ()
 Set the value to the maximum.
 
void change_sign ()
 Change the sign of the data.
 
virtual void clamp (bool force=false)
 Clamp the value at the min or max.
 
operator++ ()
 Pre-increment value.
 
operator-- ()
 Pre-decrement value.
 

Protected Member Functions

void auto_clamp (bool force=false)
 Calls clamp() only if automatic clamping is enabled (autoClamp_ = true).
 
virtual void set_boundaries ()
 Set min and max boundaries supported based on maxSize_ (digit count).
 
void calculate_size ()
 Calculate the size in digits.
 
 DISALLOW_COPY_AND_ASSIGN (EntryModel)
 

Protected Attributes

value_
 present value held
 
valueMin_
 minimum value representable by maxSize_
 
valueMax_
 maximum value representable by maxSize_
 
unsigned numLeadingZeros_: 5
 number of leading zeros
 
unsigned maxSize_: 5
 maximum number of digits
 
unsigned size_: 5
 actual number of digits
 
unsigned isAtInitialValue_: 1
 true if still has the initial value
 
unsigned empty_: 1
 true if the value_ is "empty"
 
unsigned base_: 6
 radix base
 
unsigned autoClamp_: 1
 true to auto clamp the values
 

Detailed Description

template<class T>
class EntryModel< T >

Implementation of a text entry menu.

Template Parameters
Tthe data type up to 64-bits in size, signed or unsigned

Definition at line 49 of file EntryModel.hxx.

Constructor & Destructor Documentation

◆ EntryModel()

template<class T >
EntryModel< T >::EntryModel ( )
inline

Constructor.

Definition at line 53 of file EntryModel.hxx.

Member Function Documentation

◆ append()

template<class T >
EntryModel & EntryModel< T >::append ( uint8_t  val)
inline

Append a value to the "back".

Parameters
valvalue to append, base 10: 0 - 9, base 16: 0x0 - 0xF
Returns
*this

Definition at line 168 of file EntryModel.hxx.

◆ append_char()

template<class T >
EntryModel & EntryModel< T >::append_char ( char  c)
inline

Append a character to the "back".

Parameters
ccharacter to append, base 10: 0 - 9, base 16: 0 - F
Returns
*this

Definition at line 177 of file EntryModel.hxx.

◆ auto_clamp()

template<class T >
void EntryModel< T >::auto_clamp ( bool  force = false)
inlineprotected

Calls clamp() only if automatic clamping is enabled (autoClamp_ = true).

Parameters
forceNormally, clamping doesn't occur if the entry is "empty". However, if force is set to true, we will clamp anyways. force also applies if the value is zero yet there is space for more leading zeros.

Definition at line 459 of file EntryModel.hxx.

◆ calculate_size()

template<class T >
void EntryModel< T >::calculate_size ( )
inlineprotected

Calculate the size in digits.

Definition at line 480 of file EntryModel.hxx.

◆ change_sign()

template<class T >
void EntryModel< T >::change_sign ( )
inline

Change the sign of the data.

Definition at line 380 of file EntryModel.hxx.

◆ clamp()

template<class T >
virtual void EntryModel< T >::clamp ( bool  force = false)
inlinevirtual

Clamp the value at the min or max.

Clamping will not occur if the value is zero and there is space for more leading zeros.

Parameters
forceNormally, clamping doesn't occur if the entry is "empty". However, if force is set to true, we will clamp anyways. force also applies if the value is zero yet there is space for more leading zeros.

Reimplemented in EntryModelBounded< T >.

Definition at line 400 of file EntryModel.hxx.

◆ clear()

template<class T >
void EntryModel< T >::clear ( )
inline

Clear the entry string.

Definition at line 68 of file EntryModel.hxx.

◆ cursor_visible()

template<class T >
bool EntryModel< T >::cursor_visible ( )
inline

Test if cursor is visible.

Returns
true if cursor is visible, else false

Definition at line 273 of file EntryModel.hxx.

◆ empty()

template<class T >
bool EntryModel< T >::empty ( )
inline

Test if the entry is "empty".

Having an initial value is not empty.

Returns
true if empty, else false

Definition at line 266 of file EntryModel.hxx.

◆ get_string()

template<class T >
string EntryModel< T >::get_string ( bool  right_justify = false)
inline

Get the value as a string.

The number of characters will not be trimmed to maxSize_. If trimming is required, it must be done by the caller.

Parameters
right_justifytrue to right justify.

Definition at line 321 of file EntryModel.hxx.

◆ get_value()

template<class T >
T EntryModel< T >::get_value ( bool  force_clamp = false)
inline

Get the entry as an unsigned integer value.

Note, that '0' is returned both when the actual value is '0' and when the entry is "empty". If the caller needs to distinguish between these two states, check for "empty()".

Parameters
force_clampNormally, clamping doesn't occur if the entry is "empty". However, if force is set to true, we will clamp anyways. This may be valuable when wanting an "empty" entry to return a valid value and '0' is out of bounds. The auto clamping setting is ignored.
Returns
value representation of the entry

Definition at line 309 of file EntryModel.hxx.

◆ has_leading_zeros()

template<class T >
bool EntryModel< T >::has_leading_zeros ( )
inline

It is not always possible with get_string() to return the leading zeros.

Furthermore, get_value() does not tell the caller if there are leading zeros. Therefore, this API provides a definitive answer.

Definition at line 288 of file EntryModel.hxx.

◆ init() [1/2]

template<class T >
void EntryModel< T >::init ( unsigned  max_size,
int  base 
)
inline

Initialize empty.

Parameters
max_sizemax number of digits in the base type
basebase type, 10 or 16

Definition at line 80 of file EntryModel.hxx.

◆ init() [2/2]

template<class T >
void EntryModel< T >::init ( unsigned  max_size,
int  base,
value,
bool  automatic_clamp = true 
)
inline

Initialize with a value.

Parameters
max_sizemax number of digits in the base type
basebase type, 10 or 16
valuevalue to initialize with
automatic_clampUnless otherwise specified by the API, enables automatic clamping of the value each time it is modified when true, else automatic clamping is not applied.

Definition at line 96 of file EntryModel.hxx.

◆ is_at_initial_value()

template<class T >
bool EntryModel< T >::is_at_initial_value ( )
inline

Determine if this object is holding an initial or modified value.

Returns
true if if holding an initial value, else false if modified

Definition at line 280 of file EntryModel.hxx.

◆ max_size()

template<class T >
size_t EntryModel< T >::max_size ( )
inline

Get the max size (in digits).

Returns
max size in number of digits

Definition at line 259 of file EntryModel.hxx.

◆ operator++()

template<class T >
T EntryModel< T >::operator++ ( )
inline

Pre-increment value.

While this method does prevent wrap around of the native type limits, it is incumbent on the caller to limit the resulting number of digits. Always clamps, the auto clamping setting is ignroed.

Definition at line 427 of file EntryModel.hxx.

◆ operator--()

template<class T >
T EntryModel< T >::operator-- ( )
inline

Pre-decrement value.

While this method does prevent wrap around of the native type limits, it is incumbent on the caller to limit the resulting number of digits. Always clamps, the auto clamping setting is ignroed.

Definition at line 442 of file EntryModel.hxx.

◆ pop_back()

template<class T >
void EntryModel< T >::pop_back ( )
inline

Removes (deletes) a character off the end.

Definition at line 184 of file EntryModel.hxx.

◆ push_back()

template<class T >
void EntryModel< T >::push_back ( uint8_t  val)
inline

Append a value to the "back".

Parameters
valvalue to append, base 10: 0 - 9, base 16: 0x0 - 0xF

Definition at line 107 of file EntryModel.hxx.

◆ push_back_char()

template<class T >
void EntryModel< T >::push_back_char ( char  c)
inline

Append a character to the "back".

Parameters
ccharacter to append, base 10: 0 - 9, base 16: 0 - F

Definition at line 151 of file EntryModel.hxx.

◆ set_base() [1/2]

template<class T >
void EntryModel< T >::set_base ( int  base)
inline

Set the radix base.

Parameters
basenew radix base to set.

Definition at line 212 of file EntryModel.hxx.

◆ set_base() [2/2]

template<class T >
void EntryModel< T >::set_base ( int  base,
bool  convert 
)
inline

Set the radix base.

Parameters
basenew radix base to set.
convertconvert the current value, as a string, to the new base.

Definition at line 222 of file EntryModel.hxx.

◆ set_boundaries()

template<class T >
virtual void EntryModel< T >::set_boundaries ( )
inlineprotectedvirtual

Set min and max boundaries supported based on maxSize_ (digit count).

Reimplemented in EntryModelBounded< T >.

Definition at line 468 of file EntryModel.hxx.

◆ set_leading_zeros()

template<class T >
void EntryModel< T >::set_leading_zeros ( unsigned  num)
inline

Sets the number of leading zeros without changing the value.

Definition at line 294 of file EntryModel.hxx.

◆ set_max()

template<class T >
void EntryModel< T >::set_max ( )
inline

Set the value to the maximum.

Definition at line 374 of file EntryModel.hxx.

◆ set_min()

template<class T >
void EntryModel< T >::set_min ( )
inline

Set the value to the minimum.

Definition at line 368 of file EntryModel.hxx.

◆ set_value()

template<class T >
void EntryModel< T >::set_value ( value)
inline

Set the value, keep the max number of digits and base the same.

Parameters
valuevalue to initialize with

Definition at line 244 of file EntryModel.hxx.

◆ size()

template<class T >
size_t EntryModel< T >::size ( )
inline

Get the size (actual number of digits).

Note, if the entry is still at its initial value, the result will be 0.

Returns
size actual size in number of digits

Definition at line 252 of file EntryModel.hxx.

Member Data Documentation

◆ autoClamp_

template<class T >
unsigned EntryModel< T >::autoClamp_
protected

true to auto clamp the values

Definition at line 503 of file EntryModel.hxx.

◆ base_

template<class T >
unsigned EntryModel< T >::base_
protected

radix base

Definition at line 502 of file EntryModel.hxx.

◆ empty_

template<class T >
unsigned EntryModel< T >::empty_
protected

true if the value_ is "empty"

Definition at line 501 of file EntryModel.hxx.

◆ isAtInitialValue_

template<class T >
unsigned EntryModel< T >::isAtInitialValue_
protected

true if still has the initial value

Definition at line 500 of file EntryModel.hxx.

◆ maxSize_

template<class T >
unsigned EntryModel< T >::maxSize_
protected

maximum number of digits

Definition at line 498 of file EntryModel.hxx.

◆ numLeadingZeros_

template<class T >
unsigned EntryModel< T >::numLeadingZeros_
protected

number of leading zeros

Definition at line 497 of file EntryModel.hxx.

◆ size_

template<class T >
unsigned EntryModel< T >::size_
protected

actual number of digits

Definition at line 499 of file EntryModel.hxx.

◆ value_

template<class T >
T EntryModel< T >::value_
protected

present value held

Definition at line 493 of file EntryModel.hxx.

◆ valueMax_

template<class T >
T EntryModel< T >::valueMax_
protected

maximum value representable by maxSize_

Definition at line 495 of file EntryModel.hxx.

◆ valueMin_

template<class T >
T EntryModel< T >::valueMin_
protected

minimum value representable by maxSize_

Definition at line 494 of file EntryModel.hxx.


The documentation for this class was generated from the following file: