LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
lsst::daf::persistence::FormatterRegistry Class Reference

Class that registers all Formatter subclasses. More...

#include <FormatterRegistry.h>

Inheritance diagram for lsst::daf::persistence::FormatterRegistry:
lsst::daf::base::Citizen

Public Member Functions

void registerFormatter (std::string const &persistableName, std::type_info const &persistableType, Formatter::FactoryPtr factory)
 
Formatter::Ptr lookupFormatter (std::type_info const &persistableType, lsst::pex::policy::Policy::Ptr policy)
 
Formatter::Ptr lookupFormatter (std::string const &persistableName, lsst::pex::policy::Policy::Ptr policy)
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 

Static Public Member Functions

static FormatterRegistrygetInstance (void)
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector
< const Citizen * > * 
census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 

Private Types

typedef std::map< std::string,
Formatter::FactoryPtr
FactoryMap
 
typedef std::map< std::string,
std::string > 
StringMap
 

Private Member Functions

 FormatterRegistry (void)
 
 ~FormatterRegistry (void)
 
 FormatterRegistry (FormatterRegistry const &)
 
FormatterRegistryoperator= (FormatterRegistry const &)
 

Private Attributes

FactoryMap _byName
 Registry of Formatter factories by Persistable name. More...
 
StringMap _nameForType
 Registry of Persistable names by std::type_info::name(). More...
 

Additional Inherited Members

- Public Types inherited from lsst::daf::base::Citizen
enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback )(const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback )(const Citizen *ptr)
 

Detailed Description

Class that registers all Formatter subclasses.

Allows lookup by Persistable type_info or name.

Definition at line 53 of file FormatterRegistry.h.

Member Typedef Documentation

Definition at line 66 of file FormatterRegistry.h.

typedef std::map<std::string, std::string> lsst::daf::persistence::FormatterRegistry::StringMap
private

Definition at line 67 of file FormatterRegistry.h.

Constructor & Destructor Documentation

lsst::daf::persistence::FormatterRegistry::FormatterRegistry ( void  )
private

Default constructor.

Definition at line 117 of file FormatterRegistry.cc.

117  :
118  lsst::daf::base::Citizen(typeid(*this)) {
119  markPersistent();
120 }
void markPersistent(void)
Mark a Citizen as persistent and not destroyed until process end.
Definition: Citizen.cc:253
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
lsst::daf::persistence::FormatterRegistry::~FormatterRegistry ( void  )
private

Minimal destructor.

Definition at line 124 of file FormatterRegistry.cc.

124  {
125 }
lsst::daf::persistence::FormatterRegistry::FormatterRegistry ( FormatterRegistry const &  )
private

Member Function Documentation

FormatterRegistry & lsst::daf::persistence::FormatterRegistry::getInstance ( void  )
static

Get a reference to the singleton instance of the FormatterRegistry.

Returns
Reference to the singleton

Uses function-scoped static to ensure proper initialization.

Definition at line 56 of file FormatterRegistry.cc.

Formatter::Ptr lsst::daf::persistence::FormatterRegistry::lookupFormatter ( std::type_info const &  persistableType,
lsst::pex::policy::Policy::Ptr  policy 
)

Create a new instance of a Formatter subclass given the typeid() of its corresponding Persistable subclass.

Parameters
[in]persistableTypetypeid() of the Persistable subclass
[in]policyPolicy containing all Formatter policies
Returns
Shared pointer to an instance of the subclass

Definition at line 81 of file FormatterRegistry.cc.

83  {
84  StringMap::const_iterator it = _nameForType.find(persistableType.name());
85  if (it == _nameForType.end()) {
86  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
87  std::string("No Formatter registered for Persistable type: ") +
88  persistableType.name());
89  }
90  return lookupFormatter(it->second, policy);
91 }
StringMap _nameForType
Registry of Persistable names by std::type_info::name().
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Formatter::Ptr lookupFormatter(std::type_info const &persistableType, lsst::pex::policy::Policy::Ptr policy)
Formatter::Ptr lsst::daf::persistence::FormatterRegistry::lookupFormatter ( std::string const &  persistableName,
lsst::pex::policy::Policy::Ptr  policy 
)

Create a new instance of a Formatter subclass given the string name of its corresponding Persistable subclass.

Parameters
[in]persistableNameName of the Persistable subclass
[in]policyPolicy containing all Formatter policies
Returns
Shared pointer to an instance of the subclass

Definition at line 99 of file FormatterRegistry.cc.

101  {
102  FactoryMap::const_iterator it = _byName.find(persistableName);
103  if (it == _byName.end()) {
104  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
105  "No Formatter registered for Persistable name: " +
106  persistableName);
107  }
108  lsst::pex::policy::Policy::Ptr formatterPolicy;
109  if (policy && policy->exists(persistableName)) {
110  formatterPolicy = policy->getPolicy(persistableName);
111  }
112  return (*(it->second))(formatterPolicy);
113 }
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
FactoryMap _byName
Registry of Formatter factories by Persistable name.
FormatterRegistry& lsst::daf::persistence::FormatterRegistry::operator= ( FormatterRegistry const &  )
private
void lsst::daf::persistence::FormatterRegistry::registerFormatter ( std::string const &  persistableName,
std::type_info const &  persistableType,
Formatter::FactoryPtr  factory 
)

Register a factory for a Formatter subclass using the name and type of the Persistable subclass it formats.

Parameters
[in]persistableNameName of the Persistable subclass
[in]persistableTypetypeid() of the Persistable subclass
[in]factoryFactory function for the Formatter, taking a Policy

Definition at line 67 of file FormatterRegistry.cc.

69  {
70  _byName.insert(FactoryMap::value_type(persistableName, factory));
71  _nameForType.insert(StringMap::value_type(persistableType.name(),
72  persistableName));
73 }
StringMap _nameForType
Registry of Persistable names by std::type_info::name().
FactoryMap _byName
Registry of Formatter factories by Persistable name.

Member Data Documentation

FactoryMap lsst::daf::persistence::FormatterRegistry::_byName
private

Registry of Formatter factories by Persistable name.

Definition at line 76 of file FormatterRegistry.h.

StringMap lsst::daf::persistence::FormatterRegistry::_nameForType
private

Registry of Persistable names by std::type_info::name().

Definition at line 78 of file FormatterRegistry.h.


The documentation for this class was generated from the following files: