00001 //================================================================================================= 00002 // Copyright (c) 2011, Johannes Meyer, TU Darmstadt 00003 // All rights reserved. 00004 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are met: 00007 // * Redistributions of source code must retain the above copyright 00008 // notice, this list of conditions and the following disclaimer. 00009 // * Redistributions in binary form must reproduce the above copyright 00010 // notice, this list of conditions and the following disclaimer in the 00011 // documentation and/or other materials provided with the distribution. 00012 // * Neither the name of the Flight Systems and Automatic Control group, 00013 // TU Darmstadt, nor the names of its contributors may be used to 00014 // endorse or promote products derived from this software without 00015 // specific prior written permission. 00016 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 //================================================================================================= 00028 00029 #include <introspection/type.h> 00030 00031 namespace cpp_introspection { 00032 00033 static V_Type g_types; 00034 static M_Type g_types_by_name; 00035 00036 namespace { 00037 static Type::StaticInitializer ros_bool (TypePtr(new BoolType("bool"))); 00038 static Type::StaticInitializer ros_int8 (TypePtr(new NumericType<int8_t>("int8"))); 00039 static Type::StaticInitializer ros_uint8 (TypePtr(new NumericType<uint8_t>("uint8"))); 00040 static Type::StaticInitializer ros_int16 (TypePtr(new NumericType<int16_t>("int16"))); 00041 static Type::StaticInitializer ros_uint16 (TypePtr(new NumericType<uint16_t>("uint16"))); 00042 static Type::StaticInitializer ros_int32 (TypePtr(new NumericType<int32_t>("int32"))); 00043 static Type::StaticInitializer ros_uint32 (TypePtr(new NumericType<uint32_t>("uint32"))); 00044 static Type::StaticInitializer ros_int64 (TypePtr(new NumericType<int64_t>("int64"))); 00045 static Type::StaticInitializer ros_uint64 (TypePtr(new NumericType<uint64_t>("uint64"))); 00046 static Type::StaticInitializer ros_float32 (TypePtr(new NumericType<float>("float32"))); 00047 static Type::StaticInitializer ros_float64 (TypePtr(new NumericType<double>("float64"))); 00048 static Type::StaticInitializer ros_string (TypePtr(new StringType("string"))); 00049 static Type::StaticInitializer ros_time (TypePtr(new TimeType("time"))); 00050 static Type::StaticInitializer ros_duration(TypePtr(new DurationType("duration"))); 00051 static Type::StaticInitializer ros_byte (TypePtr(new NumericType<int8_t>("byte"))); 00052 static Type::StaticInitializer ros_char (TypePtr(new NumericType<uint8_t>("char"))); 00053 } // namespace 00054 00055 const TypePtr& Type::add(const TypePtr& type, const std::string& alias) 00056 { 00057 if (alias.empty()) { 00058 g_types.push_back(type); 00059 g_types_by_name[type->getName()] = type; 00060 } else { 00061 g_types_by_name[alias] = type; 00062 } 00063 return type; 00064 } 00065 00066 Type::StaticInitializer::StaticInitializer(const TypePtr& type) 00067 { 00068 Type::add(type); 00069 } 00070 00071 TypePtr Type::alias(const std::string& name) const 00072 { 00073 return add(shared_from_this(), name); 00074 } 00075 00076 TypePtr UnknownType::Instance() { 00077 static TypePtr s_instance; 00078 if (!s_instance) s_instance.reset(new UnknownType); 00079 return s_instance; 00080 } 00081 00082 TypePtr type(const std::string& name) 00083 { 00084 if (!g_types_by_name.count(name)) return UnknownType::Instance(); 00085 return g_types_by_name[name].lock(); 00086 } 00087 00088 } // namespace cpp_introspection