xml_manipulation.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2022, Bielefeld University, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Bielefeld University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Robert Haschke */
36 
38 
39 namespace moveit_setup_assistant
40 {
41 namespace
42 {
43 bool hasRequiredAttributes(const TiXmlElement& e, const std::vector<Attribute>& attributes)
44 {
45  for (const auto& attr : attributes)
46  {
47  if (!attr.required)
48  continue; // attribute not required
49  const char* value = e.Attribute(attr.name);
50  if (value && strcmp(attr.value, value) == 0)
51  continue; // attribute has required value
52  else
53  return false;
54  }
55  return true;
56 };
57 } // namespace
58 
59 TiXmlElement* uniqueInsert(TiXmlElement& element, const char* tag, const std::vector<Attribute>& attributes,
60  const char* text)
61 {
62  // search for existing element with required tag name and attributes
63  TiXmlElement* result = element.FirstChildElement(tag);
64  while (result && !hasRequiredAttributes(*result, attributes))
65  result = result->NextSiblingElement(tag);
66 
67  if (!result) // if not yet present, create new element
68  result = element.InsertEndChild(TiXmlElement(tag))->ToElement();
69 
70  // set (not-yet existing) attributes
71  for (const auto& attr : attributes)
72  {
73  if (!result->Attribute(attr.name))
74  result->SetAttribute(attr.name, attr.value);
75  }
76 
77  // insert text if required
78  if (text && !result->GetText())
79  result->InsertEndChild(TiXmlText(text));
80 
81  return result;
82 }
83 
84 } // namespace moveit_setup_assistant
xml_manipulation.h
moveit_setup_assistant::uniqueInsert
TiXmlElement * uniqueInsert(TiXmlElement &element, const char *tag, const std::vector< Attribute > &attributes={}, const char *text=nullptr)
Definition: xml_manipulation.cpp:91
value
float value
moveit_setup_assistant
Definition: compute_default_collisions.h:46
attr
attr


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Sat May 3 2025 02:28:05