Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArrayContainer.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2006-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Lars Hagström / stlrha
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 
25 #ifndef __DOTS_ARRAY_CONTAINER_H__
26 #define __DOTS_ARRAY_CONTAINER_H__
27 
31 
32 namespace Safir
33 {
34 namespace Dob
35 {
36 namespace Typesystem
37 {
57  template <class T>
58  class ArrayContainer : private std::vector<T>
59  {
60  private:
61  typedef std::vector<T> Vector;
62  public:
63 
73  explicit ArrayContainer(const Int32 size):
74  std::vector<T>(size),
75  m_size(size)
76  {
77  if (size <= 0)
78  {
79  throw IllegalValueException(L"Arrays must be at least one in length!",__WFILE__,__LINE__);
80  }
81  }
82 
91  std::vector<T>(other),
92  m_size(other.m_size)
93  {
94 
95  }
96 
108  {
109  if (other.size() != size())
110  {
111  throw SoftwareViolationException(L"You are not allowed to copy arrays of different sizes",__WFILE__,__LINE__);
112  }
113  std::vector<T>::operator=(other);
114  m_size = other.size();
115  return *this;
116  }
117 
118  //This may change to become a bidirectional iterator in the future (it is random access now)
119  typedef typename Vector::iterator iterator;
120  typedef typename Vector::const_iterator const_iterator;
121  typedef typename Vector::reference reference;
122  typedef typename Vector::const_reference const_reference;
123 
129  using Vector::begin;
130  using Vector::end;
131 
138  Int32 size() const {return m_size;}
139 
149  {
150  if (index < 0 || index >= m_size)
151  {
152  throw IllegalValueException(L"Illegal array index!",__WFILE__,__LINE__);
153  }
154  return Vector::operator[](index);
155  }
156 
165  const_reference operator[](const Int32 index) const
166  {
167  if (index < 0 || index >= m_size)
168  {
169  throw IllegalValueException(L"Illegal array index!",__WFILE__,__LINE__);
170  }
171  return Vector::operator[](index);
172  }
173 
181  bool IsChanged() const
182  {
183  return end() != std::find_if(begin(),end(),&Typesystem::IsChanged);
184  }
185 
193  void SetChanged(bool changed)
194  {
195  const_iterator e = end();
196  for (iterator it = begin(); it!=e;++it)
197  {
198  it->SetChanged(changed);
199  }
200  }
201  private:
202  Int32 m_size;
203  };
204 
205 
213 
216 
219 
222 
225 
228 
231 
234 
237 
240 
243 
246 
249 
252  //--------------------------------------------------
253  // SI-types (32-bits)
254  //--------------------------------------------------
255  namespace Si32
256  {
259 
262 
265 
268 
271 
274 
277 
280 
283 
286 
289 
292 
295 
298 
301 
304 
307 
310 
313  }
314 
315  //--------------------------------------------------
316  // SI-types (64-bits)
317  //--------------------------------------------------
318  namespace Si64
319  {
322 
325 
328 
331 
334 
337 
340 
343 
346 
349 
352 
355 
358 
361 
364 
367 
370 
373 
376  }
377 }
378 }
379 }
380 #endif
381 
ArrayContainer< WattContainer > WattContainerArray
An array of DOB-containers containing 64 bit Watt values.
Definition: ArrayContainer.h:375
ArrayContainer< PascalContainer > PascalContainerArray
An array of DOB-containers containing 64 bit Pascal values.
Definition: ArrayContainer.h:351
ArrayContainer< BooleanContainer > BooleanContainerArray
An array of DOB-containers containing booleans.
Definition: ArrayContainer.h:212
ArrayContainer(const ArrayContainer &other)
Copy Constructor.
Definition: ArrayContainer.h:90
void SetChanged(bool changed)
Set the change flag on all elements in the array.
Definition: ArrayContainer.h:193
ArrayContainer< NewtonContainer > NewtonContainerArray
An array of DOB-containers containing 64 bit Newton values.
Definition: ArrayContainer.h:348
ArrayContainer< RadianContainer > RadianContainerArray
An array of DOB-containers containing 64 bit Radian values.
Definition: ArrayContainer.h:354
ArrayContainer< JouleContainer > JouleContainerArray
An array of DOB-containers containing 64 bit Joule values.
Definition: ArrayContainer.h:330
ArrayContainer< SquareMeterContainer > SquareMeterContainerArray
An array of DOB-containers containing 32 bit SquareMeter values.
Definition: ArrayContainer.h:303
ArrayContainer< KelvinContainer > KelvinContainerArray
An array of DOB-containers containing 32 bit Kelvin values.
Definition: ArrayContainer.h:270
Vector::const_reference const_reference
Definition: ArrayContainer.h:122
ArrayContainer< TypeIdContainer > TypeIdContainerArray
An array of DOB-containers containing TypeIds.
Definition: ArrayContainer.h:227
ArrayContainer< VoltContainer > VoltContainerArray
An array of DOB-containers containing 32 bit Volt values.
Definition: ArrayContainer.h:309
bool IsChanged() const
Check if any element has a change flag set on it.
Definition: ArrayContainer.h:181
ArrayContainer< AmpereContainer > AmpereContainerArray
An array of DOB-containers containing 64 bit Ampere values.
Definition: ArrayContainer.h:321
ArrayContainer< RadianPerSecondSquaredContainer > RadianPerSecondSquaredContainerArray
An array of DOB-containers containing 32 bit RadianPerSecondSquared values.
Definition: ArrayContainer.h:297
ArrayContainer & operator=(const ArrayContainer &other)
Copy Assignment operator.
Definition: ArrayContainer.h:107
ArrayContainer< SecondContainer > SecondContainerArray
An array of DOB-containers containing 32 bit Second values.
Definition: ArrayContainer.h:300
Meant to be used when something goes very wrong.
Definition: Exceptions.h:360
ArrayContainer< SecondContainer > SecondContainerArray
An array of DOB-containers containing 64 bit Second values.
Definition: ArrayContainer.h:363
ArrayContainer< NewtonContainer > NewtonContainerArray
An array of DOB-containers containing 32 bit Newton values.
Definition: ArrayContainer.h:285
ArrayContainer< Int64Container > Int64ContainerArray
An array of DOB-containers containing 64 bit integers.
Definition: ArrayContainer.h:218
ArrayContainer< RadianPerSecondSquaredContainer > RadianPerSecondSquaredContainerArray
An array of DOB-containers containing 64 bit RadianPerSecondSquared values.
Definition: ArrayContainer.h:360
ArrayContainer< WattContainer > WattContainerArray
An array of DOB-containers containing 32 bit Watt values.
Definition: ArrayContainer.h:312
ArrayContainer< SteradianContainer > SteradianContainerArray
An array of DOB-containers containing 64 bit Steradian values.
Definition: ArrayContainer.h:369
ArrayContainer(const Int32 size)
Constructor with size.
Definition: ArrayContainer.h:73
ArrayContainer< MeterContainer > MeterContainerArray
An array of DOB-containers containing 32 bit Meter values.
Definition: ArrayContainer.h:276
ArrayContainer< MeterPerSecondContainer > MeterPerSecondContainerArray
An array of DOB-containers containing 32 bit MeterPerSecond values.
Definition: ArrayContainer.h:279
ArrayContainer< Float64Container > Float64ContainerArray
An array of DOB-containers containing 64 bit floats.
Definition: ArrayContainer.h:224
ArrayContainer< SteradianContainer > SteradianContainerArray
An array of DOB-containers containing 32 bit Steradian values.
Definition: ArrayContainer.h:306
ArrayContainer< MeterPerSecondSquaredContainer > MeterPerSecondSquaredContainerArray
An array of DOB-containers containing 64 bit MeterPerSecondSquared values.
Definition: ArrayContainer.h:345
ArrayContainer< AmpereContainer > AmpereContainerArray
An array of DOB-containers containing 32 bit Ampere values.
Definition: ArrayContainer.h:258
ArrayContainer< MeterPerSecondSquaredContainer > MeterPerSecondSquaredContainerArray
An array of DOB-containers containing 32 bit MeterPerSecondSquared values.
Definition: ArrayContainer.h:282
Vector::const_iterator const_iterator
Definition: ArrayContainer.h:120
#define __WFILE__
Definition: Exceptions.h:31
ArrayContainer< HertzContainer > HertzContainerArray
An array of DOB-containers containing 32 bit Hertz values.
Definition: ArrayContainer.h:264
A parameter in the call was invalid.
Definition: Exceptions.h:254
ArrayContainer< KilogramContainer > KilogramContainerArray
An array of DOB-containers containing 64 bit Kilogram values.
Definition: ArrayContainer.h:336
ArrayContainer< MeterPerSecondContainer > MeterPerSecondContainerArray
An array of DOB-containers containing 64 bit MeterPerSecond values.
Definition: ArrayContainer.h:342
ArrayContainer< MeterContainer > MeterContainerArray
An array of DOB-containers containing 64 bit Meter values.
Definition: ArrayContainer.h:339
Int32 size() const
Get the size of the array.
Definition: ArrayContainer.h:138
ArrayContainer< SquareMeterContainer > SquareMeterContainerArray
An array of DOB-containers containing 64 bit SquareMeter values.
Definition: ArrayContainer.h:366
ArrayContainer< ChannelIdContainer > ChannelIdContainerArray
An array of DOB-containers containing ChannelIds.
Definition: ArrayContainer.h:236
ArrayContainer< KelvinContainer > KelvinContainerArray
An array of DOB-containers containing 64 bit Kelvin values.
Definition: ArrayContainer.h:333
ArrayContainer< CubicMeterContainer > CubicMeterContainerArray
An array of DOB-containers containing 32 bit CubicMeter values.
Definition: ArrayContainer.h:261
ArrayContainer< HertzContainer > HertzContainerArray
An array of DOB-containers containing 64 bit Hertz values.
Definition: ArrayContainer.h:327
ArrayContainer< Float32Container > Float32ContainerArray
An array of DOB-containers containing 32 bit floats.
Definition: ArrayContainer.h:221
Vector::reference reference
Definition: ArrayContainer.h:121
ArrayContainer< RadianPerSecondContainer > RadianPerSecondContainerArray
An array of DOB-containers containing 64 bit RadianPerSecond values.
Definition: ArrayContainer.h:357
ArrayContainer< VoltContainer > VoltContainerArray
An array of DOB-containers containing 64 bit Volt values.
Definition: ArrayContainer.h:372
ArrayContainer< StringContainer > StringContainerArray
An array of DOB-containers containing strings.
Definition: ArrayContainer.h:242
Safir::Dob::Typesystem::ArrayContainer< ObjectContainer > ObjectContainerArray
An array of DOB-containers containing DOB-objects.
Definition: ArrayContainer.h:245
ArrayContainer< RadianPerSecondContainer > RadianPerSecondContainerArray
An array of DOB-containers containing 32 bit RadianPerSecond values.
Definition: ArrayContainer.h:294
reference operator[](const Int32 index)
Returns a reference to the vector element at a specified position.
Definition: ArrayContainer.h:148
ArrayContainer< EntityIdContainer > EntityIdContainerArray
An array of DOB-containers containing EntityIds.
Definition: ArrayContainer.h:233
ArrayContainer< HandlerIdContainer > HandlerIdContainerArray
An array of DOB-containers containing HandlerIds.
Definition: ArrayContainer.h:239
Safir::Dob::Typesystem::ArrayContainer< BinaryContainer > BinaryContainerArray
An array of DOB-containers containing Binaries.
Definition: ArrayContainer.h:248
ArrayContainer< InstanceIdContainer > InstanceIdContainerArray
An array of DOB-containers containing InstanceIds.
Definition: ArrayContainer.h:230
Vector::iterator iterator
Definition: ArrayContainer.h:119
ArrayContainer< PascalContainer > PascalContainerArray
An array of DOB-containers containing 32 bit Pascal values.
Definition: ArrayContainer.h:288
STL container for arrays of DOB-containers.
Definition: ArrayContainer.h:58
ArrayContainer< JouleContainer > JouleContainerArray
An array of DOB-containers containing 32 bit Joule values.
Definition: ArrayContainer.h:267
ArrayContainer< KilogramContainer > KilogramContainerArray
An array of DOB-containers containing 32 bit Kilogram values.
Definition: ArrayContainer.h:273
DotsC_Int32 Int32
32 bit integer type.
Definition: Defs.h:67
ArrayContainer< CubicMeterContainer > CubicMeterContainerArray
An array of DOB-containers containing 64 bit CubicMeter values.
Definition: ArrayContainer.h:324
ArrayContainer< Int32Container > Int32ContainerArray
An array of DOB-containers containing 32 bit integers.
Definition: ArrayContainer.h:215
const_reference operator[](const Int32 index) const
Returns a const reference to the vector element at a specified position.
Definition: ArrayContainer.h:165
static bool IsChanged(const ContainerBase &container)
Check if a container is changed.
Definition: ContainerBase.h:134
ArrayContainer< RadianContainer > RadianContainerArray
An array of DOB-containers containing 32 bit Radian values.
Definition: ArrayContainer.h:291