This is Unofficial EPICS BASE Doxygen Site
epics::pvCopy::PVArrayFilter Class Reference

A filter that gets a sub array from a PVScalarArray. More...

#include "pvArrayPlugin.h"

+ Inheritance diagram for epics::pvCopy::PVArrayFilter:
+ Collaboration diagram for epics::pvCopy::PVArrayFilter:

Public Member Functions

 POINTER_DEFINITIONS (PVArrayFilter)
 
virtual ~PVArrayFilter ()
 
bool filter (const epics::pvData::PVFieldPtr &pvCopy, const epics::pvData::BitSetPtr &bitSet, bool toCopy)
 
std::string getName ()
 
- Public Member Functions inherited from epics::pvCopy::PVFilter
 POINTER_DEFINITIONS (PVFilter)
 
virtual ~PVFilter ()
 

Static Public Member Functions

static PVArrayFilterPtr create (const std::string &requestValue, const epics::pvData::PVFieldPtr &master)
 

Detailed Description

A filter that gets a sub array from a PVScalarArray.

Definition at line 60 of file pvArrayPlugin.h.

Constructor & Destructor Documentation

epics::pvCopy::PVArrayFilter::~PVArrayFilter ( )
virtual

Definition at line 53 of file pvArrayPlugin.cpp.

54 {
55 }

Member Function Documentation

PVArrayFilterPtr epics::pvCopy::PVArrayFilter::create ( const std::string &  requestValue,
const epics::pvData::PVFieldPtr master 
)
static

Create a PVArrayFilter.

Parameters
requestValueThe value part of a name=value request option.
masterThe field in the master PVStructure to which the PVFilter will be attached.
Returns
The PVFilter. A null is returned if master or requestValue is not appropriate for the plugin.

Definition at line 77 of file pvArrayPlugin.cpp.

80 {
81  bool masterIsUnion = false;
82  PVUnionPtr pvUnion;
83  Type type = masterField->getField()->getType();
84  if(type==epics::pvData::union_) {
85  pvUnion = std::tr1::static_pointer_cast<PVUnion>(masterField);
86  PVFieldPtr pvField = pvUnion->get();
87  if(pvField) {
88  masterIsUnion = true;
89  type = pvField->getField()->getType();
90  }
91  }
92  if(type!=scalarArray) {
94  return filter;
95  }
96  long start =0;
97  long increment =1;
98  long end = -1;
99  vector<string> values(split(requestValue));
100  long num = values.size();
101  bool ok = true;
102  string value;
103  if(num==1) {
104  value = values[0];
105  start = strtol(value.c_str(),0,10);
106  } else if(num==2) {
107  value = values[0];
108  start = strtol(value.c_str(),0,10);
109  value = values[1];
110  end = strtol(value.c_str(),0,10);
111  } else if(num==3) {
112  value = values[0];
113  start = strtol(value.c_str(),0,10);
114  value = values[1];
115  increment = strtol(value.c_str(),0,10);
116  value = values[2];
117  end = strtol(value.c_str(),0,10);
118  } else {
119  ok = false;
120  }
121  if(!ok) {
123  return filter;
124  }
125  PVScalarArrayPtr masterArray;
126  if(masterIsUnion) {
127  masterArray = static_pointer_cast<PVScalarArray>(pvUnion->get());
128  } else {
129  masterArray = static_pointer_cast<PVScalarArray>(masterField);
130  }
133  new PVArrayFilter(start,increment,end,masterField,masterArray));
134  return filter;
135 }
Definition: link.h:174
const PVFieldPtr & get()
Definition: pvData.h:968
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
pvd::StructureConstPtr type
std::tr1::shared_ptr< PVArrayFilter > PVArrayFilterPtr
Definition: pvArrayPlugin.h:23
std::tr1::shared_ptr< PVUnion > PVUnionPtr
Definition: pvData.h:107
Base class for a scalarArray.
Definition: pvData.h:618
PVUnion has a single subfield.
Definition: pvData.h:940
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
bool filter(const epics::pvData::PVFieldPtr &pvCopy, const epics::pvData::BitSetPtr &bitSet, bool toCopy)
std::tr1::shared_ptr< PVScalarArray > PVScalarArrayPtr
Definition: pvData.h:82
bool epics::pvCopy::PVArrayFilter::filter ( const epics::pvData::PVFieldPtr pvCopy,
const epics::pvData::BitSetPtr bitSet,
bool  toCopy 
)
virtual

Perform a filter operation

Parameters
pvCopyThe field in the copy PVStructure.
bitSetA bitSet for copyPVStructure.
toCopy(true,false) means copy (from master to copy,from copy to master)
Returns
if filter (modified, did not modify) destination. Null is returned if master or requestValue is not appropriate for the plugin.

Implements epics::pvCopy::PVFilter.

Definition at line 150 of file pvArrayPlugin.cpp.

151 {
152  PVFieldPtr pvCopy = pvField;
153  PVScalarArrayPtr copyArray;
154  bool isUnion = false;
155  Type type = masterField->getField()->getType();
156  if(type==epics::pvData::union_) {
157  isUnion = true;
158  PVUnionPtr pvMasterUnion = std::tr1::static_pointer_cast<PVUnion>(masterField);
159  PVUnionPtr pvCopyUnion = std::tr1::static_pointer_cast<PVUnion>(pvCopy);
160  if(toCopy) pvCopyUnion->copy(*pvMasterUnion);
161  PVFieldPtr pvField = pvCopyUnion->get();
162  copyArray = static_pointer_cast<PVScalarArray>(pvField);
163  } else {
164  copyArray = static_pointer_cast<PVScalarArray>(pvCopy);
165  }
166  long len = 0;
167  long start = this->start;
168  long end = this->end;
169  long no_elements = masterArray->getLength();
170  if(start<0) {
171  start = no_elements+start;
172  if(start<0) start = 0;
173  }
174  if (end < 0) {
175  end = no_elements + end;
176  if (end < 0) end = 0;
177 
178  }
179  if(toCopy) {
180  if (end >= no_elements) end = no_elements - 1;
181  if (end - start >= 0) len = 1 + (end - start) / increment;
182  if(len<=0 || start>=no_elements) {
183  copyArray->setLength(0);
184  return true;
185  }
186  long indfrom = start;
187  long indto = 0;
188  copyArray->setCapacity(len);
189  if(increment==1) {
190  copy(*masterArray,indfrom,1,*copyArray,indto,1,len);
191  } else {
192  for(long i=0; i<len; ++i) {
193  copy(*masterArray,indfrom,1,*copyArray,indto,1,1);
194  indfrom += increment;
195  indto += 1;
196  }
197  }
198  copyArray->setLength(len);
199  bitSet->set(pvField->getFieldOffset());
200  return true;
201  }
202  if (end - start >= 0) len = 1 + (end - start) / increment;
203  if(len<=0) return true;
204  if(no_elements<=end) masterArray->setLength(end+1);
205  long indfrom = 0;
206  long indto = start;
207  if(increment==1) {
208  copy(*copyArray,indfrom,1,*masterArray,indto,1,len);
209  } else {
210  for(long i=0; i<len; ++i) {
211  copy(*copyArray,indfrom,1,*masterArray,indto,1,1);
212  indfrom += 1;
213  indto += increment;
214  }
215  }
216  if(isUnion) masterField->postPut();
217  return true;
218 }
int i
Definition: scan.c:967
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
pvd::StructureConstPtr type
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.
std::tr1::shared_ptr< PVUnion > PVUnionPtr
Definition: pvData.h:107
Base class for a scalarArray.
Definition: pvData.h:618
PVUnion has a single subfield.
Definition: pvData.h:940
void copy(const PVUnion &from)
Definition: PVUnion.cpp:199
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
std::tr1::shared_ptr< PVScalarArray > PVScalarArrayPtr
Definition: pvData.h:82
string epics::pvCopy::PVArrayFilter::getName ( )
virtual

Get the filter name.

Returns
The name.

Implements epics::pvCopy::PVFilter.

Definition at line 220 of file pvArrayPlugin.cpp.

221 {
222  return name;
223 }
epics::pvCopy::PVArrayFilter::POINTER_DEFINITIONS ( PVArrayFilter  )

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