types.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Johannes Meyer, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #include <introspection/type.h>
30 
31 namespace cpp_introspection {
32 
33  static V_Type g_types;
35 
36  namespace {
37  static Type::StaticInitializer ros_bool (TypePtr(new BoolType("bool")));
38  static Type::StaticInitializer ros_int8 (TypePtr(new NumericType<int8_t>("int8")));
39  static Type::StaticInitializer ros_uint8 (TypePtr(new NumericType<uint8_t>("uint8")));
40  static Type::StaticInitializer ros_int16 (TypePtr(new NumericType<int16_t>("int16")));
41  static Type::StaticInitializer ros_uint16 (TypePtr(new NumericType<uint16_t>("uint16")));
42  static Type::StaticInitializer ros_int32 (TypePtr(new NumericType<int32_t>("int32")));
43  static Type::StaticInitializer ros_uint32 (TypePtr(new NumericType<uint32_t>("uint32")));
44  static Type::StaticInitializer ros_int64 (TypePtr(new NumericType<int64_t>("int64")));
45  static Type::StaticInitializer ros_uint64 (TypePtr(new NumericType<uint64_t>("uint64")));
46  static Type::StaticInitializer ros_float32 (TypePtr(new NumericType<float>("float32")));
47  static Type::StaticInitializer ros_float64 (TypePtr(new NumericType<double>("float64")));
48  static Type::StaticInitializer ros_string (TypePtr(new StringType("string")));
49  static Type::StaticInitializer ros_time (TypePtr(new TimeType("time")));
50  static Type::StaticInitializer ros_duration(TypePtr(new DurationType("duration")));
51  static Type::StaticInitializer ros_byte (TypePtr(new NumericType<int8_t>("byte")));
52  static Type::StaticInitializer ros_char (TypePtr(new NumericType<uint8_t>("char")));
53  } // namespace
54 
55  const TypePtr& Type::add(const TypePtr& type, const std::string& alias)
56  {
57  if (alias.empty()) {
58  g_types.push_back(type);
59  g_types_by_name[type->getName()] = type;
60  } else {
61  g_types_by_name[alias] = type;
62  }
63  return type;
64  }
65 
67  {
68  Type::add(type);
69  }
70 
71  TypePtr Type::alias(const std::string& name) const
72  {
73  return add(shared_from_this(), name);
74  }
75 
77  static TypePtr s_instance;
78  if (!s_instance) s_instance.reset(new UnknownType);
79  return s_instance;
80  }
81 
82  TypePtr type(const std::string& name)
83  {
84  if (!g_types_by_name.count(name)) return UnknownType::Instance();
85  return g_types_by_name[name].lock();
86  }
87 
88 } // namespace cpp_introspection
static TypePtr Instance()
Definition: types.cpp:76
static const TypePtr & add(const TypePtr &type, const std::string &alias=std::string())
Definition: types.cpp:55
std::vector< TypePtr > V_Type
Definition: forwards.h:59
TypePtr type(const std::string &name)
Definition: types.cpp:82
std::map< std::string, TypeWPtr > M_Type
Definition: forwards.h:64
static M_Type g_types_by_name
Definition: types.cpp:34
static V_Type g_types
Definition: types.cpp:33
StaticInitializer(const TypePtr &type)
Definition: types.cpp:66
TypePtr alias(const std::string &name) const
Definition: types.cpp:71
boost::shared_ptr< Type const > TypePtr
Definition: forwards.h:52


cpp_introspection
Author(s): Johannes Meyer
autogenerated on Mon Jun 10 2019 12:56:18