retdec
Classes | Namespaces | Macros
factory.h File Reference

Implementation of the Object Factory design pattern. More...

#include <map>
#include <vector>
#include "retdec/llvmir2hll/support/smart_ptr.h"

Go to the source code of this file.

Classes

class  retdec::llvmir2hll::DefaultFactoryError< ObjectIDType, AbstractObject >
 Handles the "Unknown Type" error in an object factory. More...
 
class  retdec::llvmir2hll::Factory< AbstractObject, ObjectIDType, ObjectCreator, FactoryErrorPolicy >
 Implementation of a generic object factory. More...
 

Namespaces

 retdec
 
 retdec::llvmir2hll
 

Macros

#define REGISTER_AT_FACTORY(objectId, objectIdVarName, factory, createFunc)
 Registers an object with objectId at factory. More...
 

Detailed Description

Implementation of the Object Factory design pattern.

The implementation is based on the following book:

Macro Definition Documentation

◆ REGISTER_AT_FACTORY

#define REGISTER_AT_FACTORY (   objectId,
  objectIdVarName,
  factory,
  createFunc 
)
Value:
static const std::string objectIdVarName = [] { \
factory::getInstance().registerObject(objectId, createFunc); \
return objectId; \
} ()

Registers an object with objectId at factory.

Parameters
objectIdIdentifier of the object.
objectIdVarNameName of the variable used to hold objectId.
factoryName of the factory.
createFuncFunction to be used for creating objects.

For example, the following code snippet registers a Python HLL writer:

REGISTER_AT_FACTORY("py", PY_HLL_WRITER_ID, HLLWriterFactory, PyHLLWriter::create);
#define REGISTER_AT_FACTORY(objectId, objectIdVarName, factory, createFunc)
Registers an object with objectId at factory.
Definition: factory.h:45
Singleton< Factory< HLLWriter, std::string, ShPtr< HLLWriter >(*)(llvm::raw_ostream &, const std::string &) > > HLLWriterFactory
Factory that creates instances of classes derived from HLLWriter.
Definition: hll_writer_factory.h:38

This macro creates a const std::string constant in an anonymous namespace named objectIdVarName whose value is objectId. It is supposed to be used only in implementation files (i.e. .cpp files).