This is Unofficial EPICS BASE Doxygen Site
pvDisplay.cpp
Go to the documentation of this file.
1 /* pvDisplay.cpp */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #include <string>
10 #include <stdexcept>
11 
12 #define epicsExportSharedSymbols
13 #include <pv/pvType.h>
14 #include <pv/pvIntrospect.h>
15 #include <pv/pvData.h>
16 #include <pv/pvDisplay.h>
17 
19 using std::string;
20 
21 namespace epics { namespace pvData {
22 
23 string PVDisplay::noDisplayFound("No display structure found");
24 string PVDisplay::notAttached("Not attached to an display structure");
25 
26 bool PVDisplay::attach(PVFieldPtr const & pvField)
27 {
28  if(pvField->getField()->getType()!=structure) return false;
29  PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
30  pvDescription = pvStructure->getSubField<PVString>("description");
31  if(pvDescription.get()==NULL) return false;
32  pvFormat = pvStructure->getSubField<PVString>("format");
33  if(pvFormat.get()==NULL) {
34  detach();
35  return false;
36  }
37  pvUnits = pvStructure->getSubField<PVString>("units");
38  if(pvUnits.get()==NULL) {
39  detach();
40  return false;
41  }
42  pvLow = pvStructure->getSubField<PVDouble>(string("limitLow"));
43  if(pvLow.get()==NULL) {
44  detach();
45  return false;
46  }
47  pvHigh = pvStructure->getSubField<PVDouble>(string("limitHigh"));
48  if(pvHigh.get()==NULL) {
49  detach();
50  return false;
51  }
52  return true;
53 }
54 
56 {
57  pvDescription.reset();
58  pvFormat.reset();
59  pvUnits.reset();
60  pvLow.reset();
61  pvHigh.reset();
62 }
63 
65  if(pvDescription.get()) return false;
66  return true;
67 }
68 
69 void PVDisplay::get(Display & display) const
70 {
71  if(pvDescription.get()==NULL) {
72  throw std::logic_error(notAttached);
73  }
74  display.setDescription(pvDescription->get());
75  display.setFormat(pvFormat->get());
76  display.setUnits(pvUnits->get());
77  display.setLow(pvLow->get());
78  display.setHigh(pvHigh->get());
79 }
80 
81 bool PVDisplay::set(Display const & display)
82 {
83  if(pvDescription.get()==NULL) {
84  throw std::logic_error(notAttached);
85  }
86  if(pvDescription->isImmutable() || pvFormat->isImmutable()) return false;
87  if(pvUnits->isImmutable() || pvLow->isImmutable() || pvHigh->isImmutable())
88  {
89  return false;
90  }
91  Display current;
92  get(current);
93  bool returnValue = false;
94  if(current.getDescription()!=display.getDescription())
95  {
96  pvDescription->put(display.getDescription());
97  returnValue = true;
98  }
99  if(current.getFormat()!=display.getFormat())
100  {
101  pvFormat->put(display.getFormat());
102  returnValue = true;
103  }
104  if(current.getUnits()!=display.getUnits())
105  {
106  pvUnits->put(display.getUnits());
107  returnValue = true;
108  }
109  if(current.getLow()!=display.getLow())
110  {
111  pvLow->put(display.getLow());
112  returnValue = true;
113  }
114  if(current.getHigh()!=display.getHigh())
115  {
116  pvHigh->put(display.getHigh());
117  returnValue = true;
118  }
119  return returnValue;
120 }
121 
122 }}
void setHigh(double value)
Definition: display.h:67
bool attach(PVFieldPtr const &pvField)
Definition: pvDisplay.cpp:26
bool set(Display const &display)
Definition: pvDisplay.cpp:81
double getLow() const
Definition: display.h:52
Methods for a display structure.
Definition: display.h:39
void setDescription(std::string const &value)
Definition: display.h:77
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
void get(Display &display) const
Definition: pvDisplay.cpp:69
std::string getDescription() const
Definition: display.h:72
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
#define NULL
Definition: catime.c:38
void setLow(double value)
Definition: display.h:62
void setFormat(std::string const &value)
Definition: display.h:88
PVString is special case, since it implements SerializableArray.
Definition: pvData.h:521
std::string getUnits() const
Definition: display.h:93
Data interface for a structure,.
Definition: pvData.h:712
double getHigh() const
Definition: display.h:57
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
Class that holds the data for each possible scalar type.
Definition: pvData.h:54
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
void setUnits(std::string const &value)
Definition: display.h:98
std::string getFormat() const
Definition: display.h:82