return arrayValue;
}
+template <typename T, typename=void>
+struct UniquenessChecker
+{
+ static bool get(const std::vector<T> &/*value*/)
+ {
+ return true;
+ }
+};
+
+template <typename T>
+struct UniquenessChecker<T, typename std::enable_if<
+ std::is_same<T, int>::value
+ || std::is_same<T, double>::value
+ || std::is_same<T, bool>::value
+ || std::is_same<T, std::string>::value
+ >::type >
+{
+ static bool get(const std::vector<T> &value)
+ {
+ std::vector<T> valueCopy = value;
+ std::sort(valueCopy.begin(), valueCopy.end());
+ if(valueCopy.end() != std::unique(valueCopy.begin(), valueCopy.end()))
+ return false;
+ return true;
+ }
+};
+
class IntegerValidator : public boost::static_visitor<bool>
{
public:
bool operator ()(const std::vector<T> &value)
{
// Validating length of array
- if (m_property->hasRange())
+ if (!checkLength(value))
{
- if (value.size() < m_property->getMinItems()
- || (value.size() > m_property->getMaxItems() && !m_property->isVariable()))
- {
- return false;
- }
+ return false;
+ }
+
+ // Validate the uniqueness of elements of array
+ if (!checkUniqueness(value))
+ {
+ return false;
}
// Validating elements of array
}
private:
+ template <typename T>
+ bool checkLength(const std::vector<T> &value)
+ {
+ if (m_property->hasRange())
+ {
+ if (value.size() < m_property->getMinItems()
+ || (value.size() > m_property->getMaxItems() && !m_property->isVariable()))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ template <typename T>
+ bool checkUniqueness(const std::vector<T> &value)
+ {
+ if (m_property->isUnique())
+ {
+ return UniquenessChecker<T>::get(value);
+ }
+
+ return true;
+ }
+
std::shared_ptr<ArrayProperty> m_property;
};
IntegerProperty::IntegerProperty(int defaultValue)
: AttributeProperty(AttributeProperty::Type::INTEGER),
m_defaultValue(defaultValue),
+ m_min(0),
+ m_max(0),
m_hasRange(false) {}
std::shared_ptr<IntegerProperty> IntegerProperty::build(int defaultValue)
DoubleProperty::DoubleProperty(double defaultValue)
: AttributeProperty(AttributeProperty::Type::DOUBLE),
m_defaultValue(defaultValue),
+ m_min(0),
+ m_max(0),
m_hasRange(false) {}
std::shared_ptr<DoubleProperty> DoubleProperty::build(double defaultValue)
StringProperty::StringProperty(const std::string &defaultValue)
: AttributeProperty(AttributeProperty::Type::STRING),
m_defaultValue(defaultValue),
+ m_min(0),
+ m_max(0),
m_hasRange(false) {}
std::shared_ptr<StringProperty> StringProperty::build(const std::string &defaultValue)
ArrayProperty::ArrayProperty()
: AttributeProperty(AttributeProperty::Type::ARRAY),
+ m_min(0),
+ m_max(0),
m_isVariableSize(false),
m_isUnique(false),
m_hasRange(false) {}