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/system_util.hh"
28#include "sdf/Error.hh"
29
30#if defined(__GNUC__)
31#define SDF_DEPRECATED(version) __attribute__((deprecated))
32#define SDF_FORCEINLINE __attribute__((always_inline))
33#elif defined(MSVC)
34#define SDF_DEPRECATED(version)
35#define SDF_FORCEINLINE __forceinline
36#else
37#define SDF_DEPRECATED(version)
38#define SDF_FORCEINLINE
39#endif
40
41namespace sdf
42{
48 std::vector<std::string> split(const std::string &_str,
49 const std::string &_splitter);
50
55 std::string trim(const char *_in);
56
61 template<typename T>
62 inline bool equal(const T &_a, const T &_b,
63 const T &_epsilon = 1e-6f)
64 {
65 return std::fabs(_a - _b) <= _epsilon;
66 }
67
69 using Errors = std::vector<Error>;
70
73 {
80 public: Color(float _r = 0.0f, float _g = 0.0f,
81 float _b = 0.0f, float _a = 1.0f) SDF_DEPRECATED(6.0)
82 : r(_r), g(_g), b(_b), a(_a)
83 {}
84
89 public: friend std::ostream &operator<< (std::ostream &_out,
90 const Color &_pt)
91 {
92 _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
93 return _out;
94 }
95
99 public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
100 {
101 // Skip white spaces
102 _in.setf(std::ios_base::skipws);
103 _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
104 return _in;
105 }
106
110 public: bool operator ==(const Color &_clr) const
111 {
112 return equal(this->r, _clr.r) &&
113 equal(this->g, _clr.g) &&
114 equal(this->b, _clr.b) &&
115 equal(this->a, _clr.a);
116 }
117
119 public: float r;
120
122 public: float g;
123
125 public: float b;
126
128 public: float a;
129 };
130
134 {
136 public: Time()
137 : sec(0), nsec(0)
138 {
139 }
140
144 public: Time(int32_t _sec, int32_t _nsec)
145 : sec(_sec), nsec(_nsec)
146 {
147 }
148
153 public: friend std::ostream &operator<<(std::ostream &_out,
154 const Time &_time)
155 {
156 _out << _time.sec << " " << _time.nsec;
157 return _out;
158 }
159
164 public: friend std::istream &operator>>(std::istream &_in,
165 Time &_time)
166 {
167 // Skip white spaces
168 _in.setf(std::ios_base::skipws);
169 _in >> _time.sec >> _time.nsec;
170 return _in;
171 }
172
176 public: bool operator ==(const Time &_time) const
177 {
178 return this->sec == _time.sec && this->nsec == _time.nsec;
179 }
180
182 public: int32_t sec;
183
185 public: int32_t nsec;
186 };
187
190 {
191 public: double mass;
192 };
193}
194#endif
#define SDF_DEPRECATED(version)
Definition Types.hh:37
float g
Green value.
Definition Types.hh:122
float a
Alpha value.
Definition Types.hh:128
float b
Blue value.
Definition Types.hh:125
Color(float _r=0.0f, float _g=0.0f, float _b=0.0f, float _a=1.0f)
Constructor.
Definition Types.hh:80
float r
Red value.
Definition Types.hh:119
A class for inertial information about a link.
Definition Types.hh:190
double mass
Definition Types.hh:191
int32_t nsec
Nanoseconds.
Definition Types.hh:185
int32_t sec
Seconds.
Definition Types.hh:182
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition Types.hh:153
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition Types.hh:144
Time()
Constructor.
Definition Types.hh:136
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition Types.hh:164
namespace for Simulation Description Format parser
Definition Console.hh:36
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:62
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:69
SDFORMAT_VISIBLE std::vector< std::string > split(const std::string &_str, const std::string &_splitter)
Split a string using the delimiter in splitter.
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition system_util.hh:48