This is Unofficial EPICS BASE Doxygen Site
epics::nt::Result Struct Reference

Validation methods for NT types. More...

#include "validator.h"

+ Collaboration diagram for epics::nt::Result:

Classes

struct  Error
 

Public Types

enum  result_t { Pass, Fail }
 

Public Member Functions

 Result (const epics::pvData::FieldConstPtr &field, const std::string &path=std::string())
 
 Result ()
 
Resultoperator|= (const Result &other)
 
bool valid (void) const
 
template<typename T >
Resultis (void)
 
template<typename T >
Resultis (const std::string &id)
 
template<Result &(*)(Result &) fn>
Resulthas (const std::string &name)
 
template<Result &(*)(Result &) fn>
ResultmaybeHas (const std::string &name)
 
template<Result &(*)(Result &) fn, typename T >
Resulthas (const std::string &name)
 
template<Result &(*)(Result &) fn, typename T >
ResultmaybeHas (const std::string &name)
 
template<typename T >
Resulthas (const std::string &name)
 
template<typename T >
ResultmaybeHas (const std::string &name)
 
std::ostream & dump (std::ostream &os) const
 

Public Attributes

epics::pvData::FieldConstPtr field
 
std::string path
 
std::vector< Errorerrors
 
enum epics::nt::Result::result_t result
 

Detailed Description

Validation methods for NT types.

Author
bsm

Definition at line 23 of file validator.h.

Member Enumeration Documentation

Enumerator
Pass 
Fail 

Definition at line 56 of file validator.h.

56  {
57  Pass,
58  Fail,
59  } result;
enum epics::nt::Result::result_t result

Constructor & Destructor Documentation

epics::nt::Result::Result ( const epics::pvData::FieldConstPtr field,
const std::string &  path = std::string() 
)
inline

Definition at line 61 of file validator.h.

62  : field(field), path(path), errors(), result(Pass) {}
epics::pvData::FieldConstPtr field
Definition: validator.h:52
enum epics::nt::Result::result_t result
std::string path
Definition: validator.h:53
std::vector< Error > errors
Definition: validator.h:54
epics::nt::Result::Result ( )
inline

Definition at line 64 of file validator.h.

64 {}

Member Function Documentation

std::ostream& epics::nt::Result::dump ( std::ostream &  os) const
inline

Definition at line 220 of file validator.h.

220  {
221  os << "Result(valid=" << (result == Pass) << ", errors=[ ";
222 
223  std::vector<Error>::const_iterator it;
224  for (it = errors.begin(); it != errors.end(); ++it) {
225  (*it).dump(os);
226  os << " ";
227  }
228  os << "])";
229  return os;
230  }
enum epics::nt::Result::result_t result
std::vector< Error > errors
Definition: validator.h:54
template<Result &(*)(Result &) fn>
Result& epics::nt::Result::has ( const std::string &  name)
inline

Test that this Result's field has a subfield with name 'name' and apply the function 'fn' to the subfield.

Appends an Error::Type::IncorrectType if the field is not one of Structure, StructureArray, Union, UnionArray. Appends an Error::Type::MissingField if the subfield is not present.

Returns
itself

Definition at line 132 of file validator.h.

132  {
133  return has<epics::pvData::Field>(name, false, fn);
134  }
const ChannelProviderRegistry::factoryfn_t fn
template<Result &(*)(Result &) fn, typename T >
Result& epics::nt::Result::has ( const std::string &  name)
inline

Test that this Result's field has a subfield with name 'name', apply the function 'fn' to the subfield and test that the subfield is of type 'T'.

Appends an Error::Type::IncorrectType if the field is not one of Structure, StructureArray, Union, UnionArray. Appends an Error::Type::IncorrectType if the subfield is not of type 'T'. Appends an Error::Type::MissingField if the subfield is not present.

Returns
itself

Definition at line 165 of file validator.h.

165  {
166  return has<T>(name, false, fn);
167  }
const ChannelProviderRegistry::factoryfn_t fn
template<typename T >
Result& epics::nt::Result::has ( const std::string &  name)
inline

Test that this Result's field has a subfield with name 'name' and test that the subfield is of type 'T'.

Appends an Error::Type::IncorrectType if the field is not one of Structure, StructureArray, Union, UnionArray. Appends an Error::Type::IncorrectType if the subfield is not of type 'T'. Appends an Error::Type::MissingField if the subfield is not present.

Returns
itself

Definition at line 200 of file validator.h.

200  {
201  return has<T>(name, false, NULL);
202  }
#define NULL
Definition: catime.c:38
template<typename T >
Result& epics::nt::Result::is ( void  )
inline

Test that this Result's field is of a particular type 'T'.

Appends an Error::Type::IncorrectType if the field is not of type 'T'.

Returns
itself

Definition at line 89 of file validator.h.

89  {
90  if (!dynamic_cast<T const *>(field.get())) {
91  result = Fail;
92  errors.push_back(Error(path, Error::IncorrectType));
93  }
94  return *this;
95  }
epics::pvData::FieldConstPtr field
Definition: validator.h:52
enum epics::nt::Result::result_t result
std::string path
Definition: validator.h:53
std::vector< Error > errors
Definition: validator.h:54
template<typename T >
Result& epics::nt::Result::is ( const std::string &  id)
inline

Test that this Result's field is of a particular type 'T' and has an ID equal to 'id'.

Appends an Error::Type::IncorrectType if the field is not of type 'T'. Appends an Error::Type::IncorrectId if the field does not have an ID equal to 'id'.

Returns
itself

Definition at line 108 of file validator.h.

108  {
109  T const *s = dynamic_cast<T const *>(field.get());
110  if (!s) {
111  result = Fail;
112  errors.push_back(Error(path, Error::IncorrectType));
113  } else if (s->getID() != id) {
114  result = Fail;
115  errors.push_back(Error(path, Error::IncorrectId));
116  }
117  return *this;
118  }
epics::pvData::FieldConstPtr field
Definition: validator.h:52
enum epics::nt::Result::result_t result
std::string path
Definition: validator.h:53
std::vector< Error > errors
Definition: validator.h:54
template<Result &(*)(Result &) fn>
Result& epics::nt::Result::maybeHas ( const std::string &  name)
inline

Test that this Result's field has an optional subfield with name 'name' and, if it has, apply the function 'fn' to the subfield.

Appends an Error::Type::IncorrectType if the field is not one of Structure, StructureArray, Union, UnionArray.

Returns
itself

Definition at line 146 of file validator.h.

146  {
147  return has<epics::pvData::Field>(name, true, fn);
148  }
const ChannelProviderRegistry::factoryfn_t fn
template<Result &(*)(Result &) fn, typename T >
Result& epics::nt::Result::maybeHas ( const std::string &  name)
inline

Test that this Result's field has an optional subfield with name 'name' and, if it has, apply the function 'fn' to the subfield and test that the subfield is of type 'T'.

Appends an Error::Type::IncorrectType if the field is not one of Structure, StructureArray, Union, UnionArray. Appends an Error::Type::IncorrectType if the subfield exists and is not of type 'T'.

Returns
itself

Definition at line 182 of file validator.h.

182  {
183  return has<T>(name, true, fn);
184  }
const ChannelProviderRegistry::factoryfn_t fn
template<typename T >
Result& epics::nt::Result::maybeHas ( const std::string &  name)
inline

Test that this Result's field has an optional subfield with name 'name' and, if it has, test that the subfield is of type 'T'.

Appends an Error::Type::IncorrectType if the field is not one of Structure, StructureArray, Union, UnionArray. Appends an Error::Type::IncorrectType if the subfield exists and is not of type 'T'.

Returns
itself

Definition at line 216 of file validator.h.

216  {
217  return has<T>(name, true, NULL);
218  }
#define NULL
Definition: catime.c:38
Result& epics::nt::Result::operator|= ( const Result other)
inline

Definition at line 66 of file validator.h.

66  {
67  result = std::max(result, other.result);
68  errors.insert(errors.end(), other.errors.begin(), other.errors.end());
69  return *this;
70  }
#define max(x, y)
Definition: flexdef.h:81
enum epics::nt::Result::result_t result
std::vector< Error > errors
Definition: validator.h:54
bool epics::nt::Result::valid ( void  ) const
inline

Returns whether this Result is valid.

Returns
true if all tests passed, false otherwise.

Definition at line 77 of file validator.h.

77  {
78  return result == Pass;
79  }
enum epics::nt::Result::result_t result

Member Data Documentation

std::vector<Error> epics::nt::Result::errors

Definition at line 54 of file validator.h.

epics::pvData::FieldConstPtr epics::nt::Result::field

Definition at line 52 of file validator.h.

std::string epics::nt::Result::path

Definition at line 53 of file validator.h.

enum epics::nt::Result::result_t epics::nt::Result::result

The documentation for this struct was generated from the following file: