This is a template that takes care of managing plugin registries. I wrote it because I got the distinct feeling I was needlessly reinventing the wheel as I wrote a collector registry. I haven't converted anything else to use it, though. Still, it's orthogonal and has become stable in my usage, so I thought I'd submit it in advance.
To get my collector registry going, all I needed was 5 lines:
typedef Registry<TargetCollector> CollectorRegistry;
template<> CollectorRegistry::node *CollectorRegistry::Head = 0;
template<> CollectorRegistry::node *CollectorRegistry::Tail = 0;
template<> CollectorRegistry::listener *CollectorRegistry::ListenerHead = 0;
template<> CollectorRegistry::listener *CollectorRegistry::ListenerTail = 0;
Afterwards, the most important features work more or less as to be expected:
Y("shadow-stack", "Shadow-stack collector, for uncooperative code generators");
static cl::opt<const CollectorRegistry::entry*, false, CollectorRegistry::Parser>
GC("gc", cl::desc("Enable garbage collection."));
Collector = GC->instantiate();
for (CollectorRegistry::iterator I = CollectorRegistry::begin(),
E = CollectorRegistry::end(); I != E; ++I)
cout << I->getName() << ": " << I->getDesc() << "\n";
Granted, my needs are currently simple. The default entry type has just the name, description, and use the default constructor. To convert, many registries in the system would need to also define:
1. An custom entry type, particularly where the default constructor was insufficient.
2. A custom traits type.
3. The RegisterFoo template, to create the constructor wrapper springboard.