25template <
typename HeldType>
class DLLExport TypedValidator :
public IValidator {
28 virtual std::string checkValidity(
const HeldType &)
const = 0;
37 std::string check(
const boost::any &
value)
const override {
39 const HeldType *dataPtr = boost::any_cast<const HeldType *>(
value);
40 return checkValidity(*dataPtr);
41 }
catch (boost::bad_any_cast &) {
42 return "Value was not of expected type.";
59template <
typename ElementType>
class DLLExport TypedValidator<
std::shared_ptr<ElementType>> :
public IValidator {
61 using ElementType_sptr = std::shared_ptr<ElementType>;
65 virtual std::string checkValidity(
const ElementType_sptr &)
const = 0;
76 std::string check(
const boost::any &
value)
const override {
78 const ElementType_sptr typedValue = extractValue(
value);
79 return checkValidity(typedValue);
80 }
catch (std::invalid_argument &exc) {
89 ElementType_sptr extractValue(
const boost::any &
value)
const {
94 if (
value.type().hash_code() == m_dataitemTypeID.hash_code())
96 if (
value.type() == m_dataitemTypeID)
99 return extractFromDataItem(
value);
101 return extractFromSharedPtr(
value);
109 ElementType_sptr extractFromDataItem(
const boost::any &
value)
const {
112 ElementType_sptr typedValue = std::dynamic_pointer_cast<ElementType>(data);
114 throw std::invalid_argument(
"DataItem \"" + data->getName() +
"\" is not of the expected type.");
123 ElementType_sptr extractFromSharedPtr(
const boost::any &
value)
const {
125 return boost::any_cast<ElementType_sptr>(
value);
126 }
catch (boost::bad_any_cast &) {
127 throw std::invalid_argument(
"Value was not a shared_ptr type");
131 static const std::type_info &m_dataitemTypeID;
140const std::type_info &TypedValidator<std::shared_ptr<T>>::m_dataitemTypeID =
typeid(std::shared_ptr<DataItem>);
double value
The value of the point.
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
std::shared_ptr< DataItem > DataItem_sptr
Shared pointer to a DataItem.
Helper class which provides the Collimation Length for SANS instruments.