1#ifndef _DRAMA2_PARAMETER_INC
2#define _DRAMA2_PARAMETER_INC
37#include "DitsMonitor.h"
81 template<
typename SDS_T>
class Parameter {
88 std::weak_ptr<Task> _theTask;
89 const std::string _name;
104 const std::string &name,
141 operator SDS_T()
const {
186 return (this->
operator SDS_T() ==
rhs);
215 return (this->
operator SDS_T() !=
rhs);
261 template<>
class Parameter<
drama::sds::Id> {
267 std::weak_ptr<Task> _theTask;
268 const std::string _name;
286 const std::string &name,
336 void UpdateMonitors()
const;
388 std::weak_ptr<Task> _theTask;
389 const std::string _name;
408 const std::string &name,
439 template <
typename F>
442 auto id = _parSys.
Find(_name);
446 id.ArrayAccess(&array);
449 for (
unsigned i = 0 ;
i <
count ; ++
i)
467 "Error filling array parameter %, DitsMonitor() failed",
487 template <
class ContainerType>
492 auto id = _parSys.
Find(_name);
495 sds::ArrayWriteHelper<SDS_T> array;
496 id.ArrayAccess(&array);
510 for (
unsigned i = 0 ;
i <
count ; ++
i)
526 "Error setting array parameter %, DitsMonitor() failed",
537 std::vector<SDS_T> Get()
const {
541 auto id = _parSys.
Find(_name);
544 sds::ArrayReadHelper<SDS_T> array;
547 auto count = array.Size();
548 std::vector<SDS_T>
result;
553 for (
unsigned i = 0;
i <
count ; ++
i)
582 auto id = _parSys.
Find(_name);
585 sds::ArrayWriteHelper<SDS_T> array;
588 if (index >= array.Size())
591 "Tired to set index % in array parameter is size %",
592 index, array.Size());
613 "Error setting array parameter %, DitsMonitor() failed",
629 SDS_T Get(
size_t index)
const {
633 auto id = _parSys.
Find(_name);
636 sds::ArrayReadHelper<SDS_T> array;
639 if (index >= array.Size())
642 "Tired to set index % in array parameter is size %",
643 index, array.Size());
659 unsigned Size()
const {
662 auto id = _parSys.
Find(_name);
664 std::vector<unsigned>
dims;
667 if (
dims.size() != 1)
670 "Dimensions of array parameter is NOT 1. Can only use drama::ArrayParameter for single dimension array parameters");
755 std::weak_ptr<Task> _theTask;
756 const std::string _name;
776 const std::string &name,
832 typename std::enable_if<std::is_base_of<std::string,
833 typename ContainerType::value_type>
::value>
::type* =
nullptr>
838 auto id = _parSys.
Find(_name);
841 std::vector<unsigned long>
dims;
843 id.ArrayAccess(&array, 2, &
dims);
848 if (
dims.size() != 2)
851 "Dimensions of string array parameter is NOT 2. Can only use drama::ArrayParameter<std::string> for two dimension array parameters");
882 for (
unsigned i = 0 ;
i <
nVals ; ++
i)
903 "Error setting array parameter %, DitsMonitor() failed",
915 std::vector<std::string> Get()
const;
945 std::string Get(
size_t index)
const;
959 virtual unsigned Size()
const;
972 virtual unsigned Strlen()
const;
996 virtual std::string
operator[](
size_t index)
const {
std::string Get(size_t index) const
Return a single value from an array parameter.
virtual ~ArrayParameter()
Array Parameter Destructor.
void Set(const ContainerType &vals, bool updateMonitors=true)
Set the value of the parameter to the specified value.
Definition parameter.hh:862
ArrayParameter(std::weak_ptr< Task > task, const std::string &name, unsigned nElements, unsigned strLen=100, const std::string initVal="")
Construct a parameter of a given name which is an array of scalar items.
void Set(size_t index, const std::string &val, bool updateMonitors=true)
Set the value of the parameter to the specified value.
void Fill(const std::string &filler, bool updateMonitors=true)
Fill the array parameter value with a fixed value for all elements.
virtual std::string operator[](size_t index) const
Return a single item from the Array parameter.
Definition parameter.hh:1023
virtual ~ArrayParameter()
Array Parameter Destructor.
Definition parameter.hh:709
void Set(const ContainerType &vals)
Set the value of the parameter to the specified value.
Definition parameter.hh:515
void Fill(const F filler, bool updateMonitors=true)
Fill the array parameter value with a fixed value for all elements.
Definition parameter.hh:467
SDS_T operator[](size_t index) const
Return a single item from the Array parameter.
Definition parameter.hh:730
SDS_T Get(size_t index) const
Return a single value from an array parameter.
Definition parameter.hh:656
ArrayParameter(std::weak_ptr< Task > task, const std::string &name, unsigned nElements, const SDS_T initVal)
Construct a parameter of a given name which is an array of scalar items.
Definition parameter.hh:434
void Set(size_t index, SDS_T val, bool updateMonitors=true)
Set the value of the parameter to the specified value.
Definition parameter.hh:605
The class ArrayParameter is used to implement DRAMA parameters containing arrays of primitive items (...
Definition parameter.hh:408
virtual ~Parameter()
Parameter Destructor.
Parameter< drama::sds::Id > class_type
The type of this template instantiation.
Definition parameter.hh:300
void UpdateMonitors() const
Trigger any monitors of this parameter.
void Set(const sds::IdPtr &newVal, bool copy=true, bool create=false)
Set the value of this parameter.
Parameter(std::weak_ptr< Task > task, const std::string &name, const sds::IdPtr &initVal, bool copy=true)
Construct a parameter of a given name.
sds::Id Get() const
Access the parameter.
class_type & operator=(SDS_T val)
Set the value of the parameter to the specified value.
Definition parameter.hh:148
bool operator==(T &&rhs) const
Overload the == operator.
Definition parameter.hh:211
virtual ~Parameter()
Parameter Destructor.
Definition parameter.hh:185
friend bool operator==(T &&lhs, const Parameter &p)
Overload the == operator.
Definition parameter.hh:198
Parameter< SDS_T > class_type
The type of this template instantiation.
Definition parameter.hh:120
bool operator!=(T &&rhs) const
Overload the != operator.
Definition parameter.hh:240
Parameter(std::weak_ptr< Task > task, const std::string &name, const SDS_T &initVal)
Construct a parameter of a given name.
Definition parameter.hh:130
friend bool operator!=(T &&lhs, const Parameter &p)
Overload the != operator.
Definition parameter.hh:226
The class Parameter is used to implement DRAMA parameters containing primitive items.
Definition parameter.hh:108
std::lock_guard< mutexType > guardType
Defines the type of a lock guard using our mutex type.
Definition task.hh:460
unsigned long Size() const
Return the number of elements in the array.
Definition sdsarray.hh:267
Helper class for reading data from SDS Scalar Arrays.
Definition sdsarray.hh:385
T * DataAddress()
Access the data directly.
Definition sdsarray.hh:350
Helper class for writing data to SDS Scalar Arrays.
Definition sdsarray.hh:303
void ArrayAccess(ArrayAccessHelper< T > *const data) const
Access the data of a single dimensional SDS primitive array item of a specified number of elements.
Definition sds.hh:2506
virtual Id Find(const std::string &name, bool throwOnNotFound=true) const
Factory constructor method Constructor which returns a reference to a named item.
void GetDims(ContainerType *dims) const
Return the dimensions of the SDS item.
Definition sds.hh:1705
static Id CreateFromSdsIdType(const SdsIdType item, const bool free=false, const bool del=false, const bool readfree=false)
Factory constructor method that constructs an sds::Id item from an existing C language SDS id.
Id CreateChildArray(const std::string &name, const SdsCodeType code, const ContainerType &dims, const std::string &extra="") const
Factory constructor method Constructor which creates a new child item which is an multi-dimensional a...
Definition sds.hh:940
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:114
std::ostream & operator<<(std::ostream &strm, const drama::Exception &e)
drama::Exception stream output operator
Definition exception.hh:617
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:93
std::shared_ptr< Id > IdPtr
A shared pointer for sds::Id items.
Definition sds.hh:3318
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
DRAMA 2 include file - Sds class definition.
DRAMA 2 include file - Task class definition.