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 <vector>
26 
27 #include <sdf/sdf_config.h>
28 #include "sdf/system_util.hh"
29 #include "sdf/Error.hh"
30 
31 #if defined(__GNUC__) || defined(__clang__)
32 #define SDF_DEPRECATED(version) __attribute__((deprecated))
33 #define SDF_FORCEINLINE __attribute__((always_inline))
34 #elif defined(_MSC_VER)
35 #define SDF_DEPRECATED(version)
36 #define SDF_FORCEINLINE __forceinline
37 #else
38 #define SDF_DEPRECATED(version)
39 #define SDF_FORCEINLINE
40 #endif
41 
42 #if defined(__GNUC__)
43 # define SDF_SUPPRESS_DEPRECATED_BEGIN \
44  _Pragma("GCC diagnostic push") \
45  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
46 # define SDF_SUPPRESS_DEPRECATED_END _Pragma("GCC diagnostic pop")
47 #elif defined(__clang__)
48 # define SDF_SUPPRESS_DEPRECATED_BEGIN \
49  _Pragma("clang diagnostic push") \
50  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
51 # define SDF_SUPPRESS_DEPRECATED_END _Pragma("clang diagnostic pop")
52 #else
53 # define SDF_SUPPRESS_DEPRECATED_BEGIN
54 # define SDF_SUPPRESS_DEPRECATED_END
55 #endif
56 
57 namespace sdf
58 {
59  // Inline bracket to help doxygen filtering.
60  inline namespace SDF_VERSION_NAMESPACE {
61  //
62 
68  std::vector<std::string> split(const std::string &_str,
69  const std::string &_splitter);
70 
75  std::string trim(const char *_in);
76 
81  template<typename T>
82  inline bool equal(const T &_a, const T &_b,
83  const T &_epsilon = 1e-6f)
84  {
85  return std::fabs(_a - _b) <= _epsilon;
86  }
87 
89  using Errors = std::vector<Error>;
90 
93  {
100  public: Color(float _r = 0.0f, float _g = 0.0f,
101  float _b = 0.0f, float _a = 1.0f) SDF_DEPRECATED(6.0)
102  : r(_r), g(_g), b(_b), a(_a)
103  {}
104 
109  public: friend std::ostream &operator<< (std::ostream &_out,
110  const Color &_pt)
111  {
112  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
113  return _out;
114  }
115 
119  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
120  {
121  // Skip white spaces
122  _in.setf(std::ios_base::skipws);
123  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
124  return _in;
125  }
126 
130  public: bool operator ==(const Color &_clr) const
131  {
132  return equal(this->r, _clr.r) &&
133  equal(this->g, _clr.g) &&
134  equal(this->b, _clr.b) &&
135  equal(this->a, _clr.a);
136  }
137 
139  public: float r;
140 
142  public: float g;
143 
145  public: float b;
146 
148  public: float a;
149  };
150 
154  {
156  public: Time()
157  : sec(0), nsec(0)
158  {
159  }
160 
164  public: Time(int32_t _sec, int32_t _nsec)
165  : sec(_sec), nsec(_nsec)
166  {
167  }
168 
173  public: friend std::ostream &operator<<(std::ostream &_out,
174  const Time &_time)
175  {
176  _out << _time.sec << " " << _time.nsec;
177  return _out;
178  }
179 
184  public: friend std::istream &operator>>(std::istream &_in,
185  Time &_time)
186  {
187  // Skip white spaces
188  _in.setf(std::ios_base::skipws);
189  _in >> _time.sec >> _time.nsec;
190  return _in;
191  }
192 
196  public: bool operator ==(const Time &_time) const
197  {
198  return this->sec == _time.sec && this->nsec == _time.nsec;
199  }
200 
202  public: int32_t sec;
203 
205  public: int32_t nsec;
206  };
207 
210  {
211  public: double mass;
212  };
213 
217  std::string SDFORMAT_VISIBLE lowercase(const std::string &_in);
218  }
219 }
220 #endif
sdf::v9::Time::Time
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition: Types.hh:164
sdf::v9::trim
SDFORMAT_VISIBLE std::string trim(const char *_in)
Trim leading and trailing whitespace from a string.
Error.hh
sdf::v9::Time::operator<<
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Types.hh:173
sdf::v9::Color::g
float g
Green value.
Definition: Types.hh:142
sdf
namespace for Simulation Description Format parser
Definition: Actor.hh:32
sdf::v9::operator<<
std::ostream & operator<<(std::ostream &os, ParamStreamer< T > s)
Definition: Param.hh:75
sdf::v9::Time::Time
Time()
Constructor.
Definition: Types.hh:156
sdf::v9::Color
Defines a color.
Definition: Types.hh:92
sdf::v9::lowercase
std::string SDFORMAT_VISIBLE lowercase(const std::string &_in)
Transforms a string to its lowercase equivalent.
sdf::v9::Inertia
A class for inertial information about a link.
Definition: Types.hh:209
sdf::v9::Inertia::mass
double mass
Definition: Types.hh:211
sdf::v9::Errors
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:89
sdf::v9::Time::operator>>
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Types.hh:184
SDFORMAT_VISIBLE
#define SDFORMAT_VISIBLE
Definition: system_util.hh:48
sdf::v9::Color::r
float r
Red value.
Definition: Types.hh:139
sdf::v9::SDF_DEPRECATED
class SDFORMAT_VISIBLE SDF_DEPRECATED(9.2) URDF2SDF
URDF to SDF converter.
Definition: parser_urdf.hh:40
sdf::v9::Time::sec
int32_t sec
Seconds.
Definition: Types.hh:202
sdf::v9::split
SDFORMAT_VISIBLE std::vector< std::string > split(const std::string &_str, const std::string &_splitter)
Split a string using the delimiter in splitter.
sdf::v9::Color::Color
Color(float _r=0.0f, float _g=0.0f, float _b=0.0f, float _a=1.0f)
Constructor.
Definition: Types.hh:100
sdf::v9::Time::nsec
int32_t nsec
Nanoseconds.
Definition: Types.hh:205
sdf::v9::Color::a
float a
Alpha value.
Definition: Types.hh:148
sdf::v9::Color::b
float b
Blue value.
Definition: Types.hh:145
system_util.hh
sdf::v9::Time
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:153
sdf::v9::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:82