From e46af2458876645e30c6a5e5f42cc90eb4e854f7 Mon Sep 17 00:00:00 2001 From: Tristan Penman Date: Sun, 5 Jul 2020 22:50:34 +1000 Subject: [PATCH] Cosmetic improvements for concrete_constraints.hpp and basic_constraint.hpp --- .../valijson/constraints/basic_constraint.hpp | 34 +- .../constraints/concrete_constraints.hpp | 465 +++++++++--------- 2 files changed, 240 insertions(+), 259 deletions(-) diff --git a/include/valijson/constraints/basic_constraint.hpp b/include/valijson/constraints/basic_constraint.hpp index 54aae5b..5f1b836 100644 --- a/include/valijson/constraints/basic_constraint.hpp +++ b/include/valijson/constraints/basic_constraint.hpp @@ -9,56 +9,46 @@ namespace valijson { namespace constraints { /** - * @brief Template class that implements the accept() and clone() functions of - * the Constraint interface. + * @brief Template class that implements the accept() and clone() functions of the Constraint interface. * - * @tparam ConstraintType name of the concrete constraint type, which must - * provide a copy constructor. + * @tparam ConstraintType name of the concrete constraint type, which must provide a copy constructor. */ template struct BasicConstraint: Constraint { typedef internal::CustomAllocator Allocator; - typedef std::basic_string, - internal::CustomAllocator > String; + typedef std::basic_string, internal::CustomAllocator> String; BasicConstraint() - : allocator() { } + : m_allocator() { } BasicConstraint(Allocator::CustomAlloc allocFn, Allocator::CustomFree freeFn) - : allocator(allocFn, freeFn) { } + : m_allocator(allocFn, freeFn) { } BasicConstraint(const BasicConstraint &other) - : allocator(other.allocator) { } + : m_allocator(other.m_allocator) { } - virtual ~BasicConstraint() { } + ~BasicConstraint() override = default; - virtual bool accept(ConstraintVisitor &visitor) const + bool accept(ConstraintVisitor &visitor) const override { return visitor.visit(*static_cast(this)); } - virtual Constraint * clone(CustomAlloc allocFn, CustomFree freeFn) const + Constraint * clone(CustomAlloc allocFn, CustomFree freeFn) const override { void *ptr = allocFn(sizeof(ConstraintType)); if (!ptr) { - throw std::runtime_error( - "Failed to allocate memory for cloned constraint"); + throw std::runtime_error("Failed to allocate memory for cloned constraint"); } - try { - return new (ptr) ConstraintType( - *static_cast(this)); - } catch (...) { - freeFn(ptr); - throw; - } + return new (ptr) ConstraintType(*static_cast(this)); } protected: - Allocator allocator; + Allocator m_allocator; }; } // namespace constraints diff --git a/include/valijson/constraints/concrete_constraints.hpp b/include/valijson/constraints/concrete_constraints.hpp index 7b8ba2c..41ce08e 100644 --- a/include/valijson/constraints/concrete_constraints.hpp +++ b/include/valijson/constraints/concrete_constraints.hpp @@ -26,7 +26,9 @@ #include namespace valijson { + class ValidationResults; + namespace constraints { /** @@ -40,22 +42,22 @@ class AllOfConstraint: public BasicConstraint { public: AllOfConstraint() - : subschemas(Allocator::rebind::other(allocator)) { } + : m_subschemas(Allocator::rebind::other(m_allocator)) { } AllOfConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - subschemas(Allocator::rebind::other(allocator)) { } + m_subschemas(Allocator::rebind::other(m_allocator)) { } void addSubschema(const Subschema *subschema) { - subschemas.push_back(subschema); + m_subschemas.push_back(subschema); } template void applyToSubschemas(const FunctorType &fn) const { unsigned int index = 0; - for (const Subschema *subschema : subschemas) { + for (const Subschema *subschema : m_subschemas) { if (!fn(index, subschema)) { return; } @@ -65,11 +67,10 @@ public: } private: - typedef std::vector > Subschemas; + typedef std::vector> Subschemas; /// Collection of sub-schemas, all of which must be satisfied - Subschemas subschemas; + Subschemas m_subschemas; }; /** @@ -83,22 +84,22 @@ class AnyOfConstraint: public BasicConstraint { public: AnyOfConstraint() - : subschemas(Allocator::rebind::other(allocator)) { } + : m_subschemas(Allocator::rebind::other(m_allocator)) { } AnyOfConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - subschemas(Allocator::rebind::other(allocator)) { } + m_subschemas(Allocator::rebind::other(m_allocator)) { } void addSubschema(const Subschema *subschema) { - subschemas.push_back(subschema); + m_subschemas.push_back(subschema); } template void applyToSubschemas(const FunctorType &fn) const { unsigned int index = 0; - for (const Subschema *subschema : subschemas) { + for (const Subschema *subschema : m_subschemas) { if (!fn(index, subschema)) { return; } @@ -108,11 +109,10 @@ public: } private: - typedef std::vector > Subschemas; + typedef std::vector> Subschemas; /// Collection of sub-schemas, at least one of which must be satisfied - Subschemas subschemas; + Subschemas m_subschemas; }; /** @@ -126,78 +126,78 @@ class ConditionalConstraint: public BasicConstraint { public: ConditionalConstraint() - : ifSubschema(NULL), - thenSubschema(NULL), - elseSubschema(NULL) { } + : m_ifSubschema(nullptr), + m_thenSubschema(nullptr), + m_elseSubschema(nullptr) { } ConditionalConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - ifSubschema(NULL), - thenSubschema(NULL), - elseSubschema(NULL) { } + m_ifSubschema(nullptr), + m_thenSubschema(nullptr), + m_elseSubschema(nullptr) { } const Subschema * getIfSubschema() const { - return ifSubschema; + return m_ifSubschema; } const Subschema * getThenSubschema() const { - return thenSubschema; + return m_thenSubschema; } const Subschema * getElseSubschema() const { - return elseSubschema; + return m_elseSubschema; } void setIfSubschema(const Subschema *subschema) { - ifSubschema = subschema; + m_ifSubschema = subschema; } void setThenSubschema(const Subschema *subschema) { - thenSubschema = subschema; + m_thenSubschema = subschema; } void setElseSubschema(const Subschema *subschema) { - elseSubschema = subschema; + m_elseSubschema = subschema; } private: - const Subschema *ifSubschema; - const Subschema *thenSubschema; - const Subschema *elseSubschema; + const Subschema *m_ifSubschema; + const Subschema *m_thenSubschema; + const Subschema *m_elseSubschema; }; class ConstConstraint: public BasicConstraint { public: ConstConstraint() - : value(nullptr) { } + : m_value(nullptr) { } ConstConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - value(nullptr) { } + m_value(nullptr) { } ConstConstraint(const ConstConstraint &other) : BasicConstraint(other), - value(other.value->clone()) { } + m_value(other.m_value->clone()) { } adapters::FrozenValue * getValue() const { - return value; + return m_value; } void setValue(const adapters::Adapter &value) { - this->value = value.freeze(); + m_value = value.freeze(); } private: - adapters::FrozenValue *value; + adapters::FrozenValue *m_value; }; /** @@ -210,24 +210,24 @@ class ContainsConstraint: public BasicConstraint { public: ContainsConstraint() - : subschema(nullptr) { } + : m_subschema(nullptr) { } ContainsConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - subschema(nullptr) { } + m_subschema(nullptr) { } const Subschema * getSubschema() const { - return subschema; + return m_subschema; } void setSubschema(const Subschema *subschema) { - this->subschema = subschema; + m_subschema = subschema; } private: - const Subschema *subschema; + const Subschema *m_subschema; }; /** @@ -240,14 +240,14 @@ class DependenciesConstraint: public BasicConstraint { public: DependenciesConstraint() - : propertyDependencies(std::less(), allocator), - schemaDependencies(std::less(), allocator) + : m_propertyDependencies(std::less(), m_allocator), + m_schemaDependencies(std::less(), m_allocator) { } DependenciesConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - propertyDependencies(std::less(), allocator), - schemaDependencies(std::less(), allocator) + m_propertyDependencies(std::less(), m_allocator), + m_schemaDependencies(std::less(), m_allocator) { } template @@ -255,14 +255,14 @@ public: const StringType &propertyName, const StringType &dependencyName) { - const String key(propertyName.c_str(), allocator); - PropertyDependencies::iterator itr = propertyDependencies.find(key); - if (itr == propertyDependencies.end()) { - itr = propertyDependencies.insert(PropertyDependencies::value_type( - key, PropertySet(std::less(), allocator))).first; + const String key(propertyName.c_str(), m_allocator); + auto itr = m_propertyDependencies.find(key); + if (itr == m_propertyDependencies.end()) { + itr = m_propertyDependencies.insert(PropertyDependencies::value_type( + key, PropertySet(std::less(), m_allocator))).first; } - itr->second.insert(String(dependencyName.c_str(), allocator)); + itr->second.insert(String(dependencyName.c_str(), m_allocator)); return *this; } @@ -272,41 +272,38 @@ public: const StringType &propertyName, const ContainerType &dependencyNames) { - const String key(propertyName.c_str(), allocator); - PropertyDependencies::iterator itr = propertyDependencies.find(key); - if (itr == propertyDependencies.end()) { - itr = propertyDependencies.insert(PropertyDependencies::value_type( - key, PropertySet(std::less(), allocator))).first; + const String key(propertyName.c_str(), m_allocator); + auto itr = m_propertyDependencies.find(key); + if (itr == m_propertyDependencies.end()) { + itr = m_propertyDependencies.insert(PropertyDependencies::value_type( + key, PropertySet(std::less(), m_allocator))).first; } typedef typename ContainerType::value_type ValueType; for (const ValueType &dependencyName : dependencyNames) { - itr->second.insert(String(dependencyName.c_str(), allocator)); + itr->second.insert(String(dependencyName.c_str(), m_allocator)); } return *this; } template - DependenciesConstraint & addSchemaDependency( - const StringType &propertyName, - const Subschema *schemaDependency) + DependenciesConstraint & addSchemaDependency(const StringType &propertyName, const Subschema *schemaDependency) { - if (schemaDependencies.insert(SchemaDependencies::value_type( - String(propertyName.c_str(), allocator), + if (m_schemaDependencies.insert(SchemaDependencies::value_type( + String(propertyName.c_str(), m_allocator), schemaDependency)).second) { return *this; } - throw std::runtime_error( - "Dependencies constraint already contains a dependent " + throw std::runtime_error("Dependencies constraint already contains a dependent " "schema for the property '" + propertyName + "'"); } template void applyToPropertyDependencies(const FunctorType &fn) const { - for (const PropertyDependencies::value_type &v : propertyDependencies) { + for (const PropertyDependencies::value_type &v : m_propertyDependencies) { if (!fn(v.first, v.second)) { return; } @@ -316,7 +313,7 @@ public: template void applyToSchemaDependencies(const FunctorType &fn) const { - for (const SchemaDependencies::value_type &v : schemaDependencies) { + for (const SchemaDependencies::value_type &v : m_schemaDependencies) { if (!fn(v.first, v.second)) { return; } @@ -324,20 +321,19 @@ public: } private: - typedef std::set, internal::CustomAllocator > PropertySet; + typedef std::set, internal::CustomAllocator> PropertySet; typedef std::map, - internal::CustomAllocator > > PropertyDependencies; + internal::CustomAllocator>> PropertyDependencies; typedef std::map, - internal::CustomAllocator > > - SchemaDependencies; + internal::CustomAllocator>> SchemaDependencies; /// Mapping from property names to their property-based dependencies - PropertyDependencies propertyDependencies; + PropertyDependencies m_propertyDependencies; /// Mapping from property names to their schema-based dependencies - SchemaDependencies schemaDependencies; + SchemaDependencies m_schemaDependencies; }; /** @@ -351,22 +347,22 @@ class EnumConstraint: public BasicConstraint { public: EnumConstraint() - : enumValues(Allocator::rebind::other(allocator)) { } + : m_enumValues(Allocator::rebind::other(m_allocator)) { } EnumConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - enumValues(Allocator::rebind::other(allocator)) { } + m_enumValues(Allocator::rebind::other(m_allocator)) { } EnumConstraint(const EnumConstraint &other) : BasicConstraint(other), - enumValues(Allocator::rebind::other(allocator)) + m_enumValues(Allocator::rebind::other(m_allocator)) { try { // Clone individual enum values - for (const EnumValue *otherValue : other.enumValues) { + for (const EnumValue *otherValue : other.m_enumValues) { const EnumValue *value = otherValue->clone(); try { - enumValues.push_back(value); + m_enumValues.push_back(value); } catch (...) { delete value; throw; @@ -374,16 +370,16 @@ public: } } catch (...) { // Delete values already added to constraint - for (const EnumValue *value : enumValues) { + for (const EnumValue *value : m_enumValues) { delete value; } throw; } } - virtual ~EnumConstraint() + ~EnumConstraint() override { - for (const EnumValue *value : enumValues) { + for (const EnumValue *value : m_enumValues) { delete value; } } @@ -391,19 +387,19 @@ public: void addValue(const adapters::Adapter &value) { // TODO: Freeze value using custom alloc/free functions - enumValues.push_back(value.freeze()); + m_enumValues.push_back(value.freeze()); } void addValue(const adapters::FrozenValue &value) { // TODO: Clone using custom alloc/free functions - enumValues.push_back(value.clone()); + m_enumValues.push_back(value.clone()); } template void applyToValues(const FunctorType &fn) const { - for (const EnumValue *value : enumValues) { + for (const EnumValue *value : m_enumValues) { if (!fn(*value)) { return; } @@ -413,10 +409,9 @@ public: private: typedef adapters::FrozenValue EnumValue; - typedef std::vector > EnumValues; + typedef std::vector> EnumValues; - EnumValues enumValues; + EnumValues m_enumValues; }; /** @@ -436,24 +431,24 @@ class LinearItemsConstraint: public BasicConstraint { public: LinearItemsConstraint() - : itemSubschemas(Allocator::rebind::other(allocator)), - additionalItemsSubschema(NULL) { } + : m_itemSubschemas(Allocator::rebind::other(m_allocator)), + m_additionalItemsSubschema(nullptr) { } LinearItemsConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - itemSubschemas(Allocator::rebind::other(allocator)), - additionalItemsSubschema(NULL) { } + m_itemSubschemas(Allocator::rebind::other(m_allocator)), + m_additionalItemsSubschema(nullptr) { } void addItemSubschema(const Subschema *subschema) { - itemSubschemas.push_back(subschema); + m_itemSubschemas.push_back(subschema); } template void applyToItemSubschemas(const FunctorType &fn) const { unsigned int index = 0; - for (const Subschema *subschema : itemSubschemas) { + for (const Subschema *subschema : m_itemSubschemas) { if (!fn(index, subschema)) { return; } @@ -464,26 +459,25 @@ public: const Subschema * getAdditionalItemsSubschema() const { - return additionalItemsSubschema; + return m_additionalItemsSubschema; } size_t getItemSubschemaCount() const { - return itemSubschemas.size(); + return m_itemSubschemas.size(); } void setAdditionalItemsSubschema(const Subschema *subschema) { - additionalItemsSubschema = subschema; + m_additionalItemsSubschema = subschema; } private: - typedef std::vector > Subschemas; + typedef std::vector> Subschemas; - Subschemas itemSubschemas; + Subschemas m_itemSubschemas; - const Subschema* additionalItemsSubschema; + const Subschema* m_additionalItemsSubschema; }; /** @@ -493,37 +487,37 @@ class MaximumConstraint: public BasicConstraint { public: MaximumConstraint() - : maximum(std::numeric_limits::infinity()), - exclusiveMaximum(false) { } + : m_maximum(std::numeric_limits::infinity()), + m_exclusiveMaximum(false) { } MaximumConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - maximum(std::numeric_limits::infinity()), - exclusiveMaximum(false) { } + m_maximum(std::numeric_limits::infinity()), + m_exclusiveMaximum(false) { } bool getExclusiveMaximum() const { - return exclusiveMaximum; + return m_exclusiveMaximum; } void setExclusiveMaximum(bool newExclusiveMaximum) { - exclusiveMaximum = newExclusiveMaximum; + m_exclusiveMaximum = newExclusiveMaximum; } double getMaximum() const { - return maximum; + return m_maximum; } void setMaximum(double newMaximum) { - maximum = newMaximum; + m_maximum = newMaximum; } private: - double maximum; - bool exclusiveMaximum; + double m_maximum; + bool m_exclusiveMaximum; }; /** @@ -533,24 +527,24 @@ class MaxItemsConstraint: public BasicConstraint { public: MaxItemsConstraint() - : maxItems(std::numeric_limits::max()) { } + : m_maxItems(std::numeric_limits::max()) { } MaxItemsConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - maxItems(std::numeric_limits::max()) { } + m_maxItems(std::numeric_limits::max()) { } uint64_t getMaxItems() const { - return maxItems; + return m_maxItems; } void setMaxItems(uint64_t newMaxItems) { - maxItems = newMaxItems; + m_maxItems = newMaxItems; } private: - uint64_t maxItems; + uint64_t m_maxItems; }; /** @@ -560,24 +554,24 @@ class MaxLengthConstraint: public BasicConstraint { public: MaxLengthConstraint() - : maxLength(std::numeric_limits::max()) { } + : m_maxLength(std::numeric_limits::max()) { } MaxLengthConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - maxLength(std::numeric_limits::max()) { } + m_maxLength(std::numeric_limits::max()) { } uint64_t getMaxLength() const { - return maxLength; + return m_maxLength; } void setMaxLength(uint64_t newMaxLength) { - maxLength = newMaxLength; + m_maxLength = newMaxLength; } private: - uint64_t maxLength; + uint64_t m_maxLength; }; /** @@ -587,24 +581,24 @@ class MaxPropertiesConstraint: public BasicConstraint { public: MaxPropertiesConstraint() - : maxProperties(std::numeric_limits::max()) { } + : m_maxProperties(std::numeric_limits::max()) { } MaxPropertiesConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - maxProperties(std::numeric_limits::max()) { } + m_maxProperties(std::numeric_limits::max()) { } uint64_t getMaxProperties() const { - return maxProperties; + return m_maxProperties; } void setMaxProperties(uint64_t newMaxProperties) { - maxProperties = newMaxProperties; + m_maxProperties = newMaxProperties; } private: - uint64_t maxProperties; + uint64_t m_maxProperties; }; /** @@ -614,37 +608,37 @@ class MinimumConstraint: public BasicConstraint { public: MinimumConstraint() - : minimum(-std::numeric_limits::infinity()), - exclusiveMinimum(false) { } + : m_minimum(-std::numeric_limits::infinity()), + m_exclusiveMinimum(false) { } MinimumConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - minimum(-std::numeric_limits::infinity()), - exclusiveMinimum(false) { } + m_minimum(-std::numeric_limits::infinity()), + m_exclusiveMinimum(false) { } bool getExclusiveMinimum() const { - return exclusiveMinimum; + return m_exclusiveMinimum; } void setExclusiveMinimum(bool newExclusiveMinimum) { - exclusiveMinimum = newExclusiveMinimum; + m_exclusiveMinimum = newExclusiveMinimum; } double getMinimum() const { - return minimum; + return m_minimum; } void setMinimum(double newMinimum) { - minimum = newMinimum; + m_minimum = newMinimum; } private: - double minimum; - bool exclusiveMinimum; + double m_minimum; + bool m_exclusiveMinimum; }; /** @@ -654,24 +648,24 @@ class MinItemsConstraint: public BasicConstraint { public: MinItemsConstraint() - : minItems(0) { } + : m_minItems(0) { } MinItemsConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - minItems(0) { } + m_minItems(0) { } uint64_t getMinItems() const { - return minItems; + return m_minItems; } void setMinItems(uint64_t newMinItems) { - minItems = newMinItems; + m_minItems = newMinItems; } private: - uint64_t minItems; + uint64_t m_minItems; }; /** @@ -681,24 +675,24 @@ class MinLengthConstraint: public BasicConstraint { public: MinLengthConstraint() - : minLength(0) { } + : m_minLength(0) { } MinLengthConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - minLength(0) { } + m_minLength(0) { } int64_t getMinLength() const { - return minLength; + return m_minLength; } void setMinLength(uint64_t newMinLength) { - minLength = newMinLength; + m_minLength = newMinLength; } private: - uint64_t minLength; + uint64_t m_minLength; }; /** @@ -708,24 +702,24 @@ class MinPropertiesConstraint: public BasicConstraint { public: MinPropertiesConstraint() - : minProperties(0) { } + : m_minProperties(0) { } MinPropertiesConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - minProperties(0) { } + m_minProperties(0) { } uint64_t getMinProperties() const { - return minProperties; + return m_minProperties; } void setMinProperties(uint64_t newMinProperties) { - minProperties = newMinProperties; + m_minProperties = newMinProperties; } private: - uint64_t minProperties; + uint64_t m_minProperties; }; /** @@ -737,24 +731,24 @@ class MultipleOfDoubleConstraint: { public: MultipleOfDoubleConstraint() - : value(1.) { } + : m_value(1.) { } MultipleOfDoubleConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - value(1.) { } + m_value(1.) { } double getDivisor() const { - return value; + return m_value; } void setDivisor(double newValue) { - value = newValue; + m_value = newValue; } private: - double value; + double m_value; }; /** @@ -766,24 +760,24 @@ class MultipleOfIntConstraint: { public: MultipleOfIntConstraint() - : value(1) { } + : m_value(1) { } MultipleOfIntConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - value(1) { } + m_value(1) { } int64_t getDivisor() const { - return value; + return m_value; } void setDivisor(int64_t newValue) { - value = newValue; + m_value = newValue; } private: - int64_t value; + int64_t m_value; }; /** @@ -793,24 +787,24 @@ class NotConstraint: public BasicConstraint { public: NotConstraint() - : subschema(NULL) { } + : m_subschema(nullptr) { } NotConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - subschema(NULL) { } + m_subschema(nullptr) { } const Subschema * getSubschema() const { - return subschema; + return m_subschema; } void setSubschema(const Subschema *subschema) { - this->subschema = subschema; + m_subschema = subschema; } private: - const Subschema *subschema; + const Subschema *m_subschema; }; /** @@ -820,22 +814,22 @@ class OneOfConstraint: public BasicConstraint { public: OneOfConstraint() - : subschemas(Allocator::rebind::other(allocator)) { } + : m_subschemas(Allocator::rebind::other(m_allocator)) { } OneOfConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - subschemas(Allocator::rebind::other(allocator)) { } + m_subschemas(Allocator::rebind::other(m_allocator)) { } void addSubschema(const Subschema *subschema) { - subschemas.push_back(subschema); + m_subschemas.push_back(subschema); } template void applyToSubschemas(const FunctorType &fn) const { unsigned int index = 0; - for (const Subschema *subschema : subschemas) { + for (const Subschema *subschema : m_subschemas) { if (!fn(index, subschema)) { return; } @@ -845,11 +839,10 @@ public: } private: - typedef std::vector > Subschemas; + typedef std::vector> Subschemas; /// Collection of sub-schemas, exactly one of which must be satisfied - Subschemas subschemas; + Subschemas m_subschemas; }; /** @@ -859,17 +852,16 @@ class PatternConstraint: public BasicConstraint { public: PatternConstraint() - : pattern(Allocator::rebind::other(allocator)) { } + : m_pattern(Allocator::rebind::other(m_allocator)) { } PatternConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - pattern(Allocator::rebind::other(allocator)) { } + m_pattern(Allocator::rebind::other(m_allocator)) { } template - bool getPattern(std::basic_string, - AllocatorType> &result) const + bool getPattern(std::basic_string, AllocatorType> &result) const { - result.assign(this->pattern.c_str()); + result.assign(m_pattern.c_str()); return true; } @@ -877,35 +869,32 @@ public: std::basic_string, AllocatorType> getPattern( const AllocatorType &alloc = AllocatorType()) const { - return std::basic_string, AllocatorType>( - pattern.c_str(), alloc); + return std::basic_string, AllocatorType>(m_pattern.c_str(), alloc); } template - void setPattern(const std::basic_string, - AllocatorType> &pattern) + void setPattern(const std::basic_string, AllocatorType> &pattern) { - this->pattern.assign(pattern.c_str()); + m_pattern.assign(pattern.c_str()); } private: - String pattern; + String m_pattern; }; class PolyConstraint : public Constraint { public: - virtual bool accept(ConstraintVisitor &visitor) const + bool accept(ConstraintVisitor &visitor) const override { return visitor.visit(*static_cast(this)); } - virtual Constraint * clone(CustomAlloc allocFn, CustomFree freeFn) const + Constraint * clone(CustomAlloc allocFn, CustomFree freeFn) const override { void *ptr = allocFn(sizeOf()); if (!ptr) { - throw std::runtime_error( - "Failed to allocate memory for cloned constraint"); + throw std::runtime_error("Failed to allocate memory for cloned constraint"); } try { @@ -934,21 +923,20 @@ class PropertiesConstraint: public BasicConstraint { public: PropertiesConstraint() - : properties(std::less(), allocator), - patternProperties(std::less(), allocator), - additionalProperties(NULL) { } + : m_properties(std::less(), m_allocator), + m_patternProperties(std::less(), m_allocator), + m_additionalProperties(nullptr) { } PropertiesConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - properties(std::less(), allocator), - patternProperties(std::less(), allocator), - additionalProperties(NULL) { } + m_properties(std::less(), m_allocator), + m_patternProperties(std::less(), m_allocator), + m_additionalProperties(nullptr) { } - bool addPatternPropertySubschema(const char *patternProperty, - const Subschema *subschema) + bool addPatternPropertySubschema(const char *patternProperty, const Subschema *subschema) { - return patternProperties.insert(PropertySchemaMap::value_type( - String(patternProperty, allocator), subschema)).second; + return m_patternProperties.insert(PropertySchemaMap::value_type( + String(patternProperty, m_allocator), subschema)).second; } template @@ -962,8 +950,8 @@ public: bool addPropertySubschema(const char *propertyName, const Subschema *subschema) { - return properties.insert(PropertySchemaMap::value_type( - String(propertyName, allocator), subschema)).second; + return m_properties.insert(PropertySchemaMap::value_type( + String(propertyName, m_allocator), subschema)).second; } template @@ -978,7 +966,7 @@ public: void applyToPatternProperties(const FunctorType &fn) const { typedef typename PropertySchemaMap::value_type ValueType; - for (const ValueType &value : patternProperties) { + for (const ValueType &value : m_patternProperties) { if (!fn(value.first, value.second)) { return; } @@ -989,7 +977,7 @@ public: void applyToProperties(const FunctorType &fn) const { typedef typename PropertySchemaMap::value_type ValueType; - for (const ValueType &value : properties) { + for (const ValueType &value : m_properties) { if (!fn(value.first, value.second)) { return; } @@ -998,46 +986,50 @@ public: const Subschema * getAdditionalPropertiesSubschema() const { - return additionalProperties; + return m_additionalProperties; } void setAdditionalPropertiesSubschema(const Subschema *subschema) { - additionalProperties = subschema; + m_additionalProperties = subschema; } private: - typedef std::map, internal::CustomAllocator > > - PropertySchemaMap; + typedef std::map< + String, + const Subschema *, + std::less, + internal::CustomAllocator> + > PropertySchemaMap; - PropertySchemaMap properties; - PropertySchemaMap patternProperties; + PropertySchemaMap m_properties; + PropertySchemaMap m_patternProperties; - const Subschema *additionalProperties; + const Subschema *m_additionalProperties; }; class PropertyNamesConstraint: public BasicConstraint { public: PropertyNamesConstraint() - : subschema(NULL) { } + : m_subschema(nullptr) { } PropertyNamesConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - subschema(NULL) { } + m_subschema(nullptr) { } const Subschema * getSubschema() const { - return subschema; + return m_subschema; } void setSubschema(const Subschema *subschema) { - this->subschema = subschema; + m_subschema = subschema; } private: - const Subschema *subschema; + const Subschema *m_subschema; }; /** @@ -1047,21 +1039,20 @@ class RequiredConstraint: public BasicConstraint { public: RequiredConstraint() - : requiredProperties(std::less(), allocator) { } + : m_requiredProperties(std::less(), m_allocator) { } RequiredConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - requiredProperties(std::less(), allocator) { } + m_requiredProperties(std::less(), m_allocator) { } bool addRequiredProperty(const char *propertyName) { - return requiredProperties.insert(String(propertyName, - Allocator::rebind::other(allocator))).second; + return m_requiredProperties.insert(String(propertyName, + Allocator::rebind::other(m_allocator))).second; } template - bool addRequiredProperty(const std::basic_string, AllocatorType> &propertyName) + bool addRequiredProperty(const std::basic_string, AllocatorType> &propertyName) { return addRequiredProperty(propertyName.c_str()); } @@ -1069,7 +1060,7 @@ public: template void applyToRequiredProperties(const FunctorType &fn) const { - for (const String &propertyName : requiredProperties) { + for (const String &propertyName : m_requiredProperties) { if (!fn(propertyName)) { return; } @@ -1078,9 +1069,9 @@ public: private: typedef std::set, - internal::CustomAllocator > RequiredProperties; + internal::CustomAllocator> RequiredProperties; - RequiredProperties requiredProperties; + RequiredProperties m_requiredProperties; }; /** @@ -1097,24 +1088,24 @@ class SingularItemsConstraint: public BasicConstraint { public: SingularItemsConstraint() - : itemsSubschema(NULL) { } + : m_itemsSubschema(nullptr) { } SingularItemsConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - itemsSubschema(NULL) { } + m_itemsSubschema(nullptr) { } const Subschema * getItemsSubschema() const { - return itemsSubschema; + return m_itemsSubschema; } void setItemsSubschema(const Subschema *subschema) { - itemsSubschema = subschema; + m_itemsSubschema = subschema; } private: - const Subschema *itemsSubschema; + const Subschema *m_itemsSubschema; }; /** @@ -1135,28 +1126,28 @@ public: }; TypeConstraint() - : namedTypes(std::less(), allocator), - schemaTypes(Allocator::rebind::other(allocator)) { } + : m_namedTypes(std::less(), m_allocator), + m_schemaTypes(Allocator::rebind::other(m_allocator)) { } TypeConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn), - namedTypes(std::less(), allocator), - schemaTypes(Allocator::rebind::other(allocator)) { } + m_namedTypes(std::less(), m_allocator), + m_schemaTypes(Allocator::rebind::other(m_allocator)) { } void addNamedType(JsonType type) { - namedTypes.insert(type); + m_namedTypes.insert(type); } void addSchemaType(const Subschema *subschema) { - schemaTypes.push_back(subschema); + m_schemaTypes.push_back(subschema); } template void applyToNamedTypes(const FunctorType &fn) const { - for (const JsonType namedType : namedTypes) { + for (const JsonType namedType : m_namedTypes) { if (!fn(namedType)) { return; } @@ -1167,7 +1158,7 @@ public: void applyToSchemaTypes(const FunctorType &fn) const { unsigned int index = 0; - for (const Subschema *subschema : schemaTypes) { + for (const Subschema *subschema : m_schemaTypes) { if (!fn(index, subschema)) { return; } @@ -1203,16 +1194,16 @@ public: } private: - typedef std::set, internal::CustomAllocator > NamedTypes; + typedef std::set, internal::CustomAllocator> NamedTypes; typedef std::vector::other> SchemaTypes; /// Set of named JSON types that serve as valid types - NamedTypes namedTypes; + NamedTypes m_namedTypes; /// Set of sub-schemas that serve as valid types - SchemaTypes schemaTypes; + SchemaTypes m_schemaTypes; }; /** @@ -1221,7 +1212,7 @@ private: class UniqueItemsConstraint: public BasicConstraint { public: - UniqueItemsConstraint() { } + UniqueItemsConstraint() = default; UniqueItemsConstraint(CustomAlloc allocFn, CustomFree freeFn) : BasicConstraint(allocFn, freeFn) { }