2007-08-17 00:36:07 +02:00
|
|
|
/* try.cpp - for trying out some language features....
|
|
|
|
|
* scons will create the binary bin/try
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 8/07 - how to control NOBUG??
|
2007-08-31 14:57:49 +02:00
|
|
|
// execute with NOBUG_LOG='ttt:TRACE' bin/try
|
2008-01-04 01:44:40 +01:00
|
|
|
// 1/08 - working out a static initialisation problem for Visitor (Tag creation)
|
2007-08-17 00:36:07 +02:00
|
|
|
|
|
|
|
|
|
2008-01-04 01:44:40 +01:00
|
|
|
#include <nobug.h>
|
|
|
|
|
#include <iostream>
|
2007-08-17 00:36:07 +02:00
|
|
|
|
2008-01-04 01:44:40 +01:00
|
|
|
using std::string;
|
|
|
|
|
using std::cout;
|
2007-08-17 00:36:07 +02:00
|
|
|
|
2008-01-04 01:44:40 +01:00
|
|
|
NOBUG_CPP_DEFINE_FLAG(test);
|
|
|
|
|
|
|
|
|
|
template<class TOOL> class Tag;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class TOOL, class TOOLImpl>
|
|
|
|
|
class TagTypeRef
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static Tag<TOOL> tag;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class TOOL>
|
|
|
|
|
class Tag
|
|
|
|
|
{
|
|
|
|
|
size_t tagID;
|
|
|
|
|
static size_t lastRegisteredID;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Tag(size_t tt=0) : tagID(tt) {}
|
|
|
|
|
operator size_t() const { return tagID; }
|
2007-08-17 00:36:07 +02:00
|
|
|
|
2008-01-04 01:44:40 +01:00
|
|
|
template<class TOOLImpl>
|
|
|
|
|
static Tag<TOOL>&
|
|
|
|
|
get (TOOLImpl* const concreteTool=0)
|
|
|
|
|
{
|
|
|
|
|
INFO (test,"getTag");
|
|
|
|
|
Tag<TOOL>& t = TagTypeRef<TOOL,TOOLImpl>::tag;
|
|
|
|
|
if (!t)
|
|
|
|
|
t.tagID = ++Tag<TOOL>::lastRegisteredID;
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** storage for the Tag registry for each concrete tool */
|
|
|
|
|
template<class TOOL, class TOOLImpl>
|
|
|
|
|
Tag<TOOL> TagTypeRef<TOOL,TOOLImpl> ::tag (0);
|
|
|
|
|
|
|
|
|
|
template<class TOOL>
|
|
|
|
|
size_t Tag<TOOL>::lastRegisteredID (0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TT
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TI : public TT
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
class TII : public TT
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
};
|
2007-08-17 00:36:07 +02:00
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
NOBUG_INIT;
|
|
|
|
|
|
2008-01-04 01:44:40 +01:00
|
|
|
size_t xxx = Tag<TT>::get<TII>();
|
|
|
|
|
|
|
|
|
|
cout << "created Tag=" << xxx <<"\n";
|
|
|
|
|
cout << "created Tag=" << Tag<TT>::get<TI> () <<"\n";
|
2007-08-17 00:36:07 +02:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|