Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
b5b1898d
Commit
b5b1898d
authored
8 years ago
by
Jeremie Deray
Browse files
Options
Downloads
Patches
Plain Diff
replace ProcessorFactory class with new factory typedef
parent
c7f68315
No related branches found
No related tags found
1 merge request
!84
replace ProcessorFactory class with new Factory typedef
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/CMakeLists.txt
+0
-1
0 additions, 1 deletion
src/CMakeLists.txt
src/processor_factory.cpp
+0
-51
0 additions, 51 deletions
src/processor_factory.cpp
src/processor_factory.h
+11
-24
11 additions, 24 deletions
src/processor_factory.h
src/processor_imu.cpp
+2
-6
2 additions, 6 deletions
src/processor_imu.cpp
with
13 additions
and
82 deletions
src/CMakeLists.txt
+
0
−
1
View file @
b5b1898d
...
@@ -217,7 +217,6 @@ SET(SRCS
...
@@ -217,7 +217,6 @@ SET(SRCS
node_base.cpp
node_base.cpp
problem.cpp
problem.cpp
processor_base.cpp
processor_base.cpp
processor_factory.cpp
processor_imu.cpp
processor_imu.cpp
processor_odom_2D.cpp
processor_odom_2D.cpp
processor_odom_3D.cpp
processor_odom_3D.cpp
...
...
This diff is collapsed.
Click to expand it.
src/processor_factory.cpp
deleted
100644 → 0
+
0
−
51
View file @
c7f68315
/**
* \file processor_factory.cpp
*
* Created on: May 4, 2016
* \author: jsola
*/
#include
"processor_factory.h"
#include
<iostream>
#include
<iomanip>
namespace
wolf
{
bool
ProcessorFactory
::
registerCreator
(
const
std
::
string
&
_processor_type
,
CreateProcessorCallback
createFn
)
{
bool
reg
=
callbacks_
.
insert
(
CallbackMap
::
value_type
(
_processor_type
,
createFn
)).
second
;
if
(
reg
)
std
::
cout
<<
std
::
setw
(
22
)
<<
std
::
left
<<
"ProcessorFactory"
<<
" : registered "
<<
_processor_type
<<
std
::
endl
;
else
std
::
cout
<<
"ProcessorFactory : processor "
<<
_processor_type
<<
" already registered. Skipping. "
<<
std
::
endl
;
return
reg
;
}
bool
ProcessorFactory
::
unregisterCreator
(
const
std
::
string
&
_processor_type
)
{
return
callbacks_
.
erase
(
_processor_type
)
==
1
;
}
ProcessorBase
*
ProcessorFactory
::
create
(
const
std
::
string
&
_processor_type
,
const
std
::
string
&
_name
,
const
ProcessorParamsBase
*
_params
)
{
CallbackMap
::
const_iterator
creator_callback_it
=
callbacks_
.
find
(
_processor_type
);
if
(
creator_callback_it
==
callbacks_
.
end
())
{
// not found
throw
std
::
runtime_error
(
"Unknown Processor type"
);
}
// Invoke the creation function
return
(
creator_callback_it
->
second
)(
_name
,
_params
);
}
ProcessorFactory
&
ProcessorFactory
::
get
()
// Unique point of access;
{
static
ProcessorFactory
instance_
;
// Guaranteed to be destroyed.
// Instantiated on first use.
return
instance_
;
}
}
/* namespace wolf */
This diff is collapsed.
Click to expand it.
src/processor_factory.h
+
11
−
24
View file @
b5b1898d
...
@@ -16,6 +16,7 @@ struct ProcessorParamsBase;
...
@@ -16,6 +16,7 @@ struct ProcessorParamsBase;
// wolf
// wolf
#include
"wolf.h"
#include
"wolf.h"
#include
"factory.h"
// std
// std
#include
<string>
#include
<string>
...
@@ -166,32 +167,18 @@ namespace wolf
...
@@ -166,32 +167,18 @@ namespace wolf
*
*
* You can also check the code in the example file ````src/examples/test_wolf_factories.cpp````.
* You can also check the code in the example file ````src/examples/test_wolf_factories.cpp````.
*/
*/
class
ProcessorFactory
{
public:
typedef
ProcessorBase
*
(
*
CreateProcessorCallback
)(
const
std
::
string
&
_unique_name
,
const
ProcessorParamsBase
*
_params
);
private:
typedef
std
::
map
<
std
::
string
,
CreateProcessorCallback
>
CallbackMap
;
public:
bool
registerCreator
(
const
std
::
string
&
_processor_type
,
CreateProcessorCallback
createFn
);
bool
unregisterCreator
(
const
std
::
string
&
_processor_type
);
ProcessorBase
*
create
(
const
std
::
string
&
_processor_type
,
const
std
::
string
&
_unique_name
,
const
ProcessorParamsBase
*
_params
=
nullptr
);
private:
CallbackMap
callbacks_
;
// Singleton ---------------------------------------------------
typedef
Factory
<
ProcessorBase
,
const
std
::
string
&
,
const
ProcessorParamsBase
*>
ProcessorFactory
;
// This class is a singleton. The code below guarantees this.
// See: http://stackoverflow.com/questions/1008019/c-singleton-design-pattern
template
<
>
public:
inline
std
::
string
ProcessorFactory
::
getClass
()
static
ProcessorFactory
&
get
();
// Unique point of access
{
return
"ProcessorFactory"
;
}
public:
// see http://stackoverflow.com/questions/1008019/c-singleton-design-pattern
#define WOLF_REGISTER_PROCESSOR(ProcessorType, ProcessorName) \
ProcessorFactory
(
const
ProcessorFactory
&
)
=
delete
;
namespace wolf{ namespace{ const bool ProcessorName##Registered = \
void
operator
=
(
ProcessorFactory
const
&
)
=
delete
;
ProcessorFactory::get().registerCreator(ProcessorType, ProcessorName::create); }};\
private:
ProcessorFactory
()
{
}
~
ProcessorFactory
()
{
}
};
}
/* namespace wolf */
}
/* namespace wolf */
...
...
This diff is collapsed.
Click to expand it.
src/processor_imu.cpp
+
2
−
6
View file @
b5b1898d
...
@@ -41,9 +41,5 @@ ProcessorBase* ProcessorIMU::create(const std::string& _unique_name, const Proce
...
@@ -41,9 +41,5 @@ ProcessorBase* ProcessorIMU::create(const std::string& _unique_name, const Proce
// Register in the SensorFactory
// Register in the SensorFactory
#include
"processor_factory.h"
#include
"processor_factory.h"
namespace
wolf
{
namespace
WOLF_REGISTER_PROCESSOR
(
"IMU"
,
ProcessorIMU
)
{
const
bool
registered_prc_imu
=
ProcessorFactory
::
get
().
registerCreator
(
"IMU"
,
ProcessorIMU
::
create
);
}
}
// namespace wolf
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment