SDFImpl.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef SDFIMPL_HH_
18 #define SDFIMPL_HH_
19 
20 #include <functional>
21 #include <memory>
22 #include <string>
23 
24 #include "sdf/Element.hh"
25 #include "sdf/Param.hh"
26 #include "sdf/ParserConfig.hh"
27 #include "sdf/PrintConfig.hh"
28 #include "sdf/Types.hh"
29 #include "sdf/sdf_config.h"
30 #include "sdf/system_util.hh"
31 
32 #ifdef _WIN32
33 // Disable warning C4251 which is triggered by
34 // std::unique_ptr
35 #pragma warning(push)
36 #pragma warning(disable: 4251)
37 #endif
38 
41 namespace sdf
42 {
43  // Inline bracket to help doxygen filtering.
44  inline namespace SDF_VERSION_NAMESPACE {
45  //
46 
47  class SDFORMAT_VISIBLE SDF;
48  class SDFPrivate;
49 
52  typedef std::shared_ptr<SDF> SDFPtr;
53 
56 
79  std::string findFile(const std::string &_filename,
80  bool _searchLocalPath = true,
81  bool _useCallback = false);
82 
106  std::string findFile(sdf::Errors &_errors,
107  const std::string &_filename,
108  bool _searchLocalPath = true,
109  bool _useCallback = false);
110 
125  std::string findFile(const std::string &_filename,
126  bool _searchLocalPath,
127  bool _useCallback,
128  const ParserConfig &_config);
129 
145  std::string findFile(sdf::Errors &_errors,
146  const std::string &_filename,
147  bool _searchLocalPath,
148  bool _useCallback,
149  const ParserConfig &_config);
150 
156  void addURIPath(const std::string &_uri, const std::string &_path);
157 
163  void setFindCallback(std::function<std::string (const std::string &)> _cb);
164 
167  {
168  public: SDF();
170  public: ~SDF();
171  public: void PrintDescription();
172  public: void PrintDescription(sdf::Errors &_errors);
173  public: void PrintDoc();
174  public: void Write(const std::string &_filename);
175  public: void Write(sdf::Errors &_errors, const std::string &_filename);
176 
179  public: void PrintValues(const PrintConfig &_config = PrintConfig());
180 
184  public: void PrintValues(sdf::Errors &_errors,
185  const PrintConfig &_config = PrintConfig());
186 
190  public: std::string ToString(
191  const PrintConfig &_config = PrintConfig()) const;
192 
197  public: std::string ToString(
198  sdf::Errors &_errors,
199  const PrintConfig &_config = PrintConfig()) const;
200 
203  public: void SetFromString(const std::string &_sdfData);
204 
208  public: void SetFromString(sdf::Errors &_Errors,
209  const std::string &_sdfData);
210 
212  public: void Clear();
213 
216  public: ElementPtr Root() const;
217 
220  public: void SetRoot(const ElementPtr _root);
221 
225  public: GZ_DEPRECATED(13) void Root(const ElementPtr _root);
226 
229  public: std::string FilePath() const;
230 
233  public: void SetFilePath(const std::string &_path);
234 
237  public: void SetOriginalVersion(const std::string &_version);
238 
241  public: const std::string &OriginalVersion() const;
242 
245  public: static std::string Version();
246 
249  public: static void Version(const std::string &_version);
250 
254  public: static ElementPtr WrapInRoot(const ElementPtr &_sdf);
255 
260  public: static ElementPtr WrapInRoot(sdf::Errors &_errors,
261  const ElementPtr &_sdf);
262 
276  public: static const std::string &EmbeddedSpec(
277  const std::string &_filename, const bool _quiet);
278 
292  public: static const std::string &EmbeddedSpec(
293  sdf::Errors &_errors, const std::string &_filename);
294 
297  private: std::unique_ptr<SDFPrivate> dataPtr;
298 
301  private: static std::string version;
302  };
304  }
305 }
306 
307 #ifdef _WIN32
308 #pragma warning(pop)
309 #endif
310 
311 #endif
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:100
This class contains configuration options for printing elements.
Definition: PrintConfig.hh:33
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:58
Base SDF class.
Definition: SDFImpl.hh:167
void Write(const std::string &_filename)
std::string ToString(sdf::Errors &_errors, const PrintConfig &_config=PrintConfig()) const
Convert the SDF values to a string representation.
void SetFromString(sdf::Errors &_Errors, const std::string &_sdfData)
Set SDF values from a string.
void PrintValues(sdf::Errors &_errors, const PrintConfig &_config=PrintConfig())
Output SDF's values to stdout.
void PrintValues(const PrintConfig &_config=PrintConfig())
Output SDF's values to stdout.
void SetRoot(const ElementPtr _root)
Set the root pointer.
void Write(sdf::Errors &_errors, const std::string &_filename)
ElementPtr Root() const
Get a pointer to the root element.
void PrintDescription(sdf::Errors &_errors)
void SetFromString(const std::string &_sdfData)
Set SDF values from a string.
void Clear()
Clear the data in this object.
GZ_DEPRECATED(13) void Root(const ElementPtr _root)
Set the root pointer.
std::string ToString(const PrintConfig &_config=PrintConfig()) const
Convert the SDF values to a string representation.
GZ_SDFORMAT_VISIBLE void setFindCallback(std::function< std::string(const std::string &)> _cb)
Set the callback to use when SDF can't find a file.
GZ_SDFORMAT_VISIBLE std::string findFile(const std::string &_filename, bool _searchLocalPath=true, bool _useCallback=false)
Find the absolute path of a file.
GZ_SDFORMAT_VISIBLE void addURIPath(const std::string &_uri, const std::string &_path)
Associate paths to a URI.
std::shared_ptr< SDF > SDFPtr
Definition: SDFImpl.hh:52
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:95
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:55
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25