WIP document the concept of the hash ID, get rid of the uggly cast
This commit is contained in:
parent
020636b90a
commit
bac5da777b
3 changed files with 84 additions and 70 deletions
|
|
@ -21,7 +21,27 @@
|
|||
*/
|
||||
|
||||
|
||||
/** @file ha-id.hpp
|
||||
/** @file ha-id.hpp
|
||||
** A template for generating hash based ID tags carrying compile-time type info.
|
||||
** While the actual storage is assumed to be based on a POD, the type info is crucial
|
||||
** to circumvent the problems with an "object" base class. Frequently, the need to
|
||||
** manage some objects in a central facility drives us to rely on a common base class,
|
||||
** irrespective of an actual common denominator in the semantics of the objects to
|
||||
** be managed within this collection. Typically this results in this common base class
|
||||
** being almost worthless as an API or interface, causing lots of type casts when using
|
||||
** such a common object management facility. Passing additional context or API information
|
||||
** on a metaprogramming level through the management interface helps avoiding these
|
||||
** shortcomings.
|
||||
**
|
||||
** Here we build an ID facility with the following properties:
|
||||
** - based on a configurable storage/implementation of the actual hash or index code.
|
||||
** - tied to a specific hierarchy of objects (template parameter "BA")
|
||||
** - providing an additional template parameter to pass the desired type info
|
||||
** - establishing an type hierarchy relation between ID template instances, such that
|
||||
** the IDs typed to the derived/specialised objects can stand-in for the generic
|
||||
** ID typed to the base class.
|
||||
** - providing a Mixin, which allows any hierarchy to use this facility without
|
||||
** much code duplication.
|
||||
**
|
||||
** @see HaID_test
|
||||
** @see Placement usage example
|
||||
|
|
@ -33,32 +53,50 @@
|
|||
#ifndef LIB_HA_ID_H
|
||||
#define LIB_HA_ID_H
|
||||
|
||||
//#include "pre.hpp"
|
||||
//#include "proc/mobject/session/locatingpin.hpp"
|
||||
//#include "proc/asset/pipe.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
//#include <tr1/memory>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
||||
// using std::tr1::shared_ptr;
|
||||
using std::rand;
|
||||
|
||||
|
||||
/** @todo WIP a generic hash-index, maybe also usable for assets */
|
||||
struct LuidH
|
||||
{
|
||||
long dummy_;
|
||||
|
||||
LuidH() : dummy_(rand()) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic hash based and hierarchically typed ID
|
||||
* @todo WIP maybe also usable for assets?
|
||||
*/
|
||||
template<typename T, class BA>
|
||||
struct HaID;
|
||||
|
||||
template<class BA>
|
||||
struct HaIndexed
|
||||
{
|
||||
LuidH id_;
|
||||
HaID<BA,BA> const& getID() const;
|
||||
typedef HaID<BA,BA> RootID;
|
||||
RootID id_;
|
||||
|
||||
RootID const& getID() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
void resetID(HaIndexed const& ref)
|
||||
{
|
||||
this->id_ = ref.getID();
|
||||
}
|
||||
void resetID(RootID const& ref) ///< @todo this mutator should be removed in the final version to keep the actual hash opaque
|
||||
{
|
||||
this->id_.dummy_ = ref.dummy_;
|
||||
}
|
||||
};
|
||||
|
||||
template<class BA>
|
||||
|
|
@ -75,52 +113,8 @@ namespace lib {
|
|||
HaID (T const& ref) : HaID<BA,BA> (ref) {}
|
||||
};
|
||||
|
||||
template<class BA>
|
||||
inline HaID<BA,BA> const&
|
||||
HaIndexed<BA>::getID() const
|
||||
{
|
||||
return *(static_cast<const HaID<BA,BA>*> (&id_));
|
||||
}
|
||||
|
||||
|
||||
struct Base
|
||||
{
|
||||
int ii_;
|
||||
};
|
||||
|
||||
struct TestA : Base, HaIndexed<TestA>
|
||||
{
|
||||
};
|
||||
struct TestBA : TestA {};
|
||||
struct TestBB : TestA {};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
class PlacementRef
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ID
|
||||
{
|
||||
};
|
||||
|
||||
template<class MO>
|
||||
class IDp : public ID
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace lib
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -215,6 +215,11 @@ out: dtor ~TargetObj(12) successful
|
|||
END
|
||||
|
||||
|
||||
PLANNED "HaID_test" HaID_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
TEST "LifeCycle_test" LifeCycle_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
|
|
|||
|
|
@ -22,33 +22,34 @@
|
|||
|
||||
|
||||
#include "lib/test/run.hpp"
|
||||
//#include "proc/asset/media.hpp"
|
||||
//#include "proc/mobject/session.hpp"
|
||||
//#include "proc/mobject/session/edl.hpp"
|
||||
//#include "proc/mobject/session/testclip.hpp"
|
||||
|
||||
#include "lib/ha-id.hpp"
|
||||
//#include "proc/mobject/explicitplacement.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
//#include <boost/format.hpp>
|
||||
//#include <iostream>
|
||||
#include <boost/format.hpp>
|
||||
#include <iostream>
|
||||
|
||||
//using boost::format;
|
||||
//using lumiera::Time;
|
||||
//using util::contains;
|
||||
using std::string;
|
||||
//using std::cout;
|
||||
using boost::format;
|
||||
//using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
||||
/** @todo WIP a generic hash-index, maybe also usable for assets */
|
||||
HaID<TestBB,TestA> hahaBB1;
|
||||
|
||||
TestBA bab;
|
||||
HaID<TestBA,TestA> hahaBA1 (bab);
|
||||
///////////////////////////////TODO (Experimentation)
|
||||
/* == a hierarchy of test-dummy objects to use the HaID == */
|
||||
|
||||
struct Base
|
||||
{
|
||||
int ii_;
|
||||
};
|
||||
|
||||
struct TestA : Base, HaIndexed<TestA>
|
||||
{
|
||||
};
|
||||
struct TestBA : TestA {};
|
||||
struct TestBB : TestA {};
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
|
|
@ -61,7 +62,21 @@ namespace test{
|
|||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
format fmt ("sizeof( %s ) = %d\n");
|
||||
|
||||
/////////////////////////////////TODO
|
||||
HaID<TestBB,TestA> hahaBB1;
|
||||
|
||||
TestBA bab;
|
||||
bab.resetID(hahaBB1);
|
||||
|
||||
HaID<TestBA,TestA> hahaBA1 (bab);
|
||||
|
||||
cout << fmt % "TestBA" % sizeof(bab);
|
||||
cout << fmt % "ID<TestBA>" % sizeof(hahaBA1);
|
||||
cout << fmt % "ID<TestBB>" % sizeof(hahaBB1);
|
||||
|
||||
ASSERT (hahaBA1.dummy_ == hahaBB1.dummy_);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue