diff --git a/src/lib/time/digxel.cpp b/src/lib/time/digxel.cpp index 3eea7f927..5c8046de7 100644 --- a/src/lib/time/digxel.cpp +++ b/src/lib/time/digxel.cpp @@ -33,6 +33,10 @@ namespace lib { namespace time { + Digxel::~Digxel () { } + // A hint for the compiler to emit VTables and magic stuff here + + /** */ diff --git a/src/lib/time/digxel.hpp b/src/lib/time/digxel.hpp index af451cbb2..6cdc3888e 100644 --- a/src/lib/time/digxel.hpp +++ b/src/lib/time/digxel.hpp @@ -63,6 +63,7 @@ #define LIB_TIME_DIGXEL_H #include "lib/error.hpp" +//#include "lib/symbol.hpp" //#include #include ////////////////////TODO @@ -72,8 +73,7 @@ namespace lib { namespace time { - using std::string; - +// using std::string; /** * A number element for building structured numeric displays. @@ -89,17 +89,77 @@ namespace time { * @see lib::time::TCode * @todo WIP-WIP-WIP */ - template class Digxel { public: - - string describe() const; - - + virtual ~Digxel (); ///< this is an ABC + }; + namespace digxel { + +// using lib::Literal; + + template + struct PrintfFormatter + { + enum{ len = 6 + , bufsiz = len+1 + }; + + char printbuffer_[bufsiz]; + + static void + show (NUM val) + { + size_t space = std::snprintf (printbuffer_, bufsiz, "%5d", val); + REQUIRE (space <= bufsiz, "Digxel value exceeded available buffer size. " + "For showing %d, %d chars instead of just %d would be required." + , val, space, bufsiz); + } + }; + + template + struct Formatter; + + template<> + struct Formatter + : PrintfFormatter + { + enum{ len = 6 + , bufsiz = len+1 + }; + + }; + + /** + * The outward hull of a concrete Digxel implementation. + * Inheriting from the Digxel interface, it embodies a concrete + * Formatter specialised to yield the desired behaviour. + * + * @param TODO + * @todo WIP-WIP-WIP + */ + template< typename NUM + , class FMT = digxel::Formatter + > + class Holder + : public Digxel + { + FMT buffer_; + NUM value_; + + public: + Holder () + : buffer_() + , value_() + { } + + }; + + } + }} // lib::time diff --git a/tests/lib/time/digxel-test.cpp b/tests/lib/time/digxel-test.cpp index 9707e490a..e5fffccc2 100644 --- a/tests/lib/time/digxel-test.cpp +++ b/tests/lib/time/digxel-test.cpp @@ -55,6 +55,7 @@ namespace test{ const uint REPEAT = 40; const uint RAND_RANGE = 100; const uint RAND_DENOM = 3; + const uint TIMING_CNT = 10000; inline double randomFrac() @@ -63,7 +64,25 @@ namespace test{ arbitrary /= (1 + rand() % RAND_DENOM); return arbitrary; } - + + + /* === special Digxel configuration for this test === */ + + double + limitingMutator (double value2set) + { + return (+1 < value2set) ? 1.0 + : (-1 > value2set) ? -1.0 + : value2set; + } + + + struct VerySpecialFormat + { + + }; + + typedef digxel::Holder TestDigxel; } @@ -79,9 +98,14 @@ namespace test{ class Digxel_test : public Test { virtual void - run (Arg arg) + run (Arg) { - checkSimpleUsage (ref); + checkSimpleUsage (); + checkMutation (); + verifyMutatorInfluence (); + checkCopy (); + checkDisplayOverrun (); + verifyDisplayCaching (); } @@ -114,21 +138,30 @@ namespace test{ double arbitrary = randomFrac(); checksum += arbitrary; - digi.mutate (arbitrary); // invoke the mutation functor + digi = arbitrary; // invoke the mutation functor CHECK (sum == checksum, "divergence after adding %f in iteration %d", arbitrary, i); - CHECK (0 == digi); // the value itself is not touched + CHECK (digi == abitrary); } } void - checkDefaultMutator () + verifyMutatorInfluence () { TestDigxel digi; + // using the default mutator CHECK (0 == digi); - digi.mutate(12.3); + digi = 12.3; + CHECK (12.3 == digi); + + digi.mutator = limitingMutator; + CHECK (12.3 == digi); + digi = 12.3; + CHECK (1 == digi); + + digi.setValueRaw(12.3); CHECK (12.3 == digi); } @@ -159,7 +192,7 @@ namespace test{ TestDigxel digi; digi = 123456789.12345678; - string formatted (digi.show()); + string formatted (digi.show()); // should trigger assertion CHECK (formatted.length() <= digi.maxlen()); }