All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
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 
18 #ifndef _SDF_TYPES_HH_
19 #define _SDF_TYPES_HH_
20 
21 #include <algorithm>
22 #include <cmath>
23 #include <cstdint>
24 #include <sstream>
25 #include <vector>
26 
27 #include "sdf/system_util.hh"
28 
29 #if defined(__GNUC__)
30 #define SDF_DEPRECATED(version) __attribute__((deprecated))
31 #define SDF_FORCEINLINE __attribute__((always_inline))
32 #elif defined(MSVC)
33 #define SDF_DEPRECATED(version)
34 #define SDF_FORCEINLINE __forceinline
35 #else
36 #define SDF_DEPRECATED(version)
37 #define SDF_FORCEINLINE
38 #endif
39 
40 namespace sdf
41 {
47  const char *winGetEnv(const char *_name);
48 
53  template<typename T>
54  inline bool equal(const T &_a, const T &_b,
55  const T &_epsilon = 1e-6f)
56  {
57  return std::fabs(_a - _b) <= _epsilon;
58  }
59 
62  {
68  public: Color(float _r = 0.0f, float _g = 0.0f,
69  float _b = 0.0f, float _a = 1.0f)
70  : r(_r), g(_g), b(_b), a(_a) {}
71 
76  public: friend std::ostream &operator<< (std::ostream &_out,
77  const Color &_pt)
78  {
79  _out << _pt.r << " " << _pt.g << " " << _pt.b << " " << _pt.a;
80  return _out;
81  }
82 
86  public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
87  {
88  // Skip white spaces
89  _in.setf(std::ios_base::skipws);
90  _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
91  return _in;
92  }
93 
97  public: bool operator ==(const Color &_clr) const
98  {
99  return equal(this->r, _clr.r) &&
100  equal(this->g, _clr.g) &&
101  equal(this->b, _clr.b) &&
102  equal(this->a, _clr.a);
103  }
104 
106  public: float r;
107 
109  public: float g;
110 
112  public: float b;
113 
115  public: float a;
116  };
117 
121  {
123  public: Time()
124  : sec(0), nsec(0)
125  {
126  }
127 
131  public: Time(int32_t _sec, int32_t _nsec)
132  : sec(_sec), nsec(_nsec)
133  {
134  }
135 
140  public: friend std::ostream &operator<<(std::ostream &_out,
141  const Time &_time)
142  {
143  _out << _time.sec << " " << _time.nsec;
144  return _out;
145  }
146 
151  public: friend std::istream &operator>>(std::istream &_in,
152  Time &_time)
153  {
154  // Skip white spaces
155  _in.setf(std::ios_base::skipws);
156  _in >> _time.sec >> _time.nsec;
157  return _in;
158  }
159 
163  public: bool operator ==(const Time &_time) const
164  {
165  return this->sec == _time.sec && this->nsec == _time.nsec;
166  }
167 
169  public: int32_t sec;
170 
172  public: int32_t nsec;
173  };
174 
177  {
178  public: double mass;
179  };
180 }
181 #endif
float b
Blue value.
Definition: Types.hh:112
int32_t sec
Seconds.
Definition: Types.hh:169
double mass
Definition: Types.hh:178
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48
Time()
Constructor.
Definition: Types.hh:123
SDFORMAT_VISIBLE const char * winGetEnv(const char *_name)
Windows equivalent of getEnv.
Time(int32_t _sec, int32_t _nsec)
Constructor.
Definition: Types.hh:131
Defines a color.
Definition: Types.hh:61
float r
Red value.
Definition: Types.hh:106
A class for inertial information about a link.
Definition: Types.hh:176
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:120
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Types.hh:140
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Types.hh:151
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:54
Color(float _r=0.0f, float _g=0.0f, float _b=0.0f, float _a=1.0f)
Constructor.
Definition: Types.hh:68
float g
Green value.
Definition: Types.hh:109
float a
Alpha value.
Definition: Types.hh:115
int32_t nsec
Nanoseconds.
Definition: Types.hh:172