WIP extract the hash ID draft into separate header & test

This commit is contained in:
Fischlurch 2009-05-22 02:40:20 +02:00
parent 0802d969cc
commit 020636b90a
5 changed files with 203 additions and 65 deletions

126
src/lib/ha-id.hpp Normal file
View file

@ -0,0 +1,126 @@
/*
HA-ID.hpp - generic hash based and hierarchically typed ID
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file ha-id.hpp
**
** @see HaID_test
** @see Placement usage example
**
*/
#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 <tr1/memory>
namespace lib {
// using std::tr1::shared_ptr;
/** @todo WIP a generic hash-index, maybe also usable for assets */
struct LuidH
{
long dummy_;
};
template<typename T, class BA>
struct HaID;
template<class BA>
struct HaIndexed
{
LuidH id_;
HaID<BA,BA> const& getID() const;
};
template<class BA>
struct HaID<BA,BA> : LuidH
{
HaID () : LuidH () {}
HaID (BA const& ref) : LuidH (ref.getID()) {}
};
template<typename T, class BA>
struct HaID : HaID<BA,BA>
{
HaID () : HaID<BA,BA> () {}
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

View file

@ -45,57 +45,6 @@ namespace mobject {
// using std::tr1::shared_ptr;
/** @todo WIP a generic hash-index, maybe also usable for assets */
struct LuidH
{
long dummy_;
};
template<typename T, class BA>
struct HaID;
template<class BA>
struct HaIndexed
{
LuidH id_;
HaID<BA,BA> const& getID() const;
};
template<class BA>
struct HaID<BA,BA> : LuidH
{
HaID () : LuidH () {}
HaID (BA const& ref) : LuidH (ref.getID()) {}
};
template<typename T, class BA>
struct HaID : HaID<BA,BA>
{
HaID () : HaID<BA,BA> () {}
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
@ -119,8 +68,5 @@ namespace mobject {
} // namespace mobject
#endif

View file

@ -44,15 +44,7 @@ using std::string;
namespace mobject {
namespace session {
namespace test {
using asset::VIDEO;
/** @todo WIP a generic hash-index, maybe also usable for assets */
HaID<TestBB,TestA> hahaBB1;
TestBA bab;
HaID<TestBA,TestA> hahaBA1 (bab);
///////////////////////////////TODO (Experimentation)
/***************************************************************************
@ -69,12 +61,12 @@ namespace test {
run (Arg)
{
/////////////////////////////////TODO
}
}
};
/** Register this test class... */
LAUNCHER (PlacementRef_test, "unit session");
}}} // namespace mobject::session::test

View file

@ -42,6 +42,7 @@ test_lib_SOURCES = \
$(testlib_srcdir)/exceptionerrortest.cpp \
$(testlib_srcdir)/factoryspecialtest.cpp \
$(testlib_srcdir)/factorytest.cpp \
$(testlib_srcdir)/ha-id-test.cpp \
$(testlib_srcdir)/helloworldtest.cpp \
$(testlib_srcdir)/lifecycletest.cpp \
$(testlib_srcdir)/mainsuite.cpp \

73
tests/lib/ha-id-test.cpp Normal file
View file

@ -0,0 +1,73 @@
/*
HaID(Test) - proof-of-concept test for a hash based and typed ID
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#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>
//using boost::format;
//using lumiera::Time;
//using util::contains;
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)
/***************************************************************************
* @test proof-of-concept test for a generic hash based and typed ID struct.
* @see lib::HaID
*/
class HaID_test : public Test
{
virtual void
run (Arg)
{
/////////////////////////////////TODO
}
};
/** Register this test class... */
LAUNCHER (HaID_test, "unit common");
}} // namespace lib::test