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 
34 namespace armarx
35 {
36  class FactoryCollectionBase;
38 
40  {
41  FactoryCollectionBaseCleanUp(FactoryCollectionBasePtr factoryToRemoveOnDesctruction);
42  FactoryCollectionBasePtr factoryCollection;
43 
44  public:
47  friend class FactoryCollectionBase;
48  };
49 
50  template <class IceBaseClass, class DerivedClass>
51  class GenericFactory : public Ice::ValueFactory
52  {
53  public:
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 
69  virtual ObjectFactoryMap getFactories() = 0;
70 
71 
74 
75  static const std::vector<FactoryCollectionBasePtr>&
77  {
78  return PreregistrationList();
79  }
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
armarx::FactoryCollectionBase::GetPreregistratedFactories
static const std::vector< FactoryCollectionBasePtr > & GetPreregistratedFactories()
Definition: FactoryCollectionBase.h:76
armarx::ObjectFactoryMap
std::map< std::string, Ice::ValueFactoryPtr > ObjectFactoryMap
Definition: FactoryCollectionBase.h:62
armarx::FactoryCollectionBase::FactoryCollectionBase
FactoryCollectionBase()
Definition: FactoryCollectionBase.cpp:31
armarx::GenericFactory::create
Ice::ObjectPtr create(const std::string &type) override
Definition: FactoryCollectionBase.h:55
armarx::FactoryCollectionBaseCleanUp::~FactoryCollectionBaseCleanUp
~FactoryCollectionBaseCleanUp()
Definition: FactoryCollectionBase.cpp:75
armarx::FactoryCollectionBase::addToPreregistration
static FactoryCollectionBaseCleanUp addToPreregistration(FactoryCollectionBasePtr factoryCollection)
Definition: FactoryCollectionBase.cpp:43
armarx::FactoryCollectionBase
Definition: FactoryCollectionBase.h:64
armarx::FactoryCollectionBase::PreregistrationList
static std::vector< FactoryCollectionBasePtr > & PreregistrationList()
Definition: FactoryCollectionBase.cpp:60
armarx::FactoryCollectionBase::add
void add(ObjectFactoryMap &map)
Definition: FactoryCollectionBase.h:83
armarx::FactoryCollectionBase::add
void add(ObjectFactoryMap &map)
Definition: FactoryCollectionBase.h:91
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:39
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:27
armarx::FactoryCollectionBase::getFactories
virtual ObjectFactoryMap getFactories()=0