1#ifndef _DRAMA2_PARAMETER_INC
2#define _DRAMA2_PARAMETER_INC
37#include "DitsMonitor.h"
80 template<
typename SDS_T>
class Parameter {
87 std::weak_ptr<Task> _theTask;
88 const std::string _name;
103 const std::string &name,
140 operator SDS_T()
const {
185 return (this->
operator SDS_T() ==
rhs);
214 return (this->
operator SDS_T() !=
rhs);
234 template <
typename SDS_T>
282 std::weak_ptr<Task> _theTask;
283 const std::string _name;
301 const std::string &name,
351 void UpdateMonitors()
const;
401 std::weak_ptr<Task> _theTask;
402 const std::string _name;
421 const std::string &name,
452 template <
typename F>
455 auto id = _parSys.
Find(_name);
459 id.ArrayAccess(&array);
462 for (
unsigned i = 0 ;
i <
count ; ++
i)
480 "Error filling array parameter {0}, DitsMonitor() failed",
500 template <
class ContainerType>
505 auto id = _parSys.
Find(_name);
508 sds::ArrayWriteHelper<SDS_T> array;
509 id.ArrayAccess(&array);
523 for (
unsigned i = 0 ;
i <
count ; ++
i)
539 "Error setting array parameter {0}, DitsMonitor() failed",
550 std::vector<SDS_T> Get()
const {
554 auto id = _parSys.
Find(_name);
557 sds::ArrayReadHelper<SDS_T> array;
560 auto count = array.Size();
561 std::vector<SDS_T>
result;
566 for (
unsigned i = 0;
i <
count ; ++
i)
595 auto id = _parSys.
Find(_name);
598 sds::ArrayWriteHelper<SDS_T> array;
601 if (index >= array.Size())
604 "Tired to set index {0} in array parameter is size {1}",
605 index, array.Size());
626 "Error setting array parameter {0}, DitsMonitor() failed",
642 SDS_T Get(
size_t index)
const {
646 auto id = _parSys.
Find(_name);
649 sds::ArrayReadHelper<SDS_T> array;
652 if (index >= array.Size())
655 "Tired to set index {0} in array parameter is size {1}",
656 index, array.Size());
672 unsigned Size()
const {
675 auto id = _parSys.
Find(_name);
677 std::vector<unsigned>
dims;
680 if (
dims.size() != 1)
683 "Dimensions of array parameter is NOT 1. Can only use drama::ArrayParameter for single dimension array parameters");
757 template<>
class ArrayParameter<std::string> {
764 std::weak_ptr<Task> _theTask;
765 const std::string _name;
785 const std::string &name,
841 typename std::enable_if<std::is_base_of<std::string,
842 typename ContainerType::value_type>
::value>::type* =
nullptr>
847 auto id = _parSys.Find(_name);
850 std::vector<unsigned long>
dims;
852 id.ArrayAccess(&array, 2, &
dims);
857 if (
dims.size() != 2)
860 "Dimensions of string array parameter is NOT 2. Can only use drama::ArrayParameter<std::string> for two dimension array parameters");
891 for (
unsigned i = 0 ;
i <
nVals ; ++
i)
912 "Error setting array parameter {0}, DitsMonitor() failed",
924 std::vector<std::string> Get()
const;
954 std::string Get(
size_t index)
const;
968 virtual unsigned Size()
const;
981 virtual unsigned Strlen()
const;
1005 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:871
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:1032
virtual ~ArrayParameter()
Array Parameter Destructor.
Definition parameter.hh:722
void Set(const ContainerType &vals)
Set the value of the parameter to the specified value.
Definition parameter.hh:528
void Fill(const F filler, bool updateMonitors=true)
Fill the array parameter value with a fixed value for all elements.
Definition parameter.hh:480
SDS_T operator[](size_t index) const
Return a single item from the Array parameter.
Definition parameter.hh:739
SDS_T Get(size_t index) const
Return a single value from an array parameter.
Definition parameter.hh:669
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:447
void Set(size_t index, SDS_T val, bool updateMonitors=true)
Set the value of the parameter to the specified value.
Definition parameter.hh:618
The class ArrayParameter is used to implement DRAMA parameters containing arrays of primitive items (...
Definition parameter.hh:421
virtual ~Parameter()
Parameter Destructor.
Parameter< drama::sds::Id > class_type
The type of this template instantiation.
Definition parameter.hh:315
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:147
bool operator==(T &&rhs) const
Overload the == operator.
Definition parameter.hh:210
virtual ~Parameter()
Parameter Destructor.
Definition parameter.hh:184
friend bool operator==(T &&lhs, const Parameter &p)
Overload the == operator.
Definition parameter.hh:197
Parameter< SDS_T > class_type
The type of this template instantiation.
Definition parameter.hh:119
bool operator!=(T &&rhs) const
Overload the != operator.
Definition parameter.hh:239
Parameter(std::weak_ptr< Task > task, const std::string &name, const SDS_T &initVal)
Construct a parameter of a given name.
Definition parameter.hh:129
friend bool operator!=(T &&lhs, const Parameter &p)
Overload the != operator.
Definition parameter.hh:225
The class Parameter is used to implement DRAMA parameters.
Definition parameter.hh:107
std::lock_guard< mutexType > guardType
Defines the type of a lock guard using our mutex type.
Definition task.hh:471
unsigned long Size() const
Return the number of elements in the array.
Definition sdsarray.hh:269
Helper class for reading data from SDS Scalar Arrays.
Definition sdsarray.hh:387
T * DataAddress()
Access the data directly.
Definition sdsarray.hh:352
Helper class for writing data to SDS Scalar Arrays.
Definition sdsarray.hh:305
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:2673
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:1846
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:953
A C++ Interface to the handling SDS structures.
Definition sds.hh:428
#define DramaTHROW_F(status_, format_,...)
Throw a Drama exception with fmt::format string formatting.
Definition exception.hh:129
std::ostream & operator<<(std::ostream &strm, const drama::Exception &e)
drama::Exception stream output operator
Definition exception.hh:726
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:90
std::shared_ptr< Id > IdPtr
A shared pointer for sds::Id items.
Definition sds.hh:3613
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1339
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:99
DRAMA 2 include file - Sds class definition.
DRAMA 2 include file - Task class definition.