9 #include <pv/convert.h> 10 #include <pv/pvSubArrayCopy.h> 11 #define epicsExportSharedSymbols 18 using std::tr1::static_pointer_cast;
22 namespace epics {
namespace pvCopy{
24 static ConvertPtr convert = getConvert();
25 static std::string name(
"array");
27 PVArrayPlugin::PVArrayPlugin()
31 PVArrayPlugin::~PVArrayPlugin()
35 void PVArrayPlugin::create()
37 static bool firstTime =
true;
41 PVPluginRegistry::registerPlugin(name,pvPlugin);
46 const std::string & requestValue,
48 const PVFieldPtr & master)
50 return PVArrayFilter::create(requestValue,master);
53 PVArrayFilter::~PVArrayFilter()
57 static vector<string> split(
string const & colonSeparatedList) {
58 string::size_type numValues = 1;
59 string::size_type index=0;
61 string::size_type pos = colonSeparatedList.find(
':',index);
62 if(pos==string::npos)
break;
66 vector<string> valueList(numValues,
"");
68 for(
size_t i=0; i<numValues; i++) {
69 size_t pos = colonSeparatedList.find(
':',index);
70 string value = colonSeparatedList.substr(index,pos-index);
78 const std::string & requestValue,
79 const PVFieldPtr & masterField)
81 bool masterIsUnion =
false;
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();
89 type = pvField->getField()->getType();
92 if(type!=scalarArray) {
99 vector<string> values(split(requestValue));
100 long num = values.size();
105 start = strtol(value.c_str(),0,10);
108 start = strtol(value.c_str(),0,10);
110 end = strtol(value.c_str(),0,10);
113 start = strtol(value.c_str(),0,10);
115 increment = strtol(value.c_str(),0,10);
117 end = strtol(value.c_str(),0,10);
125 PVScalarArrayPtr masterArray;
127 masterArray = static_pointer_cast<PVScalarArray>(pvUnion->get());
129 masterArray = static_pointer_cast<PVScalarArray>(masterField);
133 new PVArrayFilter(start,increment,end,masterField,masterArray));
137 PVArrayFilter::PVArrayFilter(
138 long start,
long increment,
long end,
139 const PVFieldPtr & masterField,
140 const epics::pvData::PVScalarArrayPtr masterArray)
142 increment(increment),
144 masterField(masterField),
145 masterArray(masterArray)
150 bool PVArrayFilter::filter(
const PVFieldPtr & pvField,
const BitSetPtr & bitSet,
bool toCopy)
152 PVFieldPtr pvCopy = pvField;
153 PVScalarArrayPtr copyArray;
154 bool isUnion =
false;
155 Type type = masterField->getField()->getType();
156 if(type==epics::pvData::union_) {
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);
164 copyArray = static_pointer_cast<PVScalarArray>(pvCopy);
167 long start = this->start;
168 long end = this->end;
169 long no_elements = masterArray->getLength();
171 start = no_elements+start;
172 if(start<0) start = 0;
175 end = no_elements + end;
176 if (end < 0) end = 0;
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);
186 long indfrom = start;
188 copyArray->setCapacity(len);
190 copy(*masterArray,indfrom,1,*copyArray,indto,1,len);
192 for(
long i=0; i<len; ++i) {
193 copy(*masterArray,indfrom,1,*copyArray,indto,1,1);
194 indfrom += increment;
198 copyArray->setLength(len);
199 bitSet->set(pvField->getFieldOffset());
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);
208 copy(*copyArray,indfrom,1,*masterArray,indto,1,len);
210 for(
long i=0; i<len; ++i) {
211 copy(*copyArray,indfrom,1,*masterArray,indto,1,1);
216 if(isUnion) masterField->postPut();
220 string PVArrayFilter::getName()
std::tr1::shared_ptr< PVFilter > PVFilterPtr
std::tr1::shared_ptr< PVCopy > PVCopyPtr
A filter that gets a sub array from a PVScalarArray.
std::tr1::shared_ptr< PVArrayFilter > PVArrayFilterPtr
std::tr1::shared_ptr< PVArrayPlugin > PVArrayPluginPtr
A plugin for a filter that gets a sub array from a PVScalarArray.