SheafSystem  0.0.0.0
factory.h
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Interface for class factory
19 
20 #ifndef FACTORY_H
21 #define FACTORY_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef STD_IOSTREAM_H
28 #include "SheafSystem/std_iostream.h"
29 #endif
30 
31 #ifndef STD_MAP_H
32 #include "SheafSystem/std_map.h"
33 #endif
34 
35 #ifndef STD_STRING_H
36 #include "SheafSystem/std_string.h"
37 #endif
38 
39 namespace sheaf
40 {
41 
42 class namespace_poset;
43 
44 // Forward declarations to enable friend declaration.
45 
46 template <typename T>
47 class factory;
48 
49 template <typename T>
50 std::ostream& operator << (std::ostream &os, const factory<T>& xf);
51 
52 
64 template <typename T>
65 class factory
66 {
67  friend std::ostream& operator << <T> (std::ostream& xos, const factory<T>& xf);
68 
69 public:
70 
71  // ===========================================================
72  // FACTORY FACET
73  // ===========================================================
74 
79  factory();
80 
84  virtual ~factory();
85 
89  T* new_instance(const std::string& xclient_class_name);
90 
94  template<typename S>
95  T* new_instance(const std::string& xclient_class_name, S& xarg);
96 
100  void insert_prototype(T* xprototype);
101 
105  void delete_prototype(const std::string& xclass_name);
106 
111  bool contains_prototype(const std::string& xclass_name) const;
112 
113 private:
114 
119  factory(const factory& xother);
120 
124  typedef std::map<std::string, T*> prototypes_map_type;
125 
129  prototypes_map_type _prototypes_map;
130 };
131 
132 // ===========================================================
133 // NON-MEMBER FUNCTIONS
134 // ===========================================================
135 
139 template <typename T>
140 std::ostream& operator << (std::ostream& xos, const factory<T>& xf);
141 
142 } // namespace sheaf
143 
144 #endif // ifndef FACTORY_H
bool contains_prototype(const std::string &xclass_name) const
True if the set of prototypes contains a prototype for handles of type xclass_name.
Definition: factory.impl.h:212
T * new_instance(const std::string &xclient_class_name)
Creates an instance of type xclient_class_name.
Definition: factory.impl.h:91
Namespace for the sheaves component of the sheaf system.
virtual ~factory()
Destructor.
Definition: factory.impl.h:61
factory()
Default constructor.
Definition: factory.impl.h:48
void insert_prototype(T *xprototype)
Sets xprototype as the prototype for its client class.
Definition: factory.impl.h:144
void delete_prototype(const std::string &xclass_name)
Removes the prototype for handles of type xclass_name.
Definition: factory.impl.h:182