DataType.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
26 
27 namespace variant_topic_tools {
28 
29 /*****************************************************************************/
30 /* Constructors and Destructor */
31 /*****************************************************************************/
32 
34 }
35 
36 DataType::DataType(const char* identifier) {
37  DataTypeRegistry registry;
38  DataType dataType = registry.getDataType(identifier);
39 
40  impl = dataType.impl;
41 }
42 
43 DataType::DataType(const std::string& identifier) {
44  DataTypeRegistry registry;
45  DataType dataType = registry.getDataType(identifier);
46 
47  impl = dataType.impl;
48 }
49 
50 DataType::DataType(const std::type_info& typeInfo) {
51  DataTypeRegistry registry;
52  DataType dataType = registry.getDataType(typeInfo);
53 
54  impl = dataType.impl;
55 }
56 
58  if (src.impl)
59  impl.reset(new boost::shared_ptr<Impl>(*src.impl));
60 }
61 
63 }
64 
66 }
67 
69 }
70 
71 /*****************************************************************************/
72 /* Accessors */
73 /*****************************************************************************/
74 
75 const std::string& DataType::getIdentifier() const {
76  if (!impl) {
77  static std::string identifier;
78  return identifier;
79  }
80  else
81  return (*impl)->getIdentifier();
82 }
83 
84 const std::type_info& DataType::getTypeInfo() const {
85  if (impl)
86  return (*impl)->getTypeInfo();
87  else
88  return typeid(void);
89 }
90 
91 size_t DataType::getSize() const {
92  if (impl)
93  return (*impl)->getSize();
94  else
95  return 0;
96 }
97 
98 bool DataType::isArray() const {
99  if (impl)
100  return boost::dynamic_pointer_cast<ArrayDataType::Impl>(*impl) != nullptr;
101  else
102  return false;
103 }
104 
105 bool DataType::isBuiltin() const {
106  if (impl)
107  return boost::dynamic_pointer_cast<BuiltinDataType::Impl>(*impl) != nullptr;
108  else
109  return false;
110 }
111 
112 bool DataType::isMessage() const {
113  if (impl)
114  return boost::dynamic_pointer_cast<MessageDataType::Impl>(*impl) != nullptr;
115  else
116  return false;
117 }
118 
119 bool DataType::isFixedSize() const {
120  if (impl)
121  return (*impl)->isFixedSize();
122  else
123  return true;
124 }
125 
126 bool DataType::isSimple() const {
127  if (impl)
128  return (*impl)->isSimple();
129  else
130  return true;
131 }
132 
133 bool DataType::isValid() const {
134  return impl != nullptr;
135 }
136 
137 bool DataType::hasTypeInfo() const {
138  if (impl)
139  return ((*impl)->getTypeInfo() != typeid(void));
140  else
141  return false;
142 }
143 
144 const std::type_info& DataType::Impl::getTypeInfo() const {
145  return typeid(void);
146 }
147 
148 /*****************************************************************************/
149 /* Methods */
150 /*****************************************************************************/
151 
153  impl.reset();
154 }
155 
156 void DataType::write(std::ostream& stream) const {
157  if (impl)
158  stream << (*impl)->getIdentifier();
159 }
160 
162  if (impl)
163  return (*impl)->createSerializer(*this);
164  else
165  return Serializer();
166 }
167 
169  if (impl)
170  return (*impl)->createVariant(*this);
171  else
172  return Variant();
173 }
174 
175 /*****************************************************************************/
176 /* Operators */
177 /*****************************************************************************/
178 
180  if (impl && src.impl)
181  *impl = *src.impl;
182  else if (src.impl)
183  impl.reset(new boost::shared_ptr<Impl>(*src.impl));
184  else
185  impl = src.impl;
186 
187  return *this;
188 }
189 
190 std::ostream& operator<<(std::ostream& stream, const DataType& dataType) {
191  dataType.write(stream);
192  return stream;
193 }
194 
195 }
Header file providing the DataType class interface.
Serializer createSerializer() const
Create a serializer for this data type.
Definition: DataType.cpp:161
bool hasTypeInfo() const
True, if this data type has type information.
Definition: DataType.cpp:137
Header file providing the Serializer class interface.
Header file providing the ArrayDataType class interface.
bool isArray() const
True, if this data type represents an array type.
Definition: DataType.cpp:98
bool isSimple() const
True, if this data type represents a simple data type, i.e., a data type such that an array of its in...
Definition: DataType.cpp:126
bool isMessage() const
True, if this data type represents a message type.
Definition: DataType.cpp:112
Header file providing the Variant class interface.
Built-in data type implementation.
const std::type_info & getTypeInfo() const
Retrieve the type information associated with this data type.
Definition: DataType.cpp:84
bool isValid() const
True, if this data type is valid.
Definition: DataType.cpp:133
ImplPtr impl
The data type&#39;s implementation adapter.
Definition: DataType.h:226
const std::string & getIdentifier() const
Retrieve the identifier representing this data type.
Definition: DataType.cpp:75
virtual ~DataType()
Destructor.
Definition: DataType.cpp:62
virtual const std::type_info & getTypeInfo() const
Retrieve the type information associated with this data type.
Definition: DataType.cpp:144
Header file providing the DataTypeRegistry class interface.
virtual DataType & operator=(const DataType &src)
Assignment operator.
Definition: DataType.cpp:179
std::ostream & operator<<(std::ostream &stream, const DataType &dataType)
Operator for writing the data type to a stream.
Definition: DataType.cpp:190
Header file providing the MessageDataType class interface.
DataType getDataType(const std::string &identifier)
Retrieve a data type from the registry by identifier (non-const version)
void write(std::ostream &stream) const
Write the data type to a stream.
Definition: DataType.cpp:156
Array data type implementation.
Definition: ArrayDataType.h:74
Message data type implementation.
bool isFixedSize() const
True, if this data type represents a fixed-size data type, as opposed to a variable-size data type...
Definition: DataType.cpp:119
size_t getSize() const
Retrieve the size of the instances of this data type.
Definition: DataType.cpp:91
Variant createVariant() const
Create a variant from this data type.
Definition: DataType.cpp:168
bool isBuiltin() const
True, if this data type represents a built-in type.
Definition: DataType.cpp:105
void clear()
Clear the data type.
Definition: DataType.cpp:152
virtual ~Impl()
Destructor.
Definition: DataType.cpp:68
Header file providing the BuiltinDataType class interface.
DataType()
Default constructor.
Definition: DataType.cpp:33


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49