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 #if defined(__GNUC__) || defined(__clang__)
33 #define SDF_DEPRECATED(version) __attribute__((deprecated))
34 #define SDF_FORCEINLINE __attribute__((always_inline))
35 #elif defined(_MSC_VER)
36 #define SDF_DEPRECATED(version)
37 #define SDF_FORCEINLINE __forceinline
38 #else
39 #define SDF_DEPRECATED(version)
40 #define SDF_FORCEINLINE
41 #endif
42 
43 #if defined(__GNUC__)
44 # define SDF_SUPPRESS_DEPRECATED_BEGIN \
45  _Pragma("GCC diagnostic push") \
46  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
47 # define SDF_SUPPRESS_DEPRECATED_END _Pragma("GCC diagnostic pop")
48 #elif defined(__clang__)
49 # define SDF_SUPPRESS_DEPRECATED_BEGIN \
50  _Pragma("clang diagnostic push") \
51  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
52 # define SDF_SUPPRESS_DEPRECATED_END _Pragma("clang diagnostic pop")
53 #else
54 # define SDF_SUPPRESS_DEPRECATED_BEGIN
55 # define SDF_SUPPRESS_DEPRECATED_END
56 #endif
57 
58 namespace sdf
59 {
60  // Inline bracket to help doxygen filtering.
61  inline namespace SDF_VERSION_NAMESPACE {
62  //
63 
64  const std::string kSdfScopeDelimiter = "::";
65 
68  constexpr char kSdfStringSource[] = "<data-string>";
69 
72  constexpr char kUrdfStringSource[] = "<urdf-string>";
73 
79  std::vector<std::string> split(const std::string &_str,
80  const std::string &_splitter);
81 
86  std::string trim(const char *_in);
87 
92  std::string trim(const std::string &_in);
93 
98  template<typename T>
99  inline bool equal(const T &_a, const T &_b,
100  const T &_epsilon = 1e-6f)
101  {
102  return std::fabs(_a - _b) <= _epsilon;
103  }
104 
106  using Errors = std::vector<Error>;
107 
112  SDFORMAT_VISIBLE std::ostream &operator<<(
113  std::ostream &_out, const sdf::Errors &_errs);
114 
118  {
120  public: Time()
121  : sec(0), nsec(0)
122  {
123  }
124 
128  public: Time(int32_t _sec, int32_t _nsec)
129  : sec(_sec), nsec(_nsec)
130  {
131  }
132 
137  public: friend std::ostream &operator<<(std::ostream &_out,
138  const Time &_time)
139  {
140  _out << _time.sec << " " << _time.nsec;
141  return _out;
142  }
143 
148  public: friend std::istream &operator>>(std::istream &_in,
149  Time &_time)
150  {
151  // Skip white spaces
152  _in.setf(std::ios_base::skipws);
153  _in >> _time.sec >> _time.nsec;
154  return _in;
155  }
156 
160  public: bool operator ==(const Time &_time) const
161  {
162  return this->sec == _time.sec && this->nsec == _time.nsec;
163  }
164 
166  public: int32_t sec;
167 
169  public: int32_t nsec;
170  };
171 
174  {
175  public: double mass;
176  };
177 
181  std::string SDFORMAT_VISIBLE lowercase(const std::string &_in);
182 
188  std::pair<std::string, std::string> SplitName(
189  const std::string &_absoluteName);
190 
197  std::string JoinName(
198  const std::string &_scopeName, const std::string &_localName);
199  }
200 }
201 #endif
sdf::v12::Inertia
A class for inertial information about a link.
Definition: Types.hh:173
sdf::v12::split
std::vector< std::string > split(const std::string &_str, const std::string &_splitter)
Split a string using the delimiter in splitter.
Error.hh
sdf::v12::JoinName
std::string JoinName(const std::string &_scopeName, const std::string &_localName)
Join two strings with the '::' delimiter.
sdf::v12::Time::Time
Time()
Constructor.
Definition: Types.hh:120
sdf::v12::kSdfStringSource
constexpr char kSdfStringSource[]
The source path replacement if it was parsed from a string, instead of a file.
Definition: Types.hh:68
sdf
namespace for Simulation Description Format parser
Definition: Actor.hh:33
sdf::v12::trim
std::string trim(const char *_in)
Trim leading and trailing whitespace from a string.
sdf::v12::SplitName
std::pair< std::string, std::string > SplitName(const std::string &_absoluteName)
Split a name into a two strings based on the '::' delimeter.
sdf::v12::Errors
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:106
sdf::v12::kUrdfStringSource
constexpr char kUrdfStringSource[]
The source path replacement if the urdf was parsed from a string, instead of a file.
Definition: Types.hh:72
sdf::v12::kSdfScopeDelimiter
const std::string kSdfScopeDelimiter
Definition: Types.hh:64
SDFORMAT_VISIBLE
#define SDFORMAT_VISIBLE
Definition: system_util.hh:41
sdf::v12::Time::nsec
int32_t nsec
Nanoseconds.
Definition: Types.hh:169
sdf::v12::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:99
sdf::v12::Time
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:117
sdf::v12::Time::sec
int32_t sec
Seconds.
Definition: Types.hh:166
sdf::v12::lowercase
std::string lowercase(const std::string &_in)
Transforms a string to its lowercase equivalent.
sdf::v12::Time::operator>>
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Types.hh:148
sdf::v12::Time::Time
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition: Types.hh:128
sdf::v12::Time::operator<<
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Types.hh:137
sdf::v12::Inertia::mass
double mass
Definition: Types.hh:175
system_util.hh
sdf::v12::operator<<
std::ostream & operator<<(std::ostream &os, ParamStreamer< T > s)
Definition: Param.hh:83