implementation complete -- kindof works
there is a problem with the virtual assignment, seems the default policy was picked. Beyond that, the rest of the unit test passes
This commit is contained in:
parent
93ced30770
commit
7686122354
3 changed files with 74 additions and 22 deletions
|
|
@ -183,7 +183,7 @@ namespace test {
|
|||
catch (lumiera::Error& failure)
|
||||
{
|
||||
lumiera_err errorID = lumiera_error(); // reset error flag
|
||||
cerr << "*** Test Failure " << showType(theTest) << endl;
|
||||
cerr << "*** Test Failure " << demangleCxx(showType(theTest)) << endl;
|
||||
cerr << "*** : " << failure.what() << endl;
|
||||
ERROR (test, "Error state %s", errorID);
|
||||
WARN (progress, "Caught exception %s", failure.what());
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@
|
|||
|
||||
#include "lib/meta/typelist.hpp"
|
||||
#include "lib/meta/typelist-util.hpp"
|
||||
#include "lib/meta/generator.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
|
@ -79,6 +80,7 @@ namespace lib {
|
|||
|
||||
template<typename TYPES>
|
||||
class Variant;
|
||||
|
||||
|
||||
namespace { // implementation helpers
|
||||
|
||||
|
|
@ -284,7 +286,7 @@ namespace lib {
|
|||
struct use_if_supports_copy_and_assignment
|
||||
: enable_if< is_move_constructible<X>::value
|
||||
&& is_copy_constructible<X>::value
|
||||
&& !can_use_assignment<X>::value
|
||||
&& can_use_assignment<X>::value
|
||||
,X
|
||||
>
|
||||
{ };
|
||||
|
|
@ -322,6 +324,18 @@ namespace lib {
|
|||
};
|
||||
|
||||
|
||||
|
||||
template<class VAL>
|
||||
struct ValueAcceptInterface
|
||||
{
|
||||
virtual void handle(VAL&) { /* NOP */ };
|
||||
};
|
||||
|
||||
template<typename TYPES>
|
||||
using VisitorInterface
|
||||
= meta::InstantiateForEach<typename TYPES::List, ValueAcceptInterface>;
|
||||
|
||||
|
||||
}//(End) implementation helpers
|
||||
|
||||
|
||||
|
|
@ -340,8 +354,18 @@ namespace lib {
|
|||
template<typename TYPES>
|
||||
class Variant
|
||||
{
|
||||
public:
|
||||
enum { SIZ = meta::maxSize<typename TYPES::List>::value };
|
||||
|
||||
class Visitor
|
||||
: public VisitorInterface<TYPES>
|
||||
{
|
||||
public:
|
||||
virtual ~Visitor() { } ///< this is an interface
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
/** Inner capsule managing the contained object (interface) */
|
||||
struct Buffer
|
||||
: VirtualCopySupportInterface<Buffer>
|
||||
|
|
@ -353,6 +377,8 @@ namespace lib {
|
|||
|
||||
virtual ~Buffer() {} ///< this is an ABC with VTable
|
||||
|
||||
virtual void dispatch (Visitor&) =0;
|
||||
virtual operator string() const =0;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -434,6 +460,16 @@ namespace lib {
|
|||
else
|
||||
return *buff;
|
||||
}
|
||||
|
||||
void
|
||||
dispatch (Visitor& visitor)
|
||||
{
|
||||
ValueAcceptInterface<TY>& typeDispatcher = visitor;
|
||||
typeDispatcher.handle (this->access());
|
||||
}
|
||||
|
||||
/** diagnostic helper */
|
||||
operator string() const;
|
||||
};
|
||||
|
||||
enum{ BUFFSIZE = sizeof(Buffer) };
|
||||
|
|
@ -538,14 +574,9 @@ namespace lib {
|
|||
}
|
||||
|
||||
|
||||
#ifdef LIB_TEST_TEST_HELPER_H
|
||||
/* == diagnostic helper == */
|
||||
/** diagnostic helper */
|
||||
operator string() const;
|
||||
|
||||
operator string() const
|
||||
{
|
||||
UNIMPLEMENTED("diagnostic string conversion");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* === Access === */
|
||||
|
||||
|
|
@ -560,20 +591,40 @@ namespace lib {
|
|||
}
|
||||
|
||||
|
||||
class Visitor
|
||||
{
|
||||
public:
|
||||
virtual ~Visitor() { } ///< this is an interface
|
||||
};
|
||||
|
||||
void
|
||||
accept (Visitor& visitor)
|
||||
{
|
||||
UNIMPLEMENTED("visitor style value access");
|
||||
buffer().dispatch (visitor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace lib
|
||||
} // namespace lib
|
||||
|
||||
|
||||
|
||||
/* == diagnostic helper == */
|
||||
|
||||
#ifdef LIB_FORMAT_UTIL_H
|
||||
namespace lib {
|
||||
|
||||
template<typename TYPES>
|
||||
Variant<TYPES>::operator string() const
|
||||
{
|
||||
return string(buffer());
|
||||
}
|
||||
|
||||
template<typename TYPES>
|
||||
template<typename TY>
|
||||
Variant<TYPES>::Buff<TY>::operator string() const
|
||||
{
|
||||
return "Variant|"
|
||||
+ util::str (this->access(),
|
||||
(util::tyStr<TY>()+"|").c_str()
|
||||
);
|
||||
}
|
||||
} // namespace lib
|
||||
|
||||
#endif
|
||||
#endif /*LIB_VARIANT_H*/
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "lib/time/timevalue.hpp"
|
||||
#include "lib/format-util.hpp"
|
||||
#include "lib/variant.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
|
|
@ -106,10 +107,10 @@ namespace test{
|
|||
|
||||
CHECK (contains (string(v0), "Variant"));
|
||||
CHECK (contains (string(v0), "bool"));
|
||||
CHECK (contains (string(v0), "false"));
|
||||
CHECK (contains (string(v0), "0"));
|
||||
|
||||
CHECK (contains (string(v1), "Variant"));
|
||||
CHECK (contains (string(v1), "int64_t"));
|
||||
CHECK (contains (string(v1), "int64_t") || contains (string(v1), "long") );
|
||||
CHECK (contains (string(v1), "11"));
|
||||
|
||||
CHECK (contains (string(v2), "Variant"));
|
||||
|
|
@ -118,7 +119,7 @@ namespace test{
|
|||
|
||||
CHECK (contains (string(v3), "Variant"));
|
||||
CHECK (contains (string(v3), "lib::time::Time"));
|
||||
CHECK (contains (string(v3), "0:00:00:00"));
|
||||
CHECK (contains (string(v3), "0:00:00.000"));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -167,8 +168,8 @@ namespace test{
|
|||
int i_ = 12;
|
||||
TimeVar t_;
|
||||
|
||||
void handle (bool b) { b_ = b; }
|
||||
void handle (Time t) { t_ = t; }
|
||||
void handle (bool& b) { b_ = b; }
|
||||
void handle (Time& t) { t_ = t; }
|
||||
|
||||
void handle (int64_t& i6)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue