OpenSplice ISO C++ 2 FACE API
v6.x
OpenSplice Future Airborne Capability Environment (FACE) ISO C++ 2 API
ConnectionFactory.hpp
Go to the documentation of this file.
1
/*
2
* Vortex OpenSplice
3
*
4
* This software and documentation are Copyright 2006 to 2021 ADLINK
5
* Technology Limited, its affiliated companies and licensors. All rights
6
* reserved.
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*
20
*/
21
#ifndef VORTEX_FACE_CONNECTION_FACTORY_HPP_
22
#define VORTEX_FACE_CONNECTION_FACTORY_HPP_
23
24
#include "
Vortex_FACE.hpp
"
25
#include "
Vortex/FACE/AnyConnection.hpp
"
26
27
namespace
Vortex
{
28
namespace
FACE
{
29
30
/*
31
* This class is mainly a map of <type name, typed create function>
32
* pairs. The 'type name' is the key, while the 'typed create function'
33
* can be used to create Connection<TYPE> objects.
34
*
35
* When the type is found in the map, then the 'second' part of
36
* the found pair is actually the templated create function
37
* "newConnection<TYPE>".
38
* Meaning that the it->second() will return a new instance of
39
* the Connection<TYPE> cast to AnyConnection.
40
*/
41
class
VORTEX_FACE_API
ConnectionFactory
42
{
43
public
:
44
typedef
std::map<std::string, AnyConnection*(*)()>
CF_MAP_TYPE
;
45
46
/*
47
* This function can be used to create a Connection<TYPE>:
48
* AnyConnection *anyConnection = ConnectionFactory::createConnection("Space::Type1");
49
* Connection<Space::Type1> *typedConnection = dynamic_cast< Connection<Space::Type1> >(anyConnection);
50
* typedConnection->doTypedStuff();
51
*/
52
static
AnyConnection
*
53
createConnection(
const
std::string &typeName);
54
55
/*
56
* This function can be used to check if this factory can create
57
* Connection of the given type.
58
*/
59
static
bool
60
knows(
const
std::string &typeName);
61
62
protected
:
63
/* Templated function to create a typed Connection. */
64
template
<
typename
TYPE>
65
static
AnyConnection
*
66
newConnection() {
67
return
new
TYPE;
68
}
69
70
/* Function to get the global factory map. */
71
static
CF_MAP_TYPE*
72
getMap();
73
74
private
:
75
/* Translate java style typename "Space.Type1" to a
76
* C++ style typeName "Space::Type1". */
77
std::string
78
static
translate(
const
std::string &typeName);
79
};
80
81
82
83
/*
84
* This class will add a templated create function "newConnection<TYPE>"
85
* to the ConnectionFactory map with the type name as key.
86
*
87
* This class will be a static member variable of the specialized typed
88
* connections which means that typed creation function is registered
89
* automatically for the given typed connection.
90
*
91
* Example for Space::Type1:
92
*
93
* class SpaceType1ConnectionRegistration
94
* {
95
* static ConnectionFactoryTypeRegister< Connection<Space::Type1> > reg;
96
* };
97
* ConnectionFactoryTypeRegister< Connection<Space::Type1> > SpaceType1ConnectionRegistration::reg("Space::Type1");
98
*
99
* The initialization of SpaceType1ConnectionRegistration::reg; will result
100
* in a <type name, typed create function> pair in the ConnectionFactory map.
101
*/
102
template
<
typename
TYPE>
103
struct
ConnectionFactoryTypeRegister
:
ConnectionFactory
{
104
/* When this class is a static object, then this constructor is called at
105
* startup. This means that the related type is registered at startup as well */
106
ConnectionFactoryTypeRegister
(std::string
const
& typeName) {
107
/* Add the <type name, typed create function> pair to the factory. */
108
getMap()->insert(std::pair<std::string,
AnyConnection
*(*)()>(typeName, &newConnection<TYPE>));
109
}
110
};
111
112
113
};
/* namespace FACE */
114
};
/* namespace Vortex */
115
116
#endif
/* VORTEX_FACE_REPORT_SUPPORT_HPP_ */
Vortex::FACE::ConnectionFactoryTypeRegister
Definition:
ConnectionFactory.hpp:103
AnyConnection.hpp
FACE
Definition:
Vortex_FACE.hpp:26
Vortex::FACE::ConnectionFactory::CF_MAP_TYPE
std::map< std::string, AnyConnection *(*)()> CF_MAP_TYPE
Definition:
ConnectionFactory.hpp:44
Vortex::FACE::ConnectionFactoryTypeRegister::ConnectionFactoryTypeRegister
ConnectionFactoryTypeRegister(std::string const &typeName)
Definition:
ConnectionFactory.hpp:106
Vortex::FACE::ConnectionFactory
Definition:
ConnectionFactory.hpp:41
Vortex_FACE.hpp
Vortex
Definition:
AnyConnection.hpp:27
VORTEX_FACE_API
#define VORTEX_FACE_API
Definition:
Macros.hpp:34
Vortex::FACE::AnyConnection
Definition:
AnyConnection.hpp:30
face
cpp
include
Vortex
FACE
ConnectionFactory.hpp
Generated by
1.8.13