AAO DRAMA/DRAMA2 C++ Interface
parsys.hh
Go to the documentation of this file.
1 #ifndef _DRAMA2_PARSYS_INC
2 #define _DRAMA2_PARSYS_INC
3 
23 /*
24  * History:
25  14-Jul-2014 - TJF - Original version, based on Sdp.h
26 
27  * The above ID is for Doxygen, this one has the format ACMM is looking for.
28  * "@(#) $Id: ACMM:Drama2/drama/parsys.hh,v 1.45+ 22-Feb-2016 14:09:57+11 tjf $"
29  */
30 
31 #include "drama/task.hh"
32 #include "drama/sds.hh"
33 #include <string>
34 #include "Sdp.h"
35 #include "DitsParam.h"
36 
37 
38 
39 namespace drama {
49  class ParSys {
50  private:
51  /*
52  * Pointer to the DRAMA task this parameter system is part of.
53  */
54  std::weak_ptr<Task> _theTask;
55 
56  public:
64  ParSys(std::weak_ptr<Task> dramaTask) : _theTask(dramaTask) {}
65 
81  void CreateItem(sds::Id &item) {
82 
83  // Lock access to DRAMA.
84  Task::guardType DramaLock(std::shared_ptr<Task>(_theTask)->Lock());
85 
86  StatusType status = STATUS__OK;
87 
88  SdpCreateItem((SdsIdType)(DitsGetParId()),(SdsIdType)item,&status);
89  if (status != STATUS__OK)
90  DramaTHROW(status,
91  "Failed to create new structured parameter");
92 
93  /* Ensure item is not deleted by destructor (id can go) */
94  item.ClearDelete();
95  }
96 
97  private:
98  /*
99  * The SdpPut() template function is used by the Put() method
100  * of ParSys which is implementing traditional Sdp style Put.
101  *
102  * The idea is that we must instantiate a specific version of this
103  * for each primitive SDS type and for strings. This is done
104  * outside the class definition.
105  *
106  * The Put() method won't link unless there is a specific version for
107  * the type in question.
108  *
109  * DRAMA Lock will be taken when invoked.
110  */
111  template <typename T> static void SdpPut(
112  const std::string &name,
113  T value, StatusType *status);
114 
115 
116  /*
117  * The SdpGet() template function is used by the Get() method
118  * of ParSys and is implementing traditional Sdp style Get.
119  *
120  * The idea is that we must instantiate a specific version of this
121  * for each primitive SDS type and for strings. These are done
122  * outside the class definition at the bottom of this file.
123  *
124  * The Get() method won't link unless there is a specific version for
125  * the type in question.
126  *
127  * DRAMA Lock will be taken when invoked.
128  */
129  template <typename T> static void SdpGet(
130  const std::string &name,
131  T *value, StatusType *status);
132 
133 
134  public:
135 
154  template <typename T>
155  void Get (const std::string &name, T *value) {
156 
157  // Lock access to DRAMA.
158  Task::guardType DramaLock(std::shared_ptr<Task>(_theTask)->Lock());
159 
160  StatusType status = STATUS__OK;
161  /*
162  There must be a specialization of SdpGet() which
163  supports type T. Note that conversion of DRAMA status
164  to DRAMA 2 exceptions is done here so it need only be
165  done once.
166  */
167  SdpGet(name, value, &status);
168  if (status != STATUS__OK)
169  DramaTHROW_S(status,
170  "SdpGet of parameter % failed",
171  name);
172 
173  }
193  template <typename T>
194  void Put (const std::string &name, T value) {
195 
196  // Lock access to DRAMA.
197  Task::guardType DramaLock(std::shared_ptr<Task>(_theTask)->Lock());
198 
199  StatusType status = STATUS__OK;
200  /*
201  There must be a specialization of SdpPut() which
202  supports type T. Note that conversion of DRAMA status
203  to DRAMA 2 exceptions is done here so it need only be
204  done once.
205  */
206  SdpPut(name, value, &status);
207  if (status != STATUS__OK)
208  DramaTHROW_S(status,
209  "SdpPut of parameter % failed",
210  name);
211 
212  }
221  void Put (const std::string &name, const std::string &value) {
222 
223 
224  Task::guardType DramaLock(std::shared_ptr<Task>(_theTask)->Lock());
225 
226  StatusType status = STATUS__OK;
227  SdpPutString(name.c_str(), value.c_str(), &status);
228  if (status != STATUS__OK)
229  {
230  DramaTHROW_S(status,
231  "SdpPutString of parameter % failed",
232  name);
233  }
234  }
235 
241  int GetInt(const std::string &name);
248  unsigned int GetUInt(const std::string &name);
249 
255  long GetLong(const std::string &name);
262  unsigned long GetULong(const std::string &name);
268  double GetDouble(const std::string &name);
269 
276  std::string GetString(const std::string &name);
277 
278 
301  void PutSdsCvt(const std::string &name,
302  const sds::Id & value);
303 
325  void PutSdsReplaceByCopy(const std::string &name,
326  const sds::Id &value,
327  const bool create=true );
328 
351  void PutSdsReplaceByInsert(const std::string &name,
352  sds::Id *value,
353  const bool create=true );
354 
373  void Update(const std::string &name);
374 
375 
376  }; // class ParSys.
377 
378  /*
379  * The SdpPut() template function is used by the Put() method
380  * of ParSys.
381  *
382  * The idea is that we must instantiate a specific version of this
383  * for each primitive SDS item (and for strings).
384  *
385  * The Put method won't link unless there is a specific version for
386  * the type in question. These are all implemented in parsys.cpp.
387  */
388  template <> void ParSys::SdpPut<bool>(
389  const std::string &name,
390  bool value, StatusType *status);
391  template <> void ParSys::SdpPut<char>(
392  const std::string &name,
393  char value, StatusType *status);
394  template <> void ParSys::SdpPut<short>(
395  const std::string &name,
396  short value, StatusType *status);
397  template <> void ParSys::SdpPut<unsigned short>(
398  const std::string &name,
399  unsigned short value, StatusType *status);
400  template <> void ParSys::SdpPut<INT32>(
401  const std::string &name,
402  INT32 value, StatusType *status);
403  template <> void ParSys::SdpPut<UINT32>(
404  const std::string &name,
405  UINT32 value, StatusType *status);
406  template <> void ParSys::SdpPut<INT64>(
407  const std::string &name,
408  INT64 value, StatusType *status);
409  template <> void ParSys::SdpPut<UINT64>(
410  const std::string &name,
411  UINT64 value, StatusType *status);
412  template <> void ParSys::SdpPut<float>(
413  const std::string &name,
414  float value, StatusType *status);
415  template <> void ParSys::SdpPut<double>(
416  const std::string &name,
417  double value, StatusType *status);
418 
419 
420  template <> void ParSys::SdpPut<const char *>(
421  const std::string &name,
422  const char *value, StatusType *status);
423 
424  template <> void ParSys::SdpPut<const std::string&>(
425  const std::string &name,
426  const std::string &value, StatusType *status);
427 
428  /*
429  * The SdpGet() template function is used by the Get() method
430  * of ParSys.
431  *
432  * The idea is that we must instantiate a specific version of this
433  * for each primitive SDS item (and for strings).
434  *
435  * The Get method won't link unless there is a specific version for
436  * the type in question. These are all implemented in parsys.cpp.
437  *
438  * Note - we have a Get() of an SDS type, but not a Put, there are
439  * specific PutSds... methods in ParSys for different cases.
440  */
441 
442 
443  template <> void ParSys::SdpGet<bool>(
444  const std::string &name,
445  bool *value, StatusType *status);
446  template <> void ParSys::SdpGet<char>(
447  const std::string &name,
448  char *value, StatusType *status);
449  template <> void ParSys::SdpGet<short>(
450  const std::string &name,
451  short *value, StatusType *status);
452  template <> void ParSys::SdpGet<unsigned short>(
453  const std::string &name,
454  unsigned short *value, StatusType *status);
455  template <> void ParSys::SdpGet<INT32>(
456  const std::string &name,
457  INT32 *value, StatusType *status);
458  template <> void ParSys::SdpGet<UINT32>(
459  const std::string &name,
460  UINT32 *value, StatusType *status);
461  template <> void ParSys::SdpGet<INT64>(
462  const std::string &name,
463  INT64 *value, StatusType *status);
464  template <> void ParSys::SdpGet<UINT64>(
465  const std::string &name,
466  UINT64 *value, StatusType *status);
467  template <> void ParSys::SdpGet<float>(
468  const std::string &name,
469  float *value, StatusType *status);
470  template <> void ParSys::SdpGet<double>(
471  const std::string &name,
472  double *value, StatusType *status);
473  template <> void ParSys::SdpGet<std::string>(
474  const std::string &name,
475  std::string *value, StatusType *status);
476 #if 0
477  template <> void ParSys::SdpGet<sds::Id>(
478  const std::string &name,
479  sds::Id *parId, StatusType *status);
480 #endif
481 
482 
493  class ParId : public sds::Id {
494  private:
495  /*
496  * Pointer to the DRAMA task this parameter system is part of.
497  */
498  std::weak_ptr<Task> _theTask;
499  ParSys _parSys;
500 
501  void InvalidCall(const std::string &fromWhere);
502 
503  /*
504  * Various SDS methods are not allowed, make them private and
505  * (incase they are invoked in the class itself) replace them
506  * such that they throw an exception.
507  *
508  * We can't just delete these - Under the C++11 standard, a deleted
509  * virtual function may not override a non-deleted virtual function
510  *
511  * We don't need to change the free flag - it is set correctly.
512  */
513  void SetFree() override final {
514  InvalidCall("SetFree()");
515  }
516 
517  // Don't allow delete to be set - that would remove the parameter.
518  void SetDelete() override final {
519  InvalidCall("SetDelete()");
520  }
521 
522  // Not needed, delete will never be set.
523  void ClearDelete() override final {
524  InvalidCall("ClearDelete()");
525  }
526 
527  // Not needed - outlives anyway.
528  void Outlive() override final {
529  InvalidCall("Outlive()");
530  }
531  // Can't delete- that will kill the parameter, mess up monitors.
532  void Delete() override final {
533  InvalidCall("Delete()");
534  }
535  //Would remove the parameter from the parameter system,mess up monitors
536  void Extract() override final {
537  InvalidCall("Extract()");
538  }
539  // Potential to mess up parameter monitors.
540  void Rename(const std::string &) override final {
541  InvalidCall("Rename()");
542  }
543  // Lots of potential to mess things up.
544  SdsIdType COut(const bool /*outlives*/,
545  bool * const /*free*/ = 0,
546  bool * const /*del*/= 0,
547  bool * const /*readfree*/ = 0) override final {
548 
549  InvalidCall("COut()");
550  return 0;
551  }
552  // This replaces the current item - messing up the parameter.
553  void ShallowCopy (Id * /*source*/,
554  const bool /*outlives*/=true) override final {
555  InvalidCall("ShallowCopy()");
556  }
557  // This replaces the current item - messing up the parameter.
558  void ShallowCopy (const Id & /*source*/) override final {
559  InvalidCall("ShallowCopy()");
560  }
561  void ShallowCopy (const SdsIdType /*source*/,
562  const bool /*free*/=false,
563  const bool /*del*/ = false,
564  const bool /*readfree*/ = false) override final {
565  InvalidCall("ShallowCopy()");
566  }
567 
568  public:
577  ParId(std::weak_ptr<Task> dramaTask, const std::string& name);
578 
584  void Update() const;
587  virtual ~ParId();
588  }; // class ParId
589 
590 } // namespace drama
591 
592 #endif /* defined _DRAMA2_SDP_INC */
long GetLong(const std::string &name)
If the Parameter contains scalar value, convert it to long integer.
DRAMA 2 include file - Task class definition.
#define DramaTHROW_S(status_, format_,...)
Throw a Drama exception with safe string formatting.
Definition: exception.hh:112
void Get(const std::string &name, T *value)
Fetch primitive value from parameter.
Definition: parsys.hh:182
void PutSdsCvt(const std::string &name, const sds::Id &value)
Put an SDS item a named parameter.
int GetInt(const std::string &name)
If the Parameter contains scalar value, convert it to integer.
DRAMA 2 include file - Sds class definition.
void CreateItem(sds::Id &item)
Create a new parameter by inserting an SDS item.
Definition: parsys.hh:108
void PutSdsReplaceByInsert(const std::string &name, sds::Id *value, const bool create=true)
Put a SDS item a named parameter - replacing the existing value.
std::lock_guard< mutexType > guardType
Defines the type of a lock guard using our mutex type.
Definition: task.hh:322
A C++ Interface to the handling SDS structures.
Definition: sds.hh:412
unsigned int GetUInt(const std::string &name)
If the Parameter contains scalar value, convert it to an unsigned integer.
void Update() const
Indicate to DRAMA that the parameter has been updated.
A class used to access a DRAMA Parameter via an SDS Id.
Definition: parsys.hh:520
virtual ~ParId()
Destroy this object.
std::string GetString(const std::string &name)
If the Parameter contains scalar value or a character string convert it to a string.
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition: exception.hh:82
A DRAMA 2 C++ Interface to the DRAMA Simple DITS Parameter System (SDP).
Definition: parsys.hh:76
ParSys(std::weak_ptr< Task > dramaTask)
Create an object to access the parameter system.
Definition: parsys.hh:91
unsigned long GetULong(const std::string &name)
If the Parameter contains scalar value, convert it to an unsigned long integer.
Id()
Default constructor.
Definition: sds.hh:589
ParId(std::weak_ptr< Task > dramaTask, const std::string &name)
Access a parameter of a given name.
void Put(const std::string &name, T value)
Update parameter from primitive value.
Definition: parsys.hh:221
void Update(const std::string &name)
Indicate a parameter value has been updated by other means.
double GetDouble(const std::string &name)
If the Parameter contains scalar value, convert it to a double.
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition: drama.hh:89
void PutSdsReplaceByCopy(const std::string &name, const sds::Id &value, const bool create=true)
Put a SDS item a named parameter - replacing the existing item.

Click here for the DRAMA home page and here for the AAO home page.

For more information, contact tjf@aao.gov.au 

Generated on Mon Feb 22 2016 15:57:52 for AAO DRAMA/DRAMA2 C++ Interface by doxygen 1.8.10