normativeTypesCPP
nturi.h
Go to the documentation of this file.
1 /* nturi.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 #ifndef NTURI_H
7 #define NTURI_H
8 
9 #include <vector>
10 #include <string>
11 
12 #ifdef epicsExportSharedSymbols
13 # define nturiEpicsExportSharedSymbols
14 # undef epicsExportSharedSymbols
15 #endif
16 
17 #ifdef nturiEpicsExportSharedSymbols
18 # define epicsExportSharedSymbols
19 # undef nturiEpicsExportSharedSymbols
20 #endif
21 
22 #include <pv/ntfield.h>
23 
24 #include <shareLib.h>
25 
26 namespace epics { namespace nt {
27 
28 class NTURI;
29 typedef std::tr1::shared_ptr<NTURI> NTURIPtr;
30 
31 namespace detail {
32 
40  class epicsShareClass NTURIBuilder :
41  public std::tr1::enable_shared_from_this<NTURIBuilder>
42  {
43  public:
44  POINTER_DEFINITIONS(NTURIBuilder);
45 
50  shared_pointer addAuthority();
51 
58  shared_pointer addQueryString(std::string const & name);
59 
66  shared_pointer addQueryDouble(std::string const & name);
67 
74  shared_pointer addQueryInt(std::string const & name);
75 
81  epics::pvData::StructureConstPtr createStructure();
82 
89  epics::pvData::PVStructurePtr createPVStructure();
90 
98  NTURIPtr create();
99 
106  shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
107 
108  private:
109  NTURIBuilder();
110 
111  void reset();
112 
113  std::vector<std::string> queryFieldNames;
114  std::vector<epics::pvData::ScalarType> queryTypes;
115 
116  bool authority;
117 
118  // NOTE: this preserves order, however it does not handle duplicates
119  epics::pvData::StringArray extraFieldNames;
120  epics::pvData::FieldConstPtrArray extraFields;
121 
122  friend class ::epics::nt::NTURI;
123  };
124 
125 }
126 
127 typedef std::tr1::shared_ptr<detail::NTURIBuilder> NTURIBuilderPtr;
128 
129 
130 
136 class epicsShareClass NTURI
137 {
138 public:
139  POINTER_DEFINITIONS(NTURI);
140 
141  static const std::string URI;
142 
154  static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
155 
165  static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
166 
178  static bool is_a(epics::pvData::StructureConstPtr const & structure);
179 
191  static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
192 
202  static bool isCompatible(
203  epics::pvData::StructureConstPtr const &structure);
204 
214  static bool isCompatible(
215  epics::pvData::PVStructurePtr const &pvStructure);
216 
225  bool isValid();
226 
231  static NTURIBuilderPtr createBuilder();
232 
236  ~NTURI() {}
237 
242  epics::pvData::PVStructurePtr getPVStructure() const;
243 
248  epics::pvData::PVStringPtr getScheme() const;
249 
254  epics::pvData::PVStringPtr getAuthority() const;
255 
260  epics::pvData::PVStringPtr getPath() const;
261 
266  epics::pvData::PVStructurePtr getQuery() const;
267 
274  epics::pvData::StringArray const & getQueryNames() const;
275 
281  epics::pvData::PVFieldPtr getQueryField(std::string const & name) const;
282 
292  template<typename PVT>
293  std::tr1::shared_ptr<PVT> getQueryField(std::string const & name) const
294  {
295  epics::pvData::PVFieldPtr pvField = getQueryField(name);
296  if (pvField.get())
297  return std::tr1::dynamic_pointer_cast<PVT>(pvField);
298  else
299  return std::tr1::shared_ptr<PVT>();
300  }
301 
302 private:
303  NTURI(epics::pvData::PVStructurePtr const & pvStructure);
304  epics::pvData::PVStructurePtr pvNTURI;
305  friend class detail::NTURIBuilder;
306 };
307 
308 }}
309 #endif /* NTURI_H */
Convenience Class for NTURI.
Definition: nturi.h:136
static const std::string URI
Definition: nturi.h:141
Interface for in-line creating of NTURI.
Definition: nturi.h:40
std::tr1::shared_ptr< NTURI > NTURIPtr
Definition: nturi.h:28
std::tr1::shared_ptr< PVT > getQueryField(std::string const &name) const
Definition: nturi.h:293
std::tr1::shared_ptr< detail::NTURIBuilder > NTURIBuilderPtr
Definition: nturi.h:127