/** \brief verify that all required fields are present, * and all present fields are either required or optional * \throw ArgumentError */ void validate(const ControlParameters& parameters) const { const std::vector<bool>& presentFields = parameters.getPresentFields(); for (size_t i = 0; i < CONTROL_PARAMETER_UBOUND; ++i) { bool isPresent = presentFields[i]; if (m_required[i]) { if (!isPresent) { throw ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but missing"); } } else if (isPresent && !m_optional[i]) { throw ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but present"); } } }
void ControlCommand::FieldValidator::validate(const ControlParameters& parameters) const { const std::vector<bool>& presentFields = parameters.getPresentFields(); for (size_t i = 0; i < CONTROL_PARAMETER_UBOUND; ++i) { bool isPresent = presentFields[i]; if (m_required[i]) { if (!isPresent) { BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but " "missing")); } } else if (isPresent && !m_optional[i]) { BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but " "present")); } } }
void ControlCommand::FieldValidator::validate(const ControlParameters& parameters) const { const std::vector<bool>& presentFields = parameters.getPresentFields(); for (size_t i = 0; i < CONTROL_PARAMETER_UBOUND; ++i) { bool isPresent = presentFields[i]; if (m_required[i]) { if (!isPresent) { BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but missing")); } } else if (isPresent && !m_optional[i]) { BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but present")); } } if (m_optional[CONTROL_PARAMETER_FLAGS] && m_optional[CONTROL_PARAMETER_MASK]) { if (parameters.hasFlags() != parameters.hasMask()) { BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask")); } } }