-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathConverter.hh
168 lines (151 loc) · 7.34 KB
/
Converter.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Copyright 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _SDF_CONVERTER_HH_
#define _SDF_CONVERTER_HH_
#include <tinyxml2.h>
#include <string>
#include <tuple>
#include <sdf/config.hh>
#include <sdf/Types.hh>
#include "sdf/system_util.hh"
#include <sdf/ParserConfig.hh>
namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
/// \brief Convert from one version of SDF to another
class Converter
{
/// \brief Convert SDF to the specified version.
/// \param[out] _errors Vector of errors.
/// \param[in] _doc SDF xml doc
/// \param[in] _toVersion Version number in string format.
/// \param[in] _config Parser configuration.
/// \param[in] _quiet False to be more verbose.
public: static bool Convert(sdf::Errors &_errors,
tinyxml2::XMLDocument *_doc,
const std::string &_toVersion,
const ParserConfig &_config,
bool _quiet = false);
/// \cond
/// This is an internal function.
/// \brief Generic convert function that converts the SDF based on the
/// given Convert file.
/// \param[out] _errors Vector of errors.
/// \param[in] _doc SDF xml doc
/// \param[in] _convertDoc Convert xml doc
/// \param[in] _config Parser configuration.
public: static void Convert(sdf::Errors &_errors,
tinyxml2::XMLDocument *_doc,
tinyxml2::XMLDocument *_convertDoc,
const ParserConfig &_config);
/// \endcond
/// \brief Implementation of Convert functionality.
/// \param[in] _elem SDF xml element tree to convert.
/// \param[in] _convert Convert xml element tree.
/// \param[in] _config Parser configuration.
/// \param[out] _errors Vector of errors.
private: static void ConvertImpl(tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_convert,
const ParserConfig &_config,
sdf::Errors &_errors);
/// \brief Recursive helper function for ConvertImpl that converts
/// elements named by the descendant_name attribute.
/// \param[in] _e SDF xml element tree to convert.
/// \param[in] _c Convert xml element tree.
/// \param[in] _config Parser configuration.
/// \param[out] _errors Vector of errors.
private: static void ConvertDescendantsImpl(tinyxml2::XMLElement *_e,
tinyxml2::XMLElement *_c,
const ParserConfig &_config,
sdf::Errors &_errors);
/// \brief Rename an element or attribute.
/// \param[in] _elem The element to be renamed, or the element which
/// has the attribute to be renamed.
/// \param[in] _renameElem A 'convert' element that describes the rename.
/// \param[out] _errors Vector of errors.
/// operation.
private: static void Rename(tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_renameElem,
sdf::Errors &_errors);
/// \brief Map values from one element or attribute to another.
/// \param[in] _elem Ancestor element of the element or attribute to
/// be mapped.
/// \param[in] _mapElem A 'convert' element that describes the map
/// \param[out] _errors Vector of errors.
/// operation.
private: static void Map(tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_mapElem,
sdf::Errors &_errors);
/// \brief Move an element or attribute within a common ancestor element.
/// \param[in] _elem Ancestor element of the element or attribute to
/// be moved.
/// \param[in] _moveElem A 'convert' element that describes the move
/// operation.
/// \param[in] _copy True to copy the element
/// \param[out] _errors Vector of errors.
private: static void Move(tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_moveElem,
const bool _copy,
sdf::Errors &_errors);
/// \brief Add an element or attribute to an element.
/// \param[in] _elem The element to receive the value.
/// \param[in] _addElem A 'convert' element that describes the add
/// \param[out] _errors Vector of Errors.
/// operation.
private: static void Add(tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_addElem,
sdf::Errors &_errors);
/// \brief Remove an attribute or elements.
/// \param[out] _errors Vector of Errors.
/// \param[in] _elem The element from which data may be removed.
/// \param[in] _removeElem The metadata about what to remove.
/// \param[in] _removeOnlyEmpty If true, only remove an attribute
/// containing an empty string or elements that contain neither value nor
/// child elements nor attributes.
private: static void Remove(sdf::Errors &_errors,
tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_removeElem,
bool _removeOnlyEmpty = false);
/// \brief Unflatten an element (conversion from SDFormat <= 1.7 to 1.8)
/// \param[in] _elem The element to unflatten
/// \param[out] _errors Vector of errors
private: static void Unflatten(tinyxml2::XMLElement *_elem,
sdf::Errors &_errors);
/// \brief Finds all elements related to the unflattened model
/// \param[in] _elem The element to unflatten
/// \param[in] _newModel The new unflattened model element
/// \param[in] _childNameIdx The beginning index of child element names
/// \param[out] _errors Vector of errors
/// (e.g., in newModelName::childName then _childNameIdx = 14)
/// \return True if unflattened new model elements
private: static bool FindNewModelElements(tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_newModel,
const size_t &_childNameIdx,
sdf::Errors &_errors);
private: static const char *GetValue(const char *_valueElem,
const char *_valueAttr,
tinyxml2::XMLElement *_elem);
private: static void CheckDeprecation(tinyxml2::XMLElement *_elem,
tinyxml2::XMLElement *_convert,
const ParserConfig &_config,
sdf::Errors &_errors);
};
}
}
#endif