diff --git a/src/lib/time/formats.hpp b/src/lib/time/formats.hpp index 7ded43c77..e374c407d 100644 --- a/src/lib/time/formats.hpp +++ b/src/lib/time/formats.hpp @@ -28,10 +28,10 @@ #include "lib/meta/no-instance.hpp" #include "lib/meta/typelist.hpp" #include "lib/meta/generator.hpp" +#include "lib/typed-counter.hpp" -//#include #include -#include +#include namespace lib { @@ -150,10 +150,14 @@ namespace time { + /* == Descriptor to define Support for specific formats == */ + using lumiera::typelist::Types; - + using lumiera::typelist::Node; + using lumiera::typelist::NullType; + /** - * Denote support for a specific (timecode) format. + * Descriptor to denote support for a specific (timecode) format. * This helper can be used to configure a selection of specific * timecode formats to be or not to be supported by some facility. * Formats are described by the format descriptor types defined in @@ -161,25 +165,66 @@ namespace time { * establishes an numeric ID at runtime and uses a bitset to keep * track of the support for a given format. * - * @todo WIP-WIP-WIP + * @note preconfigured limit #MAXID on the absolute number of + * different Format types; maybe needs to be increased accordingly. + * @warning the actual numeric IDs might vary on each run + * @see TypedContext */ class Supported { - public: - template - static Supported - formats(); + enum { MAXID = 8 }; + + std::bitset flags_; + template + size_t + typeID() + { + return TypedContext::ID::get(); + } + + template + Supported + define(Node) ///< @internal set the flag for one Format in the typelist + { + flags_.set (typeID()); + return define(FS()); + } + Supported define(NullType) { return *this;} ///< recursion end + + Supported() { } ///< @note use #formats to set up a new descriptor + + + public: + /** build a new Descriptor to denote support for all the Formats, + * @param TY typelist holding all the Format types to support + */ + template + static Supported + formats() + { + typedef typename TY::List SupportedFormats; + return Supported().define(SupportedFormats()); + } + + /** check if a specific Format is supported */ template bool - check(); + check() + { + return flags_[typeID()]; + } }; + /** + * predefined standard configuration: + * Descriptor for supporting all the classical timecode formats + */ struct SupportStandardTimecode : Supported { SupportStandardTimecode() - : Supported(formats >()) + : Supported(formats< Types >()) { } }; diff --git a/tests/40components.tests b/tests/40components.tests index 97bacd935..490730d84 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -668,6 +668,11 @@ return: 0 END +TEST "Defining Suppport for specific timecode formats" FormatSupport_test < -//#include - -//using std::rand; -//using std::cout; -//using std::endl; - namespace lib { namespace time { namespace format{ namespace test { - namespace { - - } /******************************************************** @@ -54,8 +44,8 @@ namespace test { run (Arg) { SupportStandardTimecode just_fine; - Supported just_smpte = Supported::formats >(); - Supported just_simple = Supported::formats >(); + Supported just_smpte = Supported::formats< Types >(); + Supported just_simple = Supported::formats< Types >(); Supported& support1 (just_fine); Supported& support2 (just_smpte);