try out a recursive approach for the extensible ID
more of a general feasability study... to be continued later
This commit is contained in:
parent
455ee34344
commit
c3d767b444
2 changed files with 88 additions and 4 deletions
|
|
@ -33,6 +33,9 @@
|
|||
** - possibility of structured adornments and variations
|
||||
** - optionally concealing these extensions from the interface level
|
||||
**
|
||||
** The first attempt to build such an entity is based on standard techniques,
|
||||
** disregarding performance and memory footprint considerations.
|
||||
**
|
||||
** @see SubID_test
|
||||
** @see MultiFact
|
||||
**
|
||||
|
|
@ -43,11 +46,17 @@
|
|||
#ifndef LIB_SUB_ID_H
|
||||
#define LIB_SUB_ID_H
|
||||
|
||||
#include "lib/format.hpp"
|
||||
|
||||
//#include <functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
||||
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
|
||||
|
||||
|
||||
|
|
@ -55,11 +64,65 @@ namespace lib {
|
|||
*
|
||||
*/
|
||||
template<typename I>
|
||||
struct SubID
|
||||
class SubId;
|
||||
|
||||
class SubID
|
||||
{
|
||||
public:
|
||||
virtual ~SubID() { }
|
||||
|
||||
virtual operator string() const =0;
|
||||
};
|
||||
|
||||
|
||||
ostream&
|
||||
operator<< (ostream& os, SubID const& sID)
|
||||
{
|
||||
return os << string(sID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename I>
|
||||
class SubId
|
||||
: public SubID
|
||||
{
|
||||
I baseID_;
|
||||
|
||||
public:
|
||||
SubId (I id)
|
||||
: baseID_(id)
|
||||
{ }
|
||||
|
||||
operator string() const
|
||||
{
|
||||
return util::str (baseID_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename I, class SUZ>
|
||||
class ExtendedSubId
|
||||
: public SubId<I>
|
||||
{
|
||||
typedef SubId<I> _baID;
|
||||
|
||||
SUZ extID_;
|
||||
|
||||
public:
|
||||
ExtendedSubId (I i, SUZ const& chain)
|
||||
: _baID(i)
|
||||
, extID_(chain)
|
||||
{ }
|
||||
|
||||
operator string() const
|
||||
{
|
||||
return _baID::operator string()
|
||||
+ '.'
|
||||
+ string (extID_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <string>
|
||||
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
||||
|
|
@ -41,10 +42,14 @@ namespace test{
|
|||
using boost::hash;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
namespace { // test data
|
||||
|
||||
enum Colour { R,G,B };
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -64,11 +69,11 @@ namespace test{
|
|||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
UNIMPLEMENTED ("SubID brainstorming");
|
||||
|
||||
checkBaseType();
|
||||
checkExtension();
|
||||
|
||||
TODO ("Hash functions, better implementation");
|
||||
// buildHashtable<ID_A> (buildIDs<ID_A>() );
|
||||
// buildHashtable<ID_B> (buildIDs<ID_B>() );
|
||||
}
|
||||
|
|
@ -77,12 +82,28 @@ namespace test{
|
|||
void
|
||||
checkBaseType ()
|
||||
{
|
||||
typedef SubId<Colour> CID;
|
||||
CID c1 (R);
|
||||
CID c2 (G);
|
||||
CID c3 (B);
|
||||
|
||||
cout << "..." << c1 << c2 << c3 << endl;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
checkExtension ()
|
||||
{
|
||||
typedef SubId<Colour> CID;
|
||||
typedef SubId<uint> UID;
|
||||
|
||||
typedef ExtendedSubId<Colour, UID> CUID;
|
||||
|
||||
SubID const& id1 = CUID(R, 12);
|
||||
SubID const& id2 = CUID(G, 13);
|
||||
|
||||
cout << "id1=" << id1 << endl;
|
||||
cout << "id2=" << id2 << endl;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue