PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
createRequest.h
1 /*createRequest.h*/
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 #ifndef CREATEREQUEST_H
8 #define CREATEREQUEST_H
9 #include <string>
10 #include <sstream>
11 #include <vector>
12 
13 #include <pv/pvData.h>
14 #include <pv/lock.h>
15 #include <pv/bitSet.h>
16 
17 #include <shareLib.h>
18 
19 namespace epics { namespace pvData {
20 
21 class BitSet;
22 
31 class epicsShareClass CreateRequest {
32  public:
33  POINTER_DEFINITIONS(CreateRequest);
38  static CreateRequest::shared_pointer create();
39  ~CreateRequest() {};
48  PVStructure::shared_pointer createRequest(std::string const & request);
53  std::string getMessage() {return message;}
54 protected:
55  CreateRequest() {}
56  std::string message;
57 };
58 
65 epicsShareExtern
66 PVStructure::shared_pointer createRequest(std::string const & request);
67 
74 class epicsShareClass PVRequestMapper {
75 public:
76  enum mode_t {
92  };
93 
96  PVRequestMapper(const PVStructure& base,
97  const PVStructure& pvRequest,
98  mode_t mode = Mask);
99 
101  void reset();
102 
104  inline const StructureConstPtr& base() const { return typeBase; }
106  inline const StructureConstPtr& requested() const { return typeRequested; }
107 
121  inline const BitSet& requestedMask() const { return maskRequested; }
122 
124  PVStructurePtr buildRequested() const;
126  PVStructurePtr buildBase() const;
127 
138  void compute(const PVStructure& base,
139  const PVStructure& pvRequest,
140  mode_t mode = Mask);
141 
143  inline const std::string& warnings() const { return messages; }
144 
154  void copyBaseToRequested(
155  const PVStructure& base,
156  const BitSet& baseMask,
157  PVStructure& request,
158  BitSet& requestMask
159  ) const;
160 
170  void copyBaseFromRequested(
171  PVStructure& base,
172  BitSet& baseMask,
173  const PVStructure& request,
174  const BitSet& requestMask
175  ) const;
176 
179  inline void maskBaseToRequested(
180  const BitSet& baseMask,
181  BitSet& requestMask
182  ) const
183  { _mapMask(baseMask, requestMask, false); }
184 
188  BitSet& baseMask,
189  const BitSet& requestMask
190  ) const
191  { _mapMask(requestMask, baseMask, true); }
192 
194  void swap(PVRequestMapper& other);
195 
196 private:
197  bool _compute(const PVStructure& base, const PVStructure& pvReq,
198  FieldBuilderPtr& builder, bool keepids, unsigned depth);
199 
200  void _map(const PVStructure& src,
201  const BitSet& maskSrc,
202  PVStructure& dest,
203  BitSet& maskDest,
204  bool dir_r2b) const;
205  void _mapMask(const BitSet& maskSrc,
206  BitSet& maskDest,
207  bool dir_r2b) const;
208 
209  StructureConstPtr typeBase, typeRequested;
210  BitSet maskRequested;
211  // Map between field offsets of base and requested Structures.
212  // Include all fields, both leaf and sub-structure.
213  struct Mapping {
214  size_t to; // offset in destination Structure
215  BitSet tomask, // if !leaf these are the other bits in the destination mask to changed
216  frommask; // if !leaf these are the other bits in the source mask to be copied
217  bool valid; // only true in (sparse) base -> requested mapping
218  bool leaf; // not a (sub)Structure?
219  Mapping() :valid(false) {}
220  Mapping(size_t to, bool leaf) :to(to), valid(true), leaf(leaf) {}
221  };
222  typedef std::vector<Mapping> mapping_t;
223  mapping_t base2req, req2base;
224 
225  std::string messages;
226 
227  mutable BitSet scratch; // avoid temporary allocs. (we aren't re-entrant!)
228 };
229 
230 }}
231 
232 #endif /* CREATEREQUEST_H */
233 
void maskBaseToRequested(const BitSet &baseMask, BitSet &requestMask) const
void maskBaseFromRequested(BitSet &baseMask, const BitSet &requestMask) const
const std::string & warnings() const
After compute(), check if !warnings().empty()
Data interface for a structure,.
Definition: pvData.h:712
epicsShareExtern PVStructure::shared_pointer createRequest(std::string const &request)
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:154
const StructureConstPtr & base() const
T swap(T val)
Definition: byteBuffer.h:212
const BitSet & requestedMask() const
const StructureConstPtr & requested() const
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
Create pvRequest structure for Channel methods.
Definition: createRequest.h:31
A vector of bits.
Definition: bitSet.h:56