g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
core
factory.h
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#ifndef G2O_FACTORY_H
28
#define G2O_FACTORY_H
29
30
#include <iostream>
31
#include <map>
32
#include <memory>
33
#include <string>
34
35
#include "
creators.h
"
36
#include "g2o/config.h"
37
#include "
g2o/stuff/misc.h
"
// ForceLinker for the macros
38
#include "
hyper_graph.h
"
39
40
// define to get some verbose output
41
// #define G2O_DEBUG_FACTORY
42
43
namespace
g2o
{
44
48
class
G2O_CORE_API
Factory
{
49
public
:
51
static
Factory
*
instance
();
52
53
Factory
(
Factory
const
&) =
delete
;
54
Factory
&
operator=
(
Factory
const
&) =
delete
;
55
57
static
void
destroy
();
58
62
void
registerType
(
const
std::string&
tag
,
63
const
std::shared_ptr<AbstractHyperGraphElementCreator>& c);
64
68
void
unregisterType
(
const
std::string&
tag
);
69
73
HyperGraph::HyperGraphElement
*
construct
(
const
std::string&
tag
)
const
;
74
80
HyperGraph::HyperGraphElement
*
construct
(
81
const
std::string&
tag
,
82
const
HyperGraph::GraphElemBitset
& elemsToConstruct)
const
;
83
87
bool
knowsTag
(
const
std::string&
tag
,
int
* elementType = 0)
const
;
88
90
const
std::string&
tag
(
const
HyperGraph::HyperGraphElement
* v)
const
;
91
95
void
fillKnownTypes
(std::vector<std::string>& types)
const
;
96
100
void
printRegisteredTypes
(std::ostream& os,
bool
comment =
false
)
const
;
101
102
protected
:
103
class
CreatorInformation
{
104
public
:
105
std::shared_ptr<AbstractHyperGraphElementCreator>
creator
;
106
int
elementTypeBit
= -1;
107
};
108
109
typedef
std::map<std::string, std::unique_ptr<CreatorInformation>>
CreatorMap
;
110
typedef
std::map<std::string, std::string>
TagLookup
;
111
Factory
() =
default
;
112
113
CreatorMap
_creator
;
114
TagLookup
_tagLookup
;
115
116
private
:
117
static
std::unique_ptr<Factory>
factoryInstance
;
118
};
119
120
template
<
typename
T>
121
class
RegisterTypeProxy
{
122
public
:
123
RegisterTypeProxy
(
const
std::string& name) :
_name
(name) {
124
#ifdef G2O_DEBUG_FACTORY
125
std::cout << __FUNCTION__ <<
": Registering "
<<
_name
<<
" of type "
126
<<
typeid
(T).name() << std::endl;
127
#endif
128
_creator
.reset(
new
HyperGraphElementCreator<T>
());
129
Factory::instance
()->
registerType
(
_name
,
_creator
);
130
}
131
132
private
:
133
std::string
_name
;
134
std::shared_ptr<AbstractHyperGraphElementCreator>
_creator
;
135
};
136
137
}
// namespace g2o
138
139
#if defined _MSC_VER && defined G2O_SHARED_LIBS
140
#define G2O_FACTORY_EXPORT __declspec(dllexport)
141
#define G2O_FACTORY_IMPORT __declspec(dllimport)
142
#else
143
#define G2O_FACTORY_EXPORT
144
#define G2O_FACTORY_IMPORT
145
#endif
146
147
// These macros are used to automate registering types and forcing linkage
148
#define G2O_REGISTER_TYPE(name, classname) \
149
extern "C" void G2O_FACTORY_EXPORT g2o_type_##classname(void) {} \
150
static g2o::RegisterTypeProxy<classname> g_type_proxy_##classname(#name);
151
152
#define G2O_USE_TYPE_BY_CLASS_NAME(classname) \
153
extern "C" void G2O_FACTORY_IMPORT g2o_type_##classname(void); \
154
static g2o::ForceLinker proxy_##classname(g2o_type_##classname);
155
156
#define G2O_REGISTER_TYPE_GROUP(typeGroupName) \
157
extern "C" void G2O_FACTORY_EXPORT g2o_type_group_##typeGroupName(void) {}
158
159
#define G2O_USE_TYPE_GROUP(typeGroupName) \
160
extern "C" void G2O_FACTORY_IMPORT g2o_type_group_##typeGroupName(void); \
161
static g2o::ForceLinker g2o_force_type_link_##typeGroupName( \
162
g2o_type_group_##typeGroupName);
163
164
#endif
g2o::Factory::CreatorInformation
Definition
factory.h:103
g2o::Factory::CreatorInformation::creator
std::shared_ptr< AbstractHyperGraphElementCreator > creator
Definition
factory.h:105
g2o::Factory::CreatorInformation::elementTypeBit
int elementTypeBit
Definition
factory.h:106
g2o::Factory::unregisterType
void unregisterType(const std::string &tag)
Definition
factory.cpp:113
g2o::Factory::knowsTag
bool knowsTag(const std::string &tag, int *elementType=0) const
Definition
factory.cpp:152
g2o::Factory::operator=
Factory & operator=(Factory const &)=delete
g2o::Factory::_creator
CreatorMap _creator
look-up map for the existing creators
Definition
factory.h:113
g2o::Factory::Factory
Factory()=default
g2o::Factory::printRegisteredTypes
void printRegisteredTypes(std::ostream &os, bool comment=false) const
Definition
factory.cpp:167
g2o::Factory::factoryInstance
static std::unique_ptr< Factory > factoryInstance
Definition
factory.h:117
g2o::Factory::instance
static Factory * instance()
return the instance
Definition
factory.cpp:46
g2o::Factory::CreatorMap
std::map< std::string, std::unique_ptr< CreatorInformation > > CreatorMap
Definition
factory.h:109
g2o::Factory::_tagLookup
TagLookup _tagLookup
reverse look-up, class name to tag
Definition
factory.h:114
g2o::Factory::construct
HyperGraph::HyperGraphElement * construct(const std::string &tag) const
Definition
factory.cpp:129
g2o::Factory::destroy
static void destroy()
free the instance
Definition
factory.cpp:162
g2o::Factory::TagLookup
std::map< std::string, std::string > TagLookup
Definition
factory.h:110
g2o::Factory::Factory
Factory(Factory const &)=delete
g2o::Factory::tag
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
Definition
factory.cpp:138
g2o::Factory::fillKnownTypes
void fillKnownTypes(std::vector< std::string > &types) const
Definition
factory.cpp:145
g2o::Factory::registerType
void registerType(const std::string &tag, const std::shared_ptr< AbstractHyperGraphElementCreator > &c)
Definition
factory.cpp:58
g2o::HyperGraphElementCreator
templatized creator class which creates graph elements
Definition
creators.h:58
g2o::HyperGraph::GraphElemBitset
std::bitset< HyperGraph::HGET_NUM_ELEMS > GraphElemBitset
Definition
hyper_graph.h:70
g2o::RegisterTypeProxy::RegisterTypeProxy
RegisterTypeProxy(const std::string &name)
Definition
factory.h:123
g2o::RegisterTypeProxy::_name
std::string _name
Definition
factory.h:133
g2o::RegisterTypeProxy::_creator
std::shared_ptr< AbstractHyperGraphElementCreator > _creator
Definition
factory.h:134
creators.h
G2O_CORE_API
#define G2O_CORE_API
Definition
g2o_core_api.h:29
hyper_graph.h
misc.h
some general case utility functions
g2o
Definition
dl_wrapper.cpp:55
g2o::HyperGraph::HyperGraphElement
Definition
hyper_graph.h:80
Generated on
for g2o by
1.17.0