The following registry, implemented as a singleton class, works fine for me. However, as it is not teared down on exit, each registry entry causes one error report stanza in valgrind. How to refactor the code to get rid of these false positives?
// registry.h
class SFuncRegistry {
private:
SFuncRegistry() {};
SFuncRegistry(SFuncRegistry const&) = delete; //! To prevent copying
void operator=(SFuncRegistry const&) = delete; //! To prevent copying
map<string,const class CFunc*> FMap;
public:
static SFuncRegistry& getInstance()
{ static SFuncRegistry instance; //! Instantiated on first use.
return instance; }
const class CFunc* find( string nam ) const;
void register( string nam, const class CFunc* fun );
}
// main.cpp
{
SFuncRegistry* GFuncRegistry = &(SFuncRegistry::getInstance());
GFuncRegistry->register( ... )
...
const class CFunc fun = GFuncRegistry->find( ... )
...
}
Aucun commentaire:
Enregistrer un commentaire