FactoryCollectionBase.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5*
6* ArmarX is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 2 as
8* published by the Free Software Foundation.
9*
10* ArmarX is distributed in the hope that it will be useful, but
11* WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* @package
19* @author Mirko Waechter( waechter at kit dot edu)
20* @date 2013
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24
25#pragma once
26
27#include <map>
28#include <memory>
29#include <string>
30#include <vector>
31
32#include <Ice/ValueFactory.h>
33
34namespace armarx
35{
38
39 class FactoryCollectionBaseCleanUp
40 {
41 FactoryCollectionBaseCleanUp(FactoryCollectionBasePtr factoryToRemoveOnDesctruction);
42 FactoryCollectionBasePtr factoryCollection;
43
44 public:
45 FactoryCollectionBaseCleanUp(FactoryCollectionBaseCleanUp&&) = default;
48 };
49
50 template <class IceBaseClass, class DerivedClass>
51 class GenericFactory : public Ice::ValueFactory
52 {
53 public:
54 Ice::ObjectPtr
55 create(const std::string& type) override
56 {
57 assert(type == IceBaseClass::ice_staticId());
58 return new DerivedClass();
59 }
60 };
61
62 using ObjectFactoryMap = std::map<std::string, Ice::ValueFactoryPtr>;
63
64 class FactoryCollectionBase : virtual public IceUtil::Shared
65 {
66 public:
68
70
71
74
75 static const std::vector<FactoryCollectionBasePtr>&
80
81 template <class IceBaseClass, class DerivedClass>
82 void
84 {
85 map.insert(std::make_pair(IceBaseClass::ice_staticId(),
87 }
88
89 template <class DerivedClass>
90 void
92 {
93 map.insert(std::make_pair(DerivedClass::ice_staticId(),
95 }
96
97 protected:
98 static std::vector<FactoryCollectionBasePtr>& PreregistrationList();
99
101 friend class ArmarXManager;
102 };
103
104
105} // namespace armarx
FactoryCollectionBaseCleanUp(FactoryCollectionBaseCleanUp &&)=default
static const std::vector< FactoryCollectionBasePtr > & GetPreregistratedFactories()
static std::vector< FactoryCollectionBasePtr > & PreregistrationList()
void add(ObjectFactoryMap &map)
virtual ObjectFactoryMap getFactories()=0
static FactoryCollectionBaseCleanUp addToPreregistration(FactoryCollectionBasePtr factoryCollection)
void add(ObjectFactoryMap &map)
Ice::ObjectPtr create(const std::string &type) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, Ice::ValueFactoryPtr > ObjectFactoryMap
IceUtil::Handle< FactoryCollectionBase > FactoryCollectionBasePtr