mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-01-07 09:48:05 +01:00
Remove potentially risky overloads of addConstraint function and make existing impl more exception safe
This commit is contained in:
parent
3a67760e4b
commit
9ad441dfbe
@ -91,42 +91,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
void addConstraint(const Constraint &constraint)
|
void addConstraint(const Constraint &constraint)
|
||||||
{
|
{
|
||||||
constraints.push_back(constraint.clone(allocFn, freeFn));
|
Constraint *newConstraint = constraint.clone(allocFn, freeFn);
|
||||||
|
try {
|
||||||
|
constraints.push_back(newConstraint);
|
||||||
|
} catch (...) {
|
||||||
|
newConstraint->~Constraint();
|
||||||
|
freeFn(newConstraint);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief move a constraint to this sub-schema
|
|
||||||
*
|
|
||||||
* The constraint will be added to the list of constraints for this
|
|
||||||
* Subschema.
|
|
||||||
*
|
|
||||||
* @param constraint pointer to the constraint to be added. Ownership
|
|
||||||
* assumed.
|
|
||||||
*/
|
|
||||||
void addConstraint(const Constraint *constraint)
|
|
||||||
{
|
|
||||||
constraints.push_back(constraint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#if _cplusplus >=201103L
|
|
||||||
#if 0
|
|
||||||
/**
|
|
||||||
* @brief Add a constraint to this sub-schema
|
|
||||||
*
|
|
||||||
* The constraint will be copied before being added to the list of
|
|
||||||
* constraints for this Subschema. Note that constraints will be copied
|
|
||||||
* only as deep as references to other Subschemas - e.g. copies of
|
|
||||||
* constraints that refer to sub-schemas, will continue to refer to the
|
|
||||||
* same Subschema instances.
|
|
||||||
*
|
|
||||||
* @param constraint Reference to the constraint to copy
|
|
||||||
*/
|
|
||||||
void addConstraint(std::unique_ptr<Constraint>constraint)
|
|
||||||
{
|
|
||||||
constraints.push_back(constraint.release());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Invoke a function on each child Constraint
|
* @brief Invoke a function on each child Constraint
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user