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 <Ice/ValueFactory.h>
28 
29 #include <vector>
30 #include <string>
31 #include <memory>
32 #include <map>
33 
34 namespace armarx
35 {
36  class FactoryCollectionBase;
39  {
40  FactoryCollectionBaseCleanUp(FactoryCollectionBasePtr factoryToRemoveOnDesctruction);
41  FactoryCollectionBasePtr factoryCollection;
42 
43  public:
46  friend class FactoryCollectionBase;
47 
48  };
49 
50  template <class IceBaseClass, class DerivedClass>
51  class GenericFactory : public Ice::ValueFactory
52  {
53  public:
54  Ice::ObjectPtr create(const std::string& type) override
55  {
56  assert(type == IceBaseClass::ice_staticId());
57  return new DerivedClass();
58  }
59  };
60 
61  using ObjectFactoryMap = std::map<std::string, Ice::ValueFactoryPtr>;
62 
63  class FactoryCollectionBase : virtual public IceUtil::Shared
64  {
65  public:
67 
68  virtual ObjectFactoryMap getFactories() = 0;
69 
70 
72 
73  static const std::vector<FactoryCollectionBasePtr>& GetPreregistratedFactories()
74  {
75  return PreregistrationList();
76  }
77 
78  template <class IceBaseClass, class DerivedClass>
79  void add(ObjectFactoryMap& map)
80  {
81  map.insert(std::make_pair(IceBaseClass::ice_staticId(), new GenericFactory<IceBaseClass, DerivedClass>()));
82  }
83 
84  template <class DerivedClass>
85  void add(ObjectFactoryMap& map)
86  {
87  map.insert(std::make_pair(DerivedClass::ice_staticId(), new GenericFactory<DerivedClass, DerivedClass>()));
88  }
89 
90  protected:
91  static std::vector<FactoryCollectionBasePtr>& PreregistrationList();
92 
94  friend class ArmarXManager;
95  };
96 
97 
98 
99 }
armarx::FactoryCollectionBase::GetPreregistratedFactories
static const std::vector< FactoryCollectionBasePtr > & GetPreregistratedFactories()
Definition: FactoryCollectionBase.h:73
armarx::ObjectFactoryMap
std::map< std::string, Ice::ValueFactoryPtr > ObjectFactoryMap
Definition: FactoryCollectionBase.h:61
armarx::FactoryCollectionBase::FactoryCollectionBase
FactoryCollectionBase()
Definition: FactoryCollectionBase.cpp:31
armarx::GenericFactory::create
Ice::ObjectPtr create(const std::string &type) override
Definition: FactoryCollectionBase.h:54
armarx::FactoryCollectionBaseCleanUp::~FactoryCollectionBaseCleanUp
~FactoryCollectionBaseCleanUp()
Definition: FactoryCollectionBase.cpp:71
armarx::FactoryCollectionBase::addToPreregistration
static FactoryCollectionBaseCleanUp addToPreregistration(FactoryCollectionBasePtr factoryCollection)
Definition: FactoryCollectionBase.cpp:41
armarx::FactoryCollectionBase
Definition: FactoryCollectionBase.h:63
armarx::FactoryCollectionBase::PreregistrationList
static std::vector< FactoryCollectionBasePtr > & PreregistrationList()
Definition: FactoryCollectionBase.cpp:57
armarx::FactoryCollectionBase::add
void add(ObjectFactoryMap &map)
Definition: FactoryCollectionBase.h:79
armarx::FactoryCollectionBase::add
void add(ObjectFactoryMap &map)
Definition: FactoryCollectionBase.h:85
IceUtil::Handle< FactoryCollectionBase >
armarx::GenericFactory
Definition: FactoryCollectionBase.h:51
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::FactoryCollectionBaseCleanUp
Definition: FactoryCollectionBase.h:38
armarx::ArmarXManager
Main class of an ArmarX process.
Definition: ArmarXManager.h:97
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::FactoryCollectionBase::getFactories
virtual ObjectFactoryMap getFactories()=0