This is Unofficial EPICS BASE Doxygen Site
ntcontinuum.cpp
Go to the documentation of this file.
1 /* ntcontinuum.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  */
6 
7 #include "validator.h"
8 
9 #define epicsExportSharedSymbols
10 #include <pv/ntcontinuum.h>
11 #include <pv/ntutils.h>
12 
13 using namespace std;
14 using namespace epics::pvData;
15 
16 namespace epics { namespace nt {
17 
18 static NTFieldPtr ntField = NTField::get();
19 
20 namespace detail {
21 
22 StructureConstPtr NTContinuumBuilder::createStructure()
23 {
24  FieldBuilderPtr builder =
25  getFieldCreate()->createFieldBuilder()->
26  setId(NTContinuum::URI)->
27  addArray("base", pvDouble)->
28  addArray("value", pvDouble)->
29  addArray("units", pvString);
30 
31  if (descriptor)
32  builder->add("descriptor", pvString);
33 
34  if (alarm)
35  builder->add("alarm", ntField->createAlarm());
36 
37  if (timeStamp)
38  builder->add("timeStamp", ntField->createTimeStamp());
39 
40  size_t extraCount = extraFieldNames.size();
41  for (size_t i = 0; i< extraCount; i++)
42  builder->add(extraFieldNames[i], extraFields[i]);
43 
44 
45  StructureConstPtr s = builder->createStructure();
46 
47  reset();
48  return s;
49 }
50 
51 NTContinuumBuilder::shared_pointer NTContinuumBuilder::addDescriptor()
52 {
53  descriptor = true;
54  return shared_from_this();
55 }
56 
57 NTContinuumBuilder::shared_pointer NTContinuumBuilder::addAlarm()
58 {
59  alarm = true;
60  return shared_from_this();
61 }
62 
63 NTContinuumBuilder::shared_pointer NTContinuumBuilder::addTimeStamp()
64 {
65  timeStamp = true;
66  return shared_from_this();
67 }
68 
69 
70 PVStructurePtr NTContinuumBuilder::createPVStructure()
71 {
72  return getPVDataCreate()->createPVStructure(createStructure());
73 }
74 
75 NTContinuumPtr NTContinuumBuilder::create()
76 {
77  return NTContinuumPtr(new NTContinuum(createPVStructure()));
78 }
79 
80 NTContinuumBuilder::NTContinuumBuilder()
81 {
82  reset();
83 }
84 
85 void NTContinuumBuilder::reset()
86 {
87  descriptor = false;
88  alarm = false;
89  timeStamp = false;
90  extraFieldNames.clear();
91  extraFields.clear();
92 }
93 
94 NTContinuumBuilder::shared_pointer NTContinuumBuilder::add(string const & name, FieldConstPtr const & field)
95 {
96  extraFields.push_back(field); extraFieldNames.push_back(name);
97  return shared_from_this();
98 }
99 
100 }
101 
102 const std::string NTContinuum::URI("epics:nt/NTContinuum:1.0");
103 
104 NTContinuum::shared_pointer NTContinuum::wrap(PVStructurePtr const & pvStructure)
105 {
106  if(!isCompatible(pvStructure)) return shared_pointer();
107  return wrapUnsafe(pvStructure);
108 }
109 
110 NTContinuum::shared_pointer NTContinuum::wrapUnsafe(PVStructurePtr const & pvStructure)
111 {
112  return shared_pointer(new NTContinuum(pvStructure));
113 }
114 
115 bool NTContinuum::is_a(StructureConstPtr const & structure)
116 {
117  return NTUtils::is_a(structure->getID(), URI);
118 }
119 
120 bool NTContinuum::is_a(PVStructurePtr const & pvStructure)
121 {
122  return is_a(pvStructure->getStructure());
123 }
124 
125 bool NTContinuum::isCompatible(StructureConstPtr const & structure)
126 {
127  if (!structure)
128  return false;
129 
130  Result result(structure);
131 
132  return result
133  .is<Structure>()
134  .has<ScalarArray>("base")
135  .has<ScalarArray>("value")
136  .has<ScalarArray>("units")
137  .maybeHas<Scalar>("descriptor")
138  .maybeHas<&NTField::isAlarm, Structure>("alarm")
139  .maybeHas<&NTField::isTimeStamp, Structure>("timeStamp")
140  .valid();
141 }
142 
143 bool NTContinuum::isCompatible(PVStructurePtr const & pvStructure)
144 {
145  if(!pvStructure) return false;
146 
147  return isCompatible(pvStructure->getStructure());
148 }
149 
150 bool NTContinuum::isValid()
151 {
152  return ((getUnits()->getLength()-1)*getBase()->getLength() ==
153  getValue()->getLength());
154 }
155 
156 NTContinuumBuilderPtr NTContinuum::createBuilder()
157 {
159 }
160 
161 bool NTContinuum::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
162 {
163  PVStructurePtr ts = getTimeStamp();
164  if (ts)
165  return pvTimeStamp.attach(ts);
166  else
167  return false;
168 }
169 
170 bool NTContinuum::attachAlarm(PVAlarm &pvAlarm) const
171 {
172  PVStructurePtr al = getAlarm();
173  if (al)
174  return pvAlarm.attach(al);
175  else
176  return false;
177 }
178 
179 PVStructurePtr NTContinuum::getPVStructure() const
180 {
181  return pvNTContinuum;
182 }
183 
184 PVStringPtr NTContinuum::getDescriptor() const
185 {
186  return pvNTContinuum->getSubField<PVString>("descriptor");
187 }
188 
189 PVStructurePtr NTContinuum::getTimeStamp() const
190 {
191  return pvNTContinuum->getSubField<PVStructure>("timeStamp");
192 }
193 
194 PVStructurePtr NTContinuum::getAlarm() const
195 {
196  return pvNTContinuum->getSubField<PVStructure>("alarm");
197 }
198 
199 PVDoubleArrayPtr NTContinuum::getBase() const
200 {
201  return pvNTContinuum->getSubField<PVDoubleArray>("base");
202 }
203 
204 PVDoubleArrayPtr NTContinuum::getValue() const
205 {
206  return pvValue;
207 }
208 
209 PVStringArrayPtr NTContinuum::getUnits() const
210 {
211  return pvNTContinuum->getSubField<PVStringArray>("units");
212 }
213 
214 NTContinuum::NTContinuum(PVStructurePtr const & pvStructure) :
215  pvNTContinuum(pvStructure),
216  pvValue(pvNTContinuum->getSubField<PVDoubleArray>("value"))
217 {}
218 
219 
220 }}
FORCE_INLINE std::tr1::shared_ptr< PVField > getSubField(A a)
Definition: pvData.h:744
This class implements introspection object for Scalar.
Definition: pvIntrospect.h:397
pvac::PutEvent result
Definition: clientSync.cpp:117
std::tr1::shared_ptr< detail::NTContinuumBuilder > NTContinuumBuilderPtr
Definition: ntcontinuum.h:109
Convenience Class for NTContinuum.
Definition: ntcontinuum.h:118
Result & is(void)
Definition: validator.h:89
Interface for in-line creating of NTContinuum.
Definition: ntcontinuum.h:38
int i
Definition: scan.c:967
bool attach(PVFieldPtr const &pvField)
Definition: pvAlarm.cpp:26
Validation methods for NT types.
Definition: validator.h:23
Definition: memory.hpp:41
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:162
std::tr1::shared_ptr< NTContinuum > NTContinuumPtr
Definition: ntcontinuum.h:26
std::tr1::shared_ptr< NTField > NTFieldPtr
Definition: ntfield.h:35
std::tr1::shared_ptr< PVStringArray > PVStringArrayPtr
Definition: pvData.h:1464
std::tr1::shared_ptr< FieldBuilder > FieldBuilderPtr
PVString is special case, since it implements SerializableArray.
Definition: pvData.h:521
pvData
Definition: monitor.h:428
This class implements introspection object for a structure.
Definition: pvIntrospect.h:697
template class for all extensions of PVArray.
Definition: pvData.h:55
Methods for accessing a timeStamp structure.
Definition: pvTimeStamp.h:38
Methods for accessing an alarm structure.
Definition: pvAlarm.h:37
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< const Field > FieldConstPtr
Definition: pvIntrospect.h:137
FORCE_INLINE const FieldCreatePtr & getFieldCreate()
This class implements introspection object for scalar array.
Definition: pvIntrospect.h:497
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
std::tr1::shared_ptr< PVString > PVStringPtr
Definition: pvData.h:540
Definition: caget.c:48
std::tr1::shared_ptr< PVDoubleArray > PVDoubleArrayPtr
Definition: pvData.h:1461
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648
bool attach(PVFieldPtr const &pvField)
Definition: pvTimeStamp.cpp:26