RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_FixedPoint.h
浏览该文件的文档.
1
11#ifndef VRPN_FIXED_POINT_H_
12#define VRPN_FIXED_POINT_H_
13
14// Internal Includes
15#include "vrpn_Types.h"
16
17// Library/third-party includes
18// - none
19
20// Standard includes
21#include <cstddef> // for NULL
22
23namespace vrpn {
24
25 namespace detail {
31 struct IntegerOverflow;
32
45 template <int NUM_BITS> struct IntegerOfSize {
46 // An integer requiring n bits can be represented by an integer of
47 // size n+1 bits.
48 typedef typename IntegerOfSize<NUM_BITS + 1>::type type;
49 };
50
51 template <> struct IntegerOfSize<8> {
52 typedef vrpn_int8 type;
53 };
54
55 template <> struct IntegerOfSize<16> {
56 typedef vrpn_int16 type;
57 };
58
59 template <> struct IntegerOfSize<32> {
60 typedef vrpn_int32 type;
61 };
62
63 template <> struct IntegerOfSize<64> {
64 typedef IntegerOfSize type;
65 };
66 template <int NUM_BITS> struct UnsignedIntegerOfSize {
67 // An integer requiring n bits can be represented by an integer of
68 // size n+1 bits.
69 typedef typename UnsignedIntegerOfSize<NUM_BITS + 1>::type type;
70 };
71
72 template <> struct UnsignedIntegerOfSize<8> {
73 typedef vrpn_uint8 type;
74 };
75
76 template <> struct UnsignedIntegerOfSize<16> {
77 typedef vrpn_uint16 type;
78 };
79
80 template <> struct UnsignedIntegerOfSize<32> {
81 typedef vrpn_uint32 type;
82 };
83
86
88 template <int BITS, bool SIGNED = true>
91 template <int BITS>
92 struct IntegerOfSizeAndSignedness<BITS, false>
93 : UnsignedIntegerOfSize<BITS> {
94 };
95 } // namespace detail
96
105 template <int INTEGER_BITS, int FRACTIONAL_BITS, bool SIGNED = true>
107 public:
111 typedef typename detail::IntegerOfSizeAndSignedness<
112 INTEGER_BITS, SIGNED>::type IntegerType;
113
114 typedef typename detail::IntegerOfSizeAndSignedness<
115 INTEGER_BITS + FRACTIONAL_BITS, SIGNED>::type RawType;
116
125 FixedPoint()
126 : value_(0)
127 {
128 }
129 explicit FixedPoint(
130 typename detail::IntegerOfSizeAndSignedness<8, SIGNED>::type x)
131 : value_(x)
132 {
133 }
134 explicit FixedPoint(
135 typename detail::IntegerOfSizeAndSignedness<16, SIGNED>::type x)
136 : value_(x)
137 {
138 }
139 explicit FixedPoint(
140 typename detail::IntegerOfSizeAndSignedness<32, SIGNED>::type x)
141 : value_(x)
142 {
143 }
144 explicit FixedPoint(double x)
145 : value_(x * (1 << FRACTIONAL_BITS))
146 {
147 }
148 explicit FixedPoint(float x)
149 : value_(x * (1 << FRACTIONAL_BITS))
150 {
151 }
153
155
160 template <typename T> T get() const
161 {
162 return get(reinterpret_cast<TypeWrapper<T> *>(NULL));
163 }
164
168 RawType value() const { return value_; }
170
171 private:
172 template <typename T> struct TypeWrapper;
173 vrpn_float32 get(TypeWrapper<vrpn_float32> *) const
174 {
175 return static_cast<vrpn_float32>(value_) / (1 << FRACTIONAL_BITS);
176 }
177
178 vrpn_float64 get(TypeWrapper<vrpn_float64> *) const
179 {
180 return static_cast<vrpn_float64>(value_) / (1 << FRACTIONAL_BITS);
181 }
182
183 RawType value_;
184 };
185
186} // namespace vrpn
187
188#endif // VRPN_FIXED_POINT_H_
定义 vrpn_FixedPoint.h:106
detail::IntegerOfSizeAndSignedness< INTEGER_BITS, SIGNED >::type IntegerType
定义 vrpn_FixedPoint.h:112
RawType value() const
定义 vrpn_FixedPoint.h:168
T get() const
定义 vrpn_FixedPoint.h:160
Namespace enclosing internal implementation details
定义 vrpn_ConnectionPtr.h:225
定义 vrpn_FixedPoint.h:89
定义 vrpn_FixedPoint.h:45
定义 vrpn_FixedPoint.h:66