13 #include <pv/pvIntrospect.h> 15 namespace epics {
namespace nt {
33 : path(path), type(type) {}
36 return type == other.
type && path == other.
path;
39 std::ostream&
dump(std::ostream& os)
const {
40 os <<
"Error(path=" << (path.empty() ?
"<root>" :
path) <<
": ";
52 epics::pvData::FieldConstPtr
field;
61 Result(
const epics::pvData::FieldConstPtr& field,
const std::string& path = std::string())
62 : field(field), path(path), errors(), result(
Pass) {}
67 result = std::max(result, other.
result);
68 errors.insert(errors.end(), other.
errors.begin(), other.
errors.end());
78 return result ==
Pass;
90 if (!dynamic_cast<T const *>(field.get())) {
109 T
const *s =
dynamic_cast<T
const *
>(field.get());
113 }
else if (s->getID() != id) {
131 template<Result& (*fn)(Result&)>
133 return has<epics::pvData::Field>(name,
false, fn);
145 template<Result& (*fn)(Result&)>
147 return has<epics::pvData::Field>(name,
true, fn);
164 template<Result& (*fn)(Result&),
typename T>
166 return has<T>(name,
false, fn);
181 template<Result& (*fn)(Result&),
typename T>
183 return has<T>(name,
true, fn);
201 return has<T>(name,
false, NULL);
217 return has<T>(name,
true, NULL);
220 std::ostream&
dump(std::ostream& os)
const {
221 os <<
"Result(valid=" << (result ==
Pass) <<
", errors=[ ";
223 std::vector<Error>::const_iterator it;
224 for (it = errors.begin(); it != errors.end(); ++it) {
235 epics::pvData::FieldConstPtr subField;
237 switch(field->getType()) {
238 case epics::pvData::structure:
239 subField =
static_cast<epics::pvData::Structure
const *
>(field.get())->getField(name);
241 case epics::pvData::structureArray:
242 subField =
static_cast<epics::pvData::StructureArray
const *
>(field.get())->getStructure()->getField(name);
244 case epics::pvData::union_:
245 subField =
static_cast<epics::pvData::Union
const *
>(field.get())->getField(name);
247 case epics::pvData::unionArray:
248 subField =
static_cast<epics::pvData::UnionArray
const *
>(field.get())->getUnion()->getField(name);
257 std::string subFieldPath(path.empty() ? name : path +
"." + name);
264 }
else if (!dynamic_cast<T const *>(subField.get())) {
268 Result r(subField, subFieldPath);
epics::pvData::FieldConstPtr field
Result & maybeHas(const std::string &name)
Result(const epics::pvData::FieldConstPtr &field, const std::string &path=std::string())
Validation methods for NT types.
Result & is(const std::string &id)
enum epics::nt::Result::result_t result
Result & has(const std::string &name)
Result & maybeHas(const std::string &name)
Error(std::string const &path, Type type)
std::ostream & dump(std::ostream &os) const
enum epics::nt::Result::Error::Type type
Result & operator|=(const Result &other)
std::vector< Error > errors
Result & has(const std::string &name)
std::ostream & dump(std::ostream &os) const
bool operator==(const Error &other) const