Skip to content

Commit ffea2ed

Browse files
authored
Merge branch 'sdf13' into scpeters/merge_12_to_13
2 parents f20edfd + a5be6ab commit ffea2ed

13 files changed

+522
-87
lines changed

include/sdf/Element.hh

+90-1
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,20 @@ namespace sdf
8383
/// \return A copy of this Element.
8484
public: ElementPtr Clone() const;
8585

86+
/// \brief Create a copy of this Element.
87+
/// \param[out] _errors Vector of errors.
88+
/// \return A copy of this Element, NULL if there was an error.
89+
public: ElementPtr Clone(sdf::Errors &_errors) const;
90+
8691
/// \brief Copy values from an Element.
8792
/// \param[in] _elem Element to copy value from.
8893
public: void Copy(const ElementPtr _elem);
8994

95+
/// \brief Copy values from an Element.
96+
/// \param[in] _elem Element to copy value from.
97+
/// \param[out] _errors Vector of errors.
98+
public: void Copy(const ElementPtr _elem, sdf::Errors &_errors);
99+
90100
/// \brief Get a pointer to this Element's parent.
91101
/// \return Pointer to this Element's parent, NULL if there is no
92102
/// parent.
@@ -220,6 +230,21 @@ namespace sdf
220230
bool _required,
221231
const std::string &_description = "");
222232

233+
/// \brief Add an attribute value.
234+
/// \param[in] _key Key value.
235+
/// \param[in] _type Type of data the attribute will hold.
236+
/// \param[in] _defaultValue Default value for the attribute.
237+
/// \param[in] _required Requirement string. \as Element::SetRequired.
238+
/// \param[out] _errors Vector of errors.
239+
/// \param[in] _description A text description of the attribute.
240+
/// \throws sdf::AssertionInternalError if an invalid type is given.
241+
public: void AddAttribute(const std::string &_key,
242+
const std::string &_type,
243+
const std::string &_defaultvalue,
244+
bool _required,
245+
sdf::Errors &_errors,
246+
const std::string &_description = "");
247+
223248
/// \brief Add a value to this Element.
224249
/// \param[in] _type Type of data the parameter will hold.
225250
/// \param[in] _defaultValue Default value for the parameter.
@@ -230,6 +255,18 @@ namespace sdf
230255
const std::string &_defaultValue, bool _required,
231256
const std::string &_description = "");
232257

258+
/// \brief Add a value to this Element.
259+
/// \param[in] _type Type of data the parameter will hold.
260+
/// \param[in] _defaultValue Default value for the parameter.
261+
/// \param[in] _required Requirement string. \as Element::SetRequired.
262+
/// \param[out] _errors Vector of errors.
263+
/// \param[in] _description A text description of the parameter.
264+
/// \throws sdf::AssertionInternalError if an invalid type is given.
265+
public: void AddValue(const std::string &_type,
266+
const std::string &_defaultValue, bool _required,
267+
sdf::Errors &_errors,
268+
const std::string &_description = "");
269+
233270
/// \brief Add a value to this Element. This override allows passing min and
234271
/// max values of the parameter.
235272
/// \param[in] _type Type of data the parameter will hold.
@@ -245,6 +282,23 @@ namespace sdf
245282
const std::string &_maxValue,
246283
const std::string &_description = "");
247284

285+
/// \brief Add a value to this Element. This override allows passing min and
286+
/// max values of the parameter.
287+
/// \param[in] _type Type of data the parameter will hold.
288+
/// \param[in] _defaultValue Default value for the parameter.
289+
/// \param[in] _required Requirement string. \as Element::SetRequired.
290+
/// \param[in] _minValue Minimum allowed value for the parameter.
291+
/// \param[in] _maxValue Maximum allowed value for the parameter.
292+
/// \param[out] _errors Vector of errors.
293+
/// \param[in] _description A text description of the parameter.
294+
/// \throws sdf::AssertionInternalError if an invalid type is given.
295+
public: void AddValue(const std::string &_type,
296+
const std::string &_defaultValue, bool _required,
297+
const std::string &_minValue,
298+
const std::string &_maxValue,
299+
sdf::Errors &_errors,
300+
const std::string &_description = "");
301+
248302
/// \brief Get the param of an attribute.
249303
/// \param[in] _key the name of the attribute.
250304
/// \return The parameter attribute value. NULL if the key is invalid.
@@ -309,6 +363,14 @@ namespace sdf
309363
/// \return The element as a std::any.
310364
public: std::any GetAny(const std::string &_key = "") const;
311365

366+
/// \brief Get the element value/attribute as a std::any.
367+
/// \param[in] _key The key of the attribute. If empty, get the value of
368+
/// the element. Defaults to empty.
369+
/// \param[out] _errors Vector of errors.
370+
/// \return The element as a std::any.
371+
public: std::any GetAny(sdf::Errors &_errors,
372+
const std::string &_key = "") const;
373+
312374
/// \brief Get the value of a key. This function assumes the _key
313375
/// exists.
314376
/// \param[in] _key the name of a child attribute or element.
@@ -431,6 +493,20 @@ namespace sdf
431493
/// element if an existing child element did not exist.
432494
public: ElementPtr GetElement(const std::string &_name);
433495

496+
/// \brief Return a pointer to the child element with the provided name.
497+
///
498+
/// A new child element, with the provided name, is added to this element
499+
/// if there is no existing child element. If this is not desired see \ref
500+
/// FindElement
501+
/// \remarks If there are multiple elements with the given tag, it returns
502+
/// the first one.
503+
/// \param[in] _name Name of the child element to retreive.
504+
/// \param[out] _errors Vector of errors.
505+
/// \return Pointer to the existing child element, or a new child
506+
/// element if an existing child element did not exist.
507+
public: ElementPtr GetElement(const std::string &_name,
508+
sdf::Errors &_errors);
509+
434510
/// \brief Return a pointer to the child element with the provided name.
435511
///
436512
/// Unlike \ref GetElement, this does not create a new child element if it
@@ -458,6 +534,13 @@ namespace sdf
458534
/// \return A pointer to the newly created Element object.
459535
public: ElementPtr AddElement(const std::string &_name);
460536

537+
/// \brief Add a named element.
538+
/// \param[in] _name the name of the element to add.
539+
/// \param[out] _errors Vector of errors.
540+
/// \return A pointer to the newly created Element object.
541+
public: ElementPtr AddElement(const std::string &_name,
542+
sdf::Errors &_errors);
543+
461544
/// \brief Add an element object.
462545
/// \param[in] _elem the element object to add.
463546
public: void InsertElement(ElementPtr _elem);
@@ -476,6 +559,11 @@ namespace sdf
476559
/// \param[in] _child Pointer to the child to remove.
477560
public: void RemoveChild(ElementPtr _child);
478561

562+
/// \brief Remove a child element.
563+
/// \param[in] _child Pointer to the child to remove.
564+
/// \param[out] _errors Vector of errors.
565+
public: void RemoveChild(ElementPtr _child, sdf::Errors &_errors);
566+
479567
/// \brief Remove all child elements.
480568
public: void ClearElements();
481569

@@ -602,15 +690,16 @@ namespace sdf
602690
/// int,...).
603691
/// \param[in] _defaultValue Default value.
604692
/// \param[in] _required True if the parameter is required to be set.
693+
/// \param[out] _errors Vector of errors.
605694
/// \param[in] _description Description of the parameter.
606695
/// \return A pointer to the new Param object.
607696
private: ParamPtr CreateParam(const std::string &_key,
608697
const std::string &_type,
609698
const std::string &_defaultValue,
610699
bool _required,
700+
sdf::Errors &_errors,
611701
const std::string &_description = "");
612702

613-
614703
/// \brief Private data pointer
615704
private: std::unique_ptr<ElementPrivate> dataPtr;
616705
};

include/sdf/Error.hh

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ namespace sdf
161161
/// \brief The specified parameter (values of SDFormat elements
162162
/// or attributes) type is unknown.
163163
UNKNOWN_PARAMETER_TYPE,
164+
165+
/// \brief Generic error to be thrown with SDF_ASSERT by the caller.
166+
/// This has been created to help preserve behavior.
167+
FATAL_ERROR,
168+
169+
/// \brief Generic warning saved as error due to WarningsPolicy config
170+
WARNING,
164171
};
165172

166173
class SDFORMAT_VISIBLE Error

include/sdf/Param.hh

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@ namespace sdf
307307

308308
/// \brief Set the parent Element of this Param.
309309
/// \param[in] _parentElement Pointer to new parent Element. A nullptr can
310-
/// provided to remove the current parent Element.
310+
/// be provided to remove the current parent Element.
311311
/// \return True if the parent Element was set and the value was reparsed
312312
/// successfully.
313313
public: bool SetParentElement(ElementPtr _parentElement);
314314

315315
/// \brief Set the parent Element of this Param.
316316
/// \param[in] _parentElement Pointer to new parent Element. A nullptr can
317-
/// provided to remove the current parent Element.
317+
/// be provided to remove the current parent Element.
318318
/// \param[out] _errors Vector of errors.
319319
/// \return True if the parent Element was set and the value was reparsed
320320
/// successfully.

include/sdf/PrintConfig.hh

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "sdf/sdf_config.h"
2424
#include "sdf/system_util.hh"
25+
#include "sdf/Types.hh"
2526

2627
namespace sdf
2728
{
@@ -54,6 +55,19 @@ namespace sdf
5455
public: bool SetRotationSnapToDegrees(unsigned int _interval,
5556
double _tolerance);
5657

58+
/// \brief Sets the option for printing pose rotation in degrees as well as
59+
/// snapping the rotation to the desired interval, with the provided
60+
/// tolerance.
61+
/// \param[in] _interval Degrees interval to snap to, this value must be
62+
/// larger than 0, and less than or equal to 360.
63+
/// \param[in] _tolerance Tolerance which snapping occurs, this value must
64+
/// be larger than 0, less than 360, and less than the provided interval.
65+
/// \param[out] _errors Vector of Errors.
66+
/// \return True, unless any of the provided values are not valid.
67+
public: bool SetRotationSnapToDegrees(unsigned int _interval,
68+
double _tolerance,
69+
sdf::Errors &_errors);
70+
5771
/// \brief Returns the current degree value that pose rotations will snap to
5872
/// when printed.
5973
/// \return The assigned degrees interval value to snap to. If it has not

0 commit comments

Comments
 (0)