Module Class Reference

Factory for objects. More...

#include <module.h>

Inherited by FromFileModule, and MapModule.

List of all members.

Classes

struct  UnrefCompare

Public Member Functions

 Module ()
void import (const Module &module)
 Import a module to serve as fallback if a type cannot be handled directly by the module.
bool isExtension (const ObjectType &child, const ObjectType &parent) const
 Check if a type extends another.
void setExtension (const ObjectTypeTemplate &childTemplate, const std::function< ObjectType(const ObjectType &)> &parentFunction)
 Set a function to compute the fathers for a type template.
void setExtension (const ObjectTypeTemplate &childTemplate, const ObjectType &parent)
 Set a father for a type template.
void setExtension (const ObjectTypeTemplate &childTemplate, const ObjectType &parent, const std::map< int, int > &parameterMapping)
 Set fathers for a type template with a mapping for parameters.
ObjectType getFather (const ObjectType &child) const
 Get the father of a type.
ObjectType specify (const ObjectType &parent) const
 Get the specification for the parent object.
void setSpecification (const ObjectType &parent, const ObjectType &child)
 Set the specification for the parent.
Objecthandle (const ObjectType &type, File &file, Object *parent=nullptr) const
 Create an object beginning at the current position of the file and add the appropriate parsers according to the inheritance structure for the type.
bool canHandle (const ObjectType &type) const
 Check if the type can be handled by the module or any of the imported one.
const Modulehandler (const ObjectType &type) const
 Get the module able to handle the type among the current module and the imported ones.
int64_t getFixedSize (const ObjectType &type) const
 Get the size that every objects of a type should have.
const ObjectTypeTemplategetTemplate (const std::string &name) const
 Get a type template stored by the module or one of the imported one, by its name.
bool hasTemplate (const std::string &name) const
 Check if any type template stored by the module or one of the imported one has this name.
bool canHandleFunction (const std::string &name) const
 Check if the module or any of the imported ones can handle a function by this name.
const ModulefunctionHandler (const std::string &name) const
 Get the module able to handle a function by this name among the currentmodule and the imported ones.
Variable executeFunction (const std::string &name, const ScopePtr &params) const
 Execute the function with the parameters given as a scope.
const std::vector< std::string > & getFunctionParameterNames (const std::string &name) const
 Get the names of the parameters as a vector of strings.
const std::vector< bool > & getFunctionParameterModifiables (const std::string &name) const
 Get a vector of boolean specifying for each parameter if the function can modify the value or not.
const std::vector< Variant > & getFunctionParameterDefaults (const std::string &name) const
 Get a vector of values specifying default values for each parameter.
bool isLoaded () const
 Check if the module has been successfully loaded by the module loader.

Protected Member Functions

virtual void addFormatDetection (StandardFormatDetector::Adder &formatAdder)
 [Pure Virtual] Use the format adder to add format detection methods, so that the module loader can choose which module to use to parse a file
virtual void requestImportations (std::vector< std::string > &modulesRequested)
 [Pure Virtual] Complete the list of modules that the module loader should load and import to the module, by adding the names of the modules requested.
virtual bool doLoad ()
 [Pure Virtual] Initialize the module. The function will be called by the module loader when the module is first used, after the requested modules have been added.
virtual ParsergetParser (const ObjectType &type, Object &object, const Module &fromModule) const
 [Pure Virtual] Get the parser associated with the type.
virtual bool hasParser (const ObjectType &type) const
 [Pure Virtual] Check if the type can be handled be the module directly.
virtual int64_t doGetFixedSize (const ObjectType &type, const Module &module) const
 [Pure Virtual] Get the size that every objects of a type should have.
virtual bool doCanHandleFunction (const std::string &name) const
virtual Variable doExecuteFunction (const std::string &name, const ScopePtr &params, const Module &fromModule) const
virtual const std::vector
< std::string > & 
doGetFunctionParameterNames (const std::string &name) const
virtual const std::vector< bool > & doGetFunctionParameterModifiables (const std::string &name) const
virtual const std::vector
< Variant > & 
doGetFunctionParameterDefaults (const std::string &name) const
void addTemplate (const ObjectTypeTemplate &typeTemplate)
 Register a type template to the module so that it can be accessed by its name by the function getTemplate.
const ObjectTypeTemplatenewTemplate (const std::string &name, const std::vector< std::string > &parameters=std::vector< std::string >())

Friends

class ModuleLoader

Detailed Description

Factory for objects.

Given a type and a file it can create an object beginning at the current position of the file and add the appropriate parsers.

It holds an object model that defines extensions and specification for types handled. This will define which parsers are added. Each parser correspond to a type generated by getParser, if the type A extends the type B then the parser for B will be added and then the parser for A.

In addition to extensions, the object model defines specification, which means that if after minimal parser an object has type A and A's specification is B then parser for B will be subsequently added and the type of the object will be B.

It can also define functions that can be used in HMDLs.

Other modules can be imported, in which case if a type or a function can not be handle by the module, then the imported modules will serve as fallback with priority for the last loaded.

The life cycle of the module is handled by a module loader : on construction the module must have the smallest memory footprint possible abd the shortest runtime, when added to the module loader format detection will be added so that the module loader knows on which file the module should be used (reimplement addFormatDetection). Then when when the module loader uses the module for the first time, it first ask for importation request to see which modules must be loaded and imported (reimplement requestImportations) and then the actual loading is done (reimplement doLoad).

The class is virtual and must be subclassed to be used. For most usages MapModule is the right class to subclass.


Constructor & Destructor Documentation


Member Function Documentation

virtual void Module::addFormatDetection ( StandardFormatDetector::Adder formatAdder) [protected, virtual]

[Pure Virtual] Use the format adder to add format detection methods, so that the module loader can choose which module to use to parse a file

void Module::addTemplate ( const ObjectTypeTemplate typeTemplate) [protected]

Register a type template to the module so that it can be accessed by its name by the function getTemplate.

Every type template should be registered so that when the module is imported into an HMDL module, the type template can be recognized.

bool Module::canHandle ( const ObjectType type) const

Check if the type can be handled by the module or any of the imported one.

bool Module::canHandleFunction ( const std::string &  name) const

Check if the module or any of the imported ones can handle a function by this name.

virtual bool Module::doCanHandleFunction ( const std::string &  name) const [protected, virtual]
virtual Variable Module::doExecuteFunction ( const std::string &  name,
const ScopePtr &  params,
const Module fromModule 
) const [protected, virtual]
virtual int64_t Module::doGetFixedSize ( const ObjectType type,
const Module module 
) const [protected, virtual]

[Pure Virtual] Get the size that every objects of a type should have.

Return 0 if the type relies on its father to compute the size

Return -1 if the size is variable and set by type's parser

virtual const std::vector<Variant>& Module::doGetFunctionParameterDefaults ( const std::string &  name) const [protected, virtual]
virtual const std::vector<bool>& Module::doGetFunctionParameterModifiables ( const std::string &  name) const [protected, virtual]
virtual const std::vector<std::string>& Module::doGetFunctionParameterNames ( const std::string &  name) const [protected, virtual]
virtual bool Module::doLoad ( ) [protected, virtual]

[Pure Virtual] Initialize the module. The function will be called by the module loader when the module is first used, after the requested modules have been added.

Variable Module::executeFunction ( const std::string &  name,
const ScopePtr &  params 
) const

Execute the function with the parameters given as a scope.

const Module* Module::functionHandler ( const std::string &  name) const

Get the module able to handle a function by this name among the currentmodule and the imported ones.

Return nullptr if no function by this name can be handled

ObjectType Module::getFather ( const ObjectType child) const

Get the father of a type.

Returns the null type if the type doesn't have a father

int64_t Module::getFixedSize ( const ObjectType type) const

Get the size that every objects of a type should have.

Return -1 if the size is variable

const std::vector<Variant>& Module::getFunctionParameterDefaults ( const std::string &  name) const

Get a vector of values specifying default values for each parameter.

const std::vector<bool>& Module::getFunctionParameterModifiables ( const std::string &  name) const

Get a vector of boolean specifying for each parameter if the function can modify the value or not.

const std::vector<std::string>& Module::getFunctionParameterNames ( const std::string &  name) const

Get the names of the parameters as a vector of strings.

virtual Parser* Module::getParser ( const ObjectType type,
Object object,
const Module fromModule 
) const [protected, virtual]

[Pure Virtual] Get the parser associated with the type.

Return nullptr if the type cannot be handled

const ObjectTypeTemplate& Module::getTemplate ( const std::string &  name) const

Get a type template stored by the module or one of the imported one, by its name.

Object* Module::handle ( const ObjectType type,
File file,
Object parent = nullptr 
) const

Create an object beginning at the current position of the file and add the appropriate parsers according to the inheritance structure for the type.

const Module* Module::handler ( const ObjectType type) const

Get the module able to handle the type among the current module and the imported ones.

Return nullptr if the type cannot be handled

virtual bool Module::hasParser ( const ObjectType type) const [protected, virtual]

[Pure Virtual] Check if the type can be handled be the module directly.

bool Module::hasTemplate ( const std::string &  name) const

Check if any type template stored by the module or one of the imported one has this name.

void Module::import ( const Module module)

Import a module to serve as fallback if a type cannot be handled directly by the module.

If a type or a function is not handled by the the module, then a handler will be searched among the imported modules, with a priority for the lastest module imported

bool Module::isExtension ( const ObjectType child,
const ObjectType parent 
) const

Check if a type extends another.

Get the father of the child and checks if it extends directly the parent, if not checks recursively if the father extends the parent.

bool Module::isLoaded ( ) const

Check if the module has been successfully loaded by the module loader.

const ObjectTypeTemplate& Module::newTemplate ( const std::string &  name,
const std::vector< std::string > &  parameters = std::vector< std::string >() 
) [protected]
virtual void Module::requestImportations ( std::vector< std::string > &  modulesRequested) [protected, virtual]

[Pure Virtual] Complete the list of modules that the module loader should load and import to the module, by adding the names of the modules requested.

void Module::setExtension ( const ObjectTypeTemplate childTemplate,
const std::function< ObjectType(const ObjectType &)> &  parentFunction 
)

Set a function to compute the fathers for a type template.

Most likely the fathers will all have the same type template but different parameters

void Module::setExtension ( const ObjectTypeTemplate childTemplate,
const ObjectType parent 
)

Set a father for a type template.

void Module::setExtension ( const ObjectTypeTemplate childTemplate,
const ObjectType parent,
const std::map< int, int > &  parameterMapping 
)

Set fathers for a type template with a mapping for parameters.

void Module::setSpecification ( const ObjectType parent,
const ObjectType child 
)

Set the specification for the parent.

ObjectType Module::specify ( const ObjectType parent) const

Get the specification for the parent object.

Returns the null type if the type doesn't have a specification


Friends And Related Function Documentation

friend class ModuleLoader [friend]

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