Loading...
Searching...
No Matches
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
57namespace 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
#define SDF_DEPRECATED(version)
Definition Types.hh:38
Defines a color.
Definition Types.hh:93
float b
Blue value.
Definition Types.hh:145
float g
Green value.
Definition Types.hh:142
Color(float _r=0.0f, float _g=0.0f, float _b=0.0f, float _a=1.0f)
Constructor.
Definition Types.hh:100
float a
Alpha value.
Definition Types.hh:148
float r
Red value.
Definition Types.hh:139
A class for inertial information about a link.
Definition Types.hh:210
double mass
Definition Types.hh:211
A Time class, can be used to hold wall- or sim-time.
Definition Types.hh:154
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition Types.hh:173
Time()
Constructor.
Definition Types.hh:156
int32_t nsec
Nanoseconds.
Definition Types.hh:205
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition Types.hh:184
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition Types.hh:164
int32_t sec
Seconds.
Definition Types.hh:202
SDFORMAT_VISIBLE std::string trim(const char *_in)
Trim leading and trailing whitespace from a string.
std::vector< Error > Errors
A vector of Error.
Definition Types.hh:89
SDFORMAT_VISIBLE std::vector< std::string > split(const std::string &_str, const std::string &_splitter)
Split a string using the delimiter in splitter.
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
std::string SDFORMAT_VISIBLE lowercase(const std::string &_in)
Transforms a string to its lowercase equivalent.
namespace for Simulation Description Format parser
Definition Actor.hh:33
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition system_util.hh:48