Types.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
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 SDFORMAT_TYPES_HH_
18 #define SDFORMAT_TYPES_HH_
19 
20 #include <algorithm>
21 #include <cmath>
22 #include <cstdint>
23 #include <sstream>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 #include <sdf/sdf_config.h>
29 #include "sdf/system_util.hh"
30 #include "sdf/Error.hh"
31 
32 namespace sdf
33 {
34  // Inline bracket to help doxygen filtering.
35  inline namespace SDF_VERSION_NAMESPACE {
36  //
37 
38  const std::string kSdfScopeDelimiter = "::";
39 
42  constexpr char kSdfStringSource[] = "<data-string>";
43 
46  constexpr char kUrdfStringSource[] = "<urdf-string>";
47 
53  std::vector<std::string> split(const std::string &_str,
54  const std::string &_splitter);
55 
60  std::string trim(const char *_in);
61 
66  std::string trim(const std::string &_in);
67 
72  template<typename T>
73  inline bool equal(const T &_a, const T &_b,
74  const T &_epsilon = 1e-6f)
75  {
76  return std::fabs(_a - _b) <= _epsilon;
77  }
78 
80  using Errors = std::vector<Error>;
81 
86  SDFORMAT_VISIBLE std::ostream &operator<<(
87  std::ostream &_out, const sdf::Errors &_errs);
88 
92  {
94  public: Time()
95  : sec(0), nsec(0)
96  {
97  }
98 
102  public: Time(int32_t _sec, int32_t _nsec)
103  : sec(_sec), nsec(_nsec)
104  {
105  }
106 
111  public: friend std::ostream &operator<<(std::ostream &_out,
112  const Time &_time)
113  {
114  _out << _time.sec << " " << _time.nsec;
115  return _out;
116  }
117 
122  public: friend std::istream &operator>>(std::istream &_in,
123  Time &_time)
124  {
125  // Skip white spaces
126  _in.setf(std::ios_base::skipws);
127  _in >> _time.sec >> _time.nsec;
128  return _in;
129  }
130 
134  public: bool operator ==(const Time &_time) const
135  {
136  return this->sec == _time.sec && this->nsec == _time.nsec;
137  }
138 
140  public: int32_t sec;
141 
143  public: int32_t nsec;
144  };
145 
147  class SDFORMAT_VISIBLE GZ_DEPRECATED(13) Inertia
148  {
149  public: double mass;
150  };
151 
155  std::string SDFORMAT_VISIBLE lowercase(const std::string &_in);
156 
162  std::pair<std::string, std::string> SplitName(
163  const std::string &_absoluteName);
164 
171  std::string JoinName(
172  const std::string &_scopeName, const std::string &_localName);
173  }
174 }
175 #endif
sdf::SDF_VERSION_NAMESPACE::GZ_DEPRECATED
class GZ_SDFORMAT_VISIBLE GZ_DEPRECATED(13) Inertia
A class for inertial information about a link.
Definition: Types.hh:147
sdf::SDF_VERSION_NAMESPACE::lowercase
std::string GZ_SDFORMAT_VISIBLE lowercase(const std::string &_in)
Transforms a string to its lowercase equivalent.
sdf::SDF_VERSION_NAMESPACE::Time::operator<<
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Types.hh:111
Error.hh
sdf::SDF_VERSION_NAMESPACE::trim
GZ_SDFORMAT_VISIBLE std::string trim(const char *_in)
Trim leading and trailing whitespace from a string.
sdf::SDF_VERSION_NAMESPACE::Time::Time
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition: Types.hh:102
sdf
namespace for Simulation Description Format parser
Definition: Actor.hh:34
sdf::SDF_VERSION_NAMESPACE::Time::nsec
int32_t nsec
Nanoseconds.
Definition: Types.hh:143
sdf::SDF_VERSION_NAMESPACE::SplitName
GZ_SDFORMAT_VISIBLE std::pair< std::string, std::string > SplitName(const std::string &_absoluteName)
Split a name into a two strings based on the '::' delimeter.
sdf::SDF_VERSION_NAMESPACE::Time::operator>>
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Types.hh:122
sdf_config.h
sdf::SDF_VERSION_NAMESPACE::Time
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:91
SDFORMAT_VISIBLE
#define SDFORMAT_VISIBLE
Definition: system_util.hh:25
sdf::SDF_VERSION_NAMESPACE::kSdfStringSource
constexpr char kSdfStringSource[]
The source path replacement if it was parsed from a string, instead of a file.
Definition: Types.hh:42
sdf::SDF_VERSION_NAMESPACE::operator<<
std::ostream & operator<<(std::ostream &os, ParamStreamer< T > s)
Definition: Param.hh:94
sdf::SDF_VERSION_NAMESPACE::Time::sec
int32_t sec
Seconds.
Definition: Types.hh:140
sdf::SDF_VERSION_NAMESPACE::equal
bool equal(const T &_a, const T &_b, const T &_epsilon=1e-6f)
check if two values are equal, within a tolerance
Definition: Types.hh:73
sdf::SDF_VERSION_NAMESPACE::Errors
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:80
sdf::SDF_VERSION_NAMESPACE::Time::Time
Time()
Constructor.
Definition: Types.hh:94
sdf::SDF_VERSION_NAMESPACE::kSdfScopeDelimiter
const std::string kSdfScopeDelimiter
Definition: Types.hh:38
system_util.hh
sdf::SDF_VERSION_NAMESPACE::kUrdfStringSource
constexpr char kUrdfStringSource[]
The source path replacement if the urdf was parsed from a string, instead of a file.
Definition: Types.hh:46
sdf::SDF_VERSION_NAMESPACE::JoinName
GZ_SDFORMAT_VISIBLE std::string JoinName(const std::string &_scopeName, const std::string &_localName)
Join two strings with the '::' delimiter.
sdf::SDF_VERSION_NAMESPACE::split
GZ_SDFORMAT_VISIBLE std::vector< std::string > split(const std::string &_str, const std::string &_splitter)
Split a string using the delimiter in splitter.