ArrayDataType.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 
23 
24 namespace variant_topic_tools {
25 
26 /*****************************************************************************/
27 /* Constructors and Destructor */
28 /*****************************************************************************/
29 
31 }
32 
33 ArrayDataType::ArrayDataType(const DataType& memberType, size_t numMembers) {
35  new ImplV(memberType, numMembers)));
36 }
37 
39  DataType(src) {
40 }
41 
43  DataType(src) {
44  if (impl)
45  BOOST_ASSERT(boost::dynamic_pointer_cast<Impl>(*impl));
46 }
47 
49 }
50 
51 ArrayDataType::Impl::Impl(const DataType& memberType) :
52  memberType(memberType) {
53  if (!memberType.isValid())
54  throw InvalidDataTypeException();
55 }
56 
58 }
59 
60 ArrayDataType::ImplV::ImplV(const DataType& memberType, size_t numMembers) :
61  Impl(memberType),
62  numMembers(numMembers) {
63 }
64 
66 }
67 
68 /*****************************************************************************/
69 /* Accessors */
70 /*****************************************************************************/
71 
73  if (!impl) {
74  static DataType memberType;
75  return memberType;
76  }
77  else
78  return boost::static_pointer_cast<Impl>(*impl)->memberType;
79 }
80 
82  if (impl)
83  return boost::static_pointer_cast<Impl>(*impl)->getNumMembers();
84  else
85  return 0;
86 }
87 
89  if (impl)
90  return boost::static_pointer_cast<Impl>(*impl)->isDynamic();
91  else
92  return 0;
93 }
94 
95 const std::string& ArrayDataType::Impl::getIdentifier() const {
96  if (identifier.empty()) {
98  "["+boost::lexical_cast<std::string>(getNumMembers())+"]" : "[]");
99  }
100 
101  return identifier;
102 }
103 
105  return numMembers;
106 }
107 
109  return numMembers*memberType.getSize();
110 }
111 
113  return !numMembers;
114 }
115 
117  return numMembers && memberType.isFixedSize();
118 }
119 
121  return false;
122 }
123 
124 /*****************************************************************************/
125 /* Methods */
126 /*****************************************************************************/
127 
130 }
131 
133  return ArrayVariant(type, memberType, numMembers);
134 }
135 
136 /*****************************************************************************/
137 /* Operators */
138 /*****************************************************************************/
139 
141  DataType::operator=(src);
142 
143  if (impl)
144  BOOST_ASSERT(boost::dynamic_pointer_cast<ArrayDataType::Impl>(*impl));
145 
146  return *this;
147 }
148 
149 }
Header file providing the ArraySerializer class interface.
Exception thrown in case of an invalid data type.
Definition: Exceptions.h:51
Serializer createSerializer() const
Create a serializer for this data type.
Definition: DataType.cpp:161
Header file providing the ArrayDataType class interface.
size_t getNumMembers() const
Retrieve the number of members of this array data type (implementation)
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
ArrayDataType & operator=(const DataType &src)
Assignment operator.
const std::string & getIdentifier() const
Retrieve the identifier representing this data type.
Definition: DataType.cpp:75
Variant createVariant(const DataType &type) const
Create a variant from this data type (re-implementation)
bool isSimple() const
True, if this data type represents a simple data type (implementation)
Header file defining exceptions for the variant topic tools.
ImplV(const DataType &memberType, size_t numMembers)
Constructor.
ArrayDataType()
Default constructor.
virtual DataType & operator=(const DataType &src)
Assignment operator.
Definition: DataType.cpp:179
size_t numMembers
The number of members of the array data type.
Header file providing the ArrayVariant class interface.
virtual bool isDynamic() const =0
True, if this array data type represents a dynamic array (abstract declaration)
Array data type implementation.
Definition: ArrayDataType.h:74
Array data type implementation (variant-typed version)
bool isDynamic() const
True, if this array data type represents a dynamic array.
const std::string & getIdentifier() const
Retrieve the identifier representing this data type (implementation)
Serializer createSerializer(const DataType &type) const
Create a serializer for this data type (re-implementation)
virtual ~ArrayDataType()
Destructor.
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
DataType memberType
The member type of the array data type.
size_t getSize() const
Retrieve the size of the instances of this data type.
Definition: DataType.cpp:91
std::string identifier
The identifier representing this array data type.
bool isDynamic() const
True, if this array data type represents a dynamic array (implementation)
virtual size_t getNumMembers() const =0
Retrieve the number of members of this array data type (abstract declaration)
const DataType & getMemberType() const
Retrieve the member type of this array data type.
size_t getNumMembers() const
Retrieve the number of members of this array data type.
size_t getSize() const
Retrieve the size of the instances of this data type (implementation)
bool isFixedSize() const
True, if this data type represents a fixed-size data type (implementation)


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