AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
sdsarray.hh
Go to the documentation of this file.
1#ifndef _DRAMA2_SDSARRAY_INC
2#define _DRAMA2_SDSARRAY_INC
3
16/*
17 * History:
18 07-Jan-2014 - TJF - Original version
19 */
20#include "sds.h"
21#include <string>
22
23namespace drama {
24
25 namespace sds {
26
42 template<typename SDS_T> int CodeForType() { return -1; }
43
48 template <> int CodeForType<double>();
53 template <> int CodeForType<float>();
58 template <> int CodeForType<short>();
63 template <> int CodeForType<INT32>();
68 template <> int CodeForType<INT64>();
73 template <> int CodeForType<unsigned short>();
78 template <> int CodeForType<UINT32>();
83 template <> int CodeForType<UINT64>();
88 template <> int CodeForType<signed char>();
93 template <> int CodeForType<unsigned char>();
94 //template <> int CodeForType<std::string>();
99 template <> int CodeForType<const std::string&>();
105 template <> int CodeForType<char>();
106
111 template <> int CodeForType<bool> ();
112
113
114 class Id;
116
117
153 template <typename T> class ArrayAccessHelper {
154 public:
155 friend class drama::sds::Id;
156 private:
157 SdsCodeType code; /* The SDS code of the item */
158 unsigned long elements; /* Number of element in the array */
159 T* data; /* The array pointer is written here */
160
161 /*
162 * Remaining private items used by sds::Id to set this item up.
163 */
164 /*
165 * Set the data pointer to be the specified address.
166 */
167 void SetDataToAddr(void *dataAddr) {
168 data = static_cast<T*>(dataAddr);
169 }
170
171 /*
172 * Set the number of elements in the array.
173 *
174 * This is used by SdsId.AccessArray() set the number of
175 * elements in the array.
176 */
177 void SetNumElements(unsigned long nelem) {
178 elements = nelem;
179 }
181 protected:
182
183 /*
184 * Helper function used to check an index is valid. Also checks
185 * that we have some data. Throws expections on problems.
186 */
187 void CheckIndexAndData(unsigned long index) const {
188 if (!data)
189 {
191 "drama::Sds::ArrayAccessHelper Index %, Code %, elements % - data is invalid", index, code, elements);
192 }
193 if (index >= elements)
194 {
196 "drama::Sds::ArrayAccessHelper Index %, Code %, elements % - index is invalid", index, code, elements);
197 }
198 }
199
200
201
206 T * GetDataAddress() {
207 return this->data;
208 }
213 const T * GetDataAddress() const {
214 return this->data;
215 }
216
217 public:
224 ArrayAccessHelper() : code(CodeForType<T>()), elements(0), data(0) {
225 if ((code < 0)||(code > SDS_C_MAXCODE))
227 "ArrayAccessHelper constructor with invalid code %, must be in range 0 to %s",
228 code, SDS_C_MAXCODE);
229 }
230
235 SdsCodeType Code() const { return code; }
240 unsigned long Size() const { return elements; }
241
242
243 }; /* Sds::ArrayAccessHelper */
244
245
276 template <typename T> class ArrayWriteHelper : public ArrayAccessHelper<T> {
277 public:
284 ArrayWriteHelper() { }
285
293 T & operator[](const unsigned long index) {
294 /* Note, "this->" is required for both of these to avoid
295 * compiler not knowing the type applied to the code
296 */
297 this->CheckIndexAndData(index);
298 return this->GetDataAddress()[index];
299 }
307 T const & operator[](const unsigned long index) const {
308 /* Note, "this->" is required for both of these to avoid
309 * compiler not knowing the type applied to the code
310 */
311 this->CheckIndexAndData(index);
312 return this->GetDataAddress()[index];
313 }
314
323 T * DataAddress() {
324 return this->GetDataAddress();
325 }
326 }; /* Sds::ArrayWriteHelper */
327
358 template <typename T> class ArrayReadHelper : public ArrayAccessHelper<T> {
359 public:
366 ArrayReadHelper() { }
367
375 T const & operator[](const unsigned long index) const {
376 /* Note, "this->" is required for both of these to avoid
377 * compiler not knowing the type applied to the code
378 */
379 this->CheckIndexAndData(index);
380 return this->GetDataAddress()[index];
381 }
390 const T * DataAddress() const {
391 return this->GetDataAddress();
392 }
393 }; /* Sds::ArrayReadHelper */
394
395
396
397
398 } // namespace sds
399
400} // namespace drama
401
402#endif
SdsCodeType Code() const
Return the SDS type code of the item being accessed.
Definition sdsarray.hh:262
ArrayAccessHelper()
Create a drama::sds::ArrayAccessHelper object.
Definition sdsarray.hh:251
unsigned long Size() const
Return the number of elements in the array.
Definition sdsarray.hh:267
const T * GetDataAddress() const
Return the address of the data.
Definition sdsarray.hh:240
T * GetDataAddress()
Return the address of the data.
Definition sdsarray.hh:233
Helper class for access to an SDS Scalar Arrays.
Definition sdsarray.hh:180
ArrayReadHelper()
Create a drama::sds::ArrayReadHelper object.
Definition sdsarray.hh:393
T const & operator[](const unsigned long index) const
SDS array subscript operator.
Definition sdsarray.hh:402
const T * DataAddress() const
Access the data directly - read only.
Definition sdsarray.hh:417
Helper class for reading data from SDS Scalar Arrays.
Definition sdsarray.hh:385
ArrayWriteHelper()
Create a drama::sds::ArrayWriteHelper object.
Definition sdsarray.hh:311
T & operator[](const unsigned long index)
SDS array subscript operator - non-const version.
Definition sdsarray.hh:320
T const & operator[](const unsigned long index) const
SDS array subscript operator - const version.
Definition sdsarray.hh:334
T * DataAddress()
Access the data directly.
Definition sdsarray.hh:350
Helper class for writing data to SDS Scalar Arrays.
Definition sdsarray.hh:303
A C++ Interface to the handling SDS structures.
Definition sds.hh:428
#define DramaTHROW_S(status_, format_,...)
Throw a Drama exception with safe string formatting.
Definition exception.hh:110
int CodeForType< short >()
Returns the SDS type for a short - SDS_SHORT.
int CodeForType< unsigned short >()
Returns the SDS type for an unsigned short - SDS_USHORT.
int CodeForType< double >()
Returns the SDS type for a double - SDS_DOUBLE.
int CodeForType< const std::string & >()
Returns the SDS type for a string - ARG_STRING.
int CodeForType< signed char >()
Returns the SDS type for a signed char - SDS_BYTE.
int CodeForType< char >()
Returns the SDS type for a char - SDS_CHAR.
int CodeForType< unsigned char >()
Returns the SDS type for an unsigned char - SDS_UBYTE.
int CodeForType< INT64 >()
Returns the SDS type for a 64 bit integer - SDS_I64.
int CodeForType()
Functions which returns the SDS type of a given C type.
Definition sdsarray.hh:69
int CodeForType< UINT32 >()
Returns the SDS type for an unsigned integer - SDS_UINT.
int CodeForType< float >()
Returns the SDS type for a flat - SDS_FLOAT.
int CodeForType< UINT64 >()
Returns the SDS type for an unsigned 64 bit integer - SDS_UI64.
int CodeForType< INT32 >()
Returns the SDS type for a 32 bit integer - SDS_INT.
int CodeForType< bool >()
Return the SDS type code for C - SDS_SHORT
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1322
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93