This is Unofficial EPICS BASE Doxygen Site
epics::pvData::PVEnumerated Class Reference

Methods for accessing an enumerated structure. More...

#include "pvEnumerated.h"

Public Member Functions

 PVEnumerated ()
 
bool attach (PVFieldPtr const &pvField)
 
void detach ()
 
bool isAttached ()
 
bool setIndex (int32 index)
 
int32 getIndex ()
 
std::string getChoice ()
 
bool choicesMutable ()
 
PVStringArray::const_svector getChoices ()
 
int32 getNumberChoices ()
 
bool setChoices (const StringArray &choices)
 

Detailed Description

Methods for accessing an enumerated structure.

An enumerated structure has the following fields:

int index
string[] choices

This class can be attached to an enumerated structure field of any PVData object. The methods provide access to the fields in the attached structure. This class should not be extended.

Definition at line 34 of file pvEnumerated.h.

Constructor & Destructor Documentation

epics::pvData::PVEnumerated::PVEnumerated ( )
inline

Definition at line 39 of file pvEnumerated.h.

39 {}

Member Function Documentation

bool epics::pvData::PVEnumerated::attach ( PVFieldPtr const &  pvField)

Definition at line 26 of file pvEnumerated.cpp.

27 {
28  if(pvField->getField()->getType()!=structure) return false;
29  PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
30  pvIndex = pvStructure->getSubField<PVInt>("index");
31  if(pvIndex.get()==NULL) return false;
32  PVStringArrayPtr pvStringArray = pvStructure->getSubField<PVStringArray>("choices");
33  if(pvStringArray.get()==NULL) {
34  pvIndex.reset();
35  return false;
36  }
37  pvChoices = pvStringArray;
38  return true;
39 }
PVScalarValue< int32 > PVInt
Definition: pvData.h:496
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
#define NULL
Definition: catime.c:38
std::tr1::shared_ptr< PVStringArray > PVStringArrayPtr
Definition: pvData.h:1464
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
PVValueArray< std::string > PVStringArray
Definition: pvData.h:1463
bool epics::pvData::PVEnumerated::choicesMutable ( )

Can choices be changed?

Returns
(false,true) if choices (can not, can) be changed.
Exceptions
ifnot attached.

Definition at line 84 of file pvEnumerated.cpp.

85 {
86  if(pvIndex.get()==NULL ) {
87  throw std::logic_error(notAttached);
88  }
89  return pvChoices->isImmutable();
90 }
#define NULL
Definition: catime.c:38
void epics::pvData::PVEnumerated::detach ( )

Detach for pvField.

Definition at line 41 of file pvEnumerated.cpp.

42 {
43  pvIndex.reset();
44  pvChoices.reset();
45 }
string epics::pvData::PVEnumerated::getChoice ( )

Get the choice corresponding to current index.

Returns
The choice. If index is out of range a null string is returned.
Exceptions
ifnot attached.

Definition at line 70 of file pvEnumerated.cpp.

71 {
72  if(pvIndex.get()==NULL ) {
73  throw std::logic_error(notAttached);
74  }
75  size_t index = pvIndex->get();
76  const PVStringArray::const_svector& data(pvChoices->view());
77  if(/*index<0 ||*/ index>=data.size()) {
78  string nullString;
79  return nullString;
80  }
81  return data[index];
82 }
#define NULL
Definition: catime.c:38
::epics::pvData::shared_vector< const T > const_svector
Definition: pvData.h:1185
PVStringArray::const_svector epics::pvData::PVEnumerated::getChoices ( )
inline

Get the choices.

Returns
The current index.
Exceptions
ifnot attached.

Definition at line 91 of file pvEnumerated.h.

91 {return pvChoices->view();}
int32 epics::pvData::PVEnumerated::getIndex ( )

Get the index.

Returns
The current index.
Exceptions
ifnot attached.

Definition at line 62 of file pvEnumerated.cpp.

63 {
64  if(pvIndex.get()==NULL ) {
65  throw std::logic_error(notAttached);
66  }
67  return pvIndex->get();
68 }
#define NULL
Definition: catime.c:38
int32 epics::pvData::PVEnumerated::getNumberChoices ( )

Get the size of the choices array.

Returns
The size.
Exceptions
ifnot attached.

Definition at line 92 of file pvEnumerated.cpp.

93 {
94  if(pvIndex.get()==NULL ) {
95  throw std::logic_error(notAttached);
96  }
97  return static_cast<int32>(pvChoices->getLength());
98 }
#define NULL
Definition: catime.c:38
int32_t int32
Definition: pvType.h:83
bool epics::pvData::PVEnumerated::isAttached ( )

Is the PVEnumerated attached to a pvField?

Returns
(false,true) (is not,is) attached to a pvField.

Definition at line 47 of file pvEnumerated.cpp.

47  {
48  if(pvIndex.get()==NULL) return false;
49  return true;
50 }
#define NULL
Definition: catime.c:38
bool epics::pvData::PVEnumerated::setChoices ( const StringArray choices)

Get the choices.

Parameters
choicesThe new value for choices.`
Returns
(false,true) if choices (was not was) replaced.
Exceptions
ifnot attached.

Definition at line 100 of file pvEnumerated.cpp.

101 {
102  if(pvIndex.get()==NULL ) {
103  throw std::logic_error(notAttached);
104  }
105  if(pvChoices->isImmutable()) return false;
106  PVStringArray::svector data(choices.size());
107  std::copy(choices.begin(), choices.end(), data.begin());
108  pvChoices->replace(freeze(data));
109  return true;
110 }
::epics::pvData::shared_vector< T > svector
Definition: pvData.h:1184
#define NULL
Definition: catime.c:38
void copy(PVValueArray< T > &pvFrom, size_t fromOffset, size_t fromStride, PVValueArray< T > &pvTo, size_t toOffset, size_t toStride, size_t count)
Copy a subarray from one scalar array to another.
bool epics::pvData::PVEnumerated::setIndex ( int32  index)

Set the index.

Parameters
indexThe new index.
Exceptions
ifnot attached. The index will be changed even if it is out of range of size of choices.

Definition at line 52 of file pvEnumerated.cpp.

53 {
54  if(pvIndex.get()==NULL ) {
55  throw std::logic_error(notAttached);
56  }
57  if(pvIndex->isImmutable()) return false;
58  pvIndex->put(index);
59  return true;
60 }
#define NULL
Definition: catime.c:38

The documentation for this class was generated from the following files: