special digxel to represent the sign
This commit is contained in:
parent
38844b9050
commit
ce420a1570
2 changed files with 48 additions and 2 deletions
|
|
@ -175,6 +175,14 @@ namespace time {
|
|||
CountFormatter() : PrintfFormatter<long,20>("%04ld") { }
|
||||
};
|
||||
|
||||
|
||||
struct SignFormatter
|
||||
{
|
||||
void clear() { }
|
||||
size_t maxlen() const { return 1; }
|
||||
CBuf show (int val) { return val<0? "-":" "; }
|
||||
};
|
||||
|
||||
} //(End) digxel configuration namespace
|
||||
|
||||
|
||||
|
|
@ -273,7 +281,25 @@ namespace time {
|
|||
/* == predefined Digxel configurations == */
|
||||
typedef Digxel< int, digxel::SexaFormatter> SexaDigit; ///< for displaying time components (sexagesimal)
|
||||
typedef Digxel<uint, digxel::HexaFormatter> HexaDigit; ///< for displaying a hex byte
|
||||
typedef Digxel<long, digxel::CountFormatter> CountVal; ///< for displaying a hex byte
|
||||
typedef Digxel<long, digxel::CountFormatter> CountVal; ///< for displaying a counter
|
||||
|
||||
|
||||
/** special Digxel to show a sign.
|
||||
* @note values limited to +1 and -1 */
|
||||
struct Signum
|
||||
: Digxel<int,digxel::SignFormatter>
|
||||
{
|
||||
Signum() { setValueRaw(1); }
|
||||
|
||||
void
|
||||
operator= (int n)
|
||||
{
|
||||
int newSign = 0 > mutator(n)? -1:+1;
|
||||
this->setValueRaw (newSign);
|
||||
}
|
||||
|
||||
friend int operator*= (Signum s, int c) { s = c*s; return s; }
|
||||
};
|
||||
|
||||
|
||||
}} // lib::time
|
||||
|
|
|
|||
|
|
@ -69,7 +69,27 @@ namespace test{
|
|||
verifyConfiguration<HexaDigit > (0xc);
|
||||
verifyConfiguration<HexaDigit > (0x6f);
|
||||
verifyConfiguration<CountVal > (-1234567890);
|
||||
}
|
||||
|
||||
verifySignum();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
verifySignum()
|
||||
{
|
||||
Signum sig;
|
||||
CHECK (1 == sig);
|
||||
|
||||
sig = 123;
|
||||
CHECK (1 == sig);
|
||||
sig = -sig;
|
||||
CHECK (-1 == sig);
|
||||
sig = -98;
|
||||
CHECK (-1 == sig);
|
||||
CHECK (sig.show() == string("-"));
|
||||
sig *= -1;
|
||||
CHECK (sig.show() == string("-"));
|
||||
}
|
||||
|
||||
|
||||
template<class DIX, typename VAL>
|
||||
|
|
|
|||
Loading…
Reference in a new issue