Sleeping Wombat Common Library  0.50.0
swCommonLibrary
DefaultInterpolators.h
Go to the documentation of this file.
1 #pragma once
2 
9 #include "IInterpolator.h"
11 
12 #include <string>
13 
14 
16 namespace DefaultInterpolators
17 {
18 
25  template< typename KeyType >
27  {
28  const static bool value = false;
29  };
30 
31 
32 
33  template< typename KeyType >
34  UPtr< IInterpolator< KeyType > > CreateLinear ( const Key< KeyType >& leftKey,
35  const Key< KeyType >& rightKey,
36  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
37  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
38 
39  template< typename KeyType >
40  UPtr< IInterpolator< KeyType > > CreateDiscrete ( const Key< KeyType >& leftKey,
41  const Key< KeyType >& rightKey,
42  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
43  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
44 
45  template< typename KeyType >
46  UPtr< IInterpolator< KeyType > > CreateCosinus ( const Key< KeyType >& leftKey,
47  const Key< KeyType >& rightKey,
48  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
49  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
50 
51 
52  template< typename KeyType >
53  UPtr< IInterpolator< KeyType > > Create ( InterpolatorType type,
54  const Key< KeyType >& leftKey,
55  const Key< KeyType >& rightKey,
56  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
57  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
58 
59 
60 
65  template< typename KeyType >
67  Create ( const Key< KeyType >& leftKey,
68  const Key< KeyType >& rightKey,
69  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
70  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
71 
72  template< typename KeyType >
74  Create ( const Key< KeyType >& leftKey,
75  const Key< KeyType >& rightKey,
76  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
77  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
78 
79  template<>
81  Create ( const Key< bool >& leftKey,
82  const Key< bool >& rightKey,
83  UPtr< const IInterpolator< bool > >& leftInterpolator,
84  UPtr< const IInterpolator< bool > >& rightInterpolator );
85 
86  template< typename KeyType >
88  Create ( const Key< KeyType >& leftKey,
89  const Key< KeyType >& rightKey,
90  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
91  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
92 
93  template< typename KeyType >
95  Create ( const Key< KeyType >& leftKey,
96  const Key< KeyType >& rightKey,
97  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
98  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
99 
100  template< typename KeyType >
102  Create ( const Key< KeyType >& leftKey,
103  const Key< KeyType >& rightKey,
104  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
105  UPtr< const IInterpolator< KeyType > >& rightInterpolator );
106 
107 //====================================================================================//
108 // Specialization declarations
109 //====================================================================================//
110 
111 #define DECLARE_SPECIALIZATON( type, Function ) \
112 template \
113 UPtr< IInterpolator< type > > Function< type >( const Key< type >& leftKey, \
114  const Key< type >& rightKey, \
115  UPtr< const IInterpolator< type > >& leftInterpolator, \
116  UPtr< const IInterpolator< type > >& rightInterpolator );
117 
118 DECLARE_SPECIALIZATON( float, CreateLinear );
119 DECLARE_SPECIALIZATON( double, CreateLinear );
120 DECLARE_SPECIALIZATON( char, CreateLinear );
121 DECLARE_SPECIALIZATON( uint8, CreateLinear );
122 DECLARE_SPECIALIZATON( int8, CreateLinear );
123 DECLARE_SPECIALIZATON( uint16, CreateLinear );
124 DECLARE_SPECIALIZATON( int16, CreateLinear );
125 DECLARE_SPECIALIZATON( uint32, CreateLinear );
126 DECLARE_SPECIALIZATON( int32, CreateLinear );
127 DECLARE_SPECIALIZATON( uint64, CreateLinear );
128 DECLARE_SPECIALIZATON( int64, CreateLinear );
129 
130 DECLARE_SPECIALIZATON( float, CreateDiscrete );
131 DECLARE_SPECIALIZATON( double, CreateDiscrete );
132 DECLARE_SPECIALIZATON( char, CreateDiscrete );
133 DECLARE_SPECIALIZATON( uint8, CreateDiscrete );
134 DECLARE_SPECIALIZATON( int8, CreateDiscrete );
135 DECLARE_SPECIALIZATON( uint16, CreateDiscrete );
136 DECLARE_SPECIALIZATON( int16, CreateDiscrete );
137 DECLARE_SPECIALIZATON( uint32, CreateDiscrete );
138 DECLARE_SPECIALIZATON( int32, CreateDiscrete );
139 DECLARE_SPECIALIZATON( uint64, CreateDiscrete );
140 DECLARE_SPECIALIZATON( int64, CreateDiscrete );
141 DECLARE_SPECIALIZATON( bool, CreateDiscrete );
142 DECLARE_SPECIALIZATON( std::wstring, CreateDiscrete );
143 DECLARE_SPECIALIZATON( std::string, CreateDiscrete );
144 
145 DECLARE_SPECIALIZATON( float, CreateCosinus );
146 DECLARE_SPECIALIZATON( double, CreateCosinus );
147 DECLARE_SPECIALIZATON( char, CreateCosinus );
148 DECLARE_SPECIALIZATON( uint8, CreateCosinus );
149 DECLARE_SPECIALIZATON( int8, CreateCosinus );
150 DECLARE_SPECIALIZATON( uint16, CreateCosinus );
151 DECLARE_SPECIALIZATON( int16, CreateCosinus );
152 DECLARE_SPECIALIZATON( uint32, CreateCosinus );
153 DECLARE_SPECIALIZATON( int32, CreateCosinus );
154 DECLARE_SPECIALIZATON( uint64, CreateCosinus );
155 DECLARE_SPECIALIZATON( int64, CreateCosinus );
156 
157 #undef DECLARE_SPECIALIZATON
158 
159 //====================================================================================//
160 // Implementation
161 //====================================================================================//
162 
163 // ================================ //
164 //
165 template< typename KeyType >
166 UPtr< IInterpolator< KeyType > > Create ( InterpolatorType type,
167  const Key< KeyType >& leftKey,
168  const Key< KeyType >& rightKey,
169  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
170  UPtr< const IInterpolator< KeyType > >& rightInterpolator )
171 {
172  switch( type )
173  {
174  case InterpolatorType::Discrete:
175  return CreateDiscrete< KeyType >( leftKey, rightKey, leftInterpolator, rightInterpolator );
176  case InterpolatorType::Linear:
177  return CreateLinear< KeyType >( leftKey, rightKey, leftInterpolator, rightInterpolator );
178  case InterpolatorType::Cosinus:
179  return CreateCosinus< KeyType >( leftKey, rightKey, leftInterpolator, rightInterpolator );
180  case InterpolatorType::Bezier:
182  return DummyInterpolator< KeyType >( leftKey, rightKey, leftInterpolator, rightInterpolator );
183  default:
184  return DummyInterpolator< KeyType >( leftKey, rightKey, leftInterpolator, rightInterpolator );
185  }
186 }
187 
188 // ================================ //
189 //
190 template< typename KeyType >
192  Create ( const Key< KeyType >& leftKey,
193  const Key<KeyType>& rightKey,
194  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
195  UPtr< const IInterpolator< KeyType > >& rightInterpolator )
196 {
197  return CreateLinear( leftKey, rightKey, leftInterpolator, rightInterpolator );
198 }
199 
200 
201 // ================================ //
202 //
203 template< typename KeyType >
205  Create ( const Key< KeyType >& leftKey,
206  const Key< KeyType >& rightKey,
207  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
208  UPtr< const IInterpolator< KeyType > >& rightInterpolator )
209 {
210  return CreateLinear( leftKey, rightKey, leftInterpolator, rightInterpolator );
211 }
212 
213 
214 // ================================ //
215 //
216 template<>
218  Create ( const Key< bool >& leftKey,
219  const Key< bool >& rightKey,
220  UPtr< const IInterpolator< bool > >& leftInterpolator,
221  UPtr< const IInterpolator< bool > >& rightInterpolator )
222 {
223  return CreateDiscrete( leftKey, rightKey, leftInterpolator, rightInterpolator );
224 }
225 
226 // ================================ //
227 //
228 template< typename KeyType >
230  Create ( const Key< KeyType >& leftKey,
231  const Key<KeyType>& rightKey,
232  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
233  UPtr< const IInterpolator< KeyType > >& rightInterpolator )
234 {
235  return CreateDiscrete( leftKey, rightKey, leftInterpolator, rightInterpolator );
236 }
237 
238 // ================================ //
239 //
240 template< typename KeyType >
242  Create ( const Key< KeyType >& leftKey,
243  const Key<KeyType>& rightKey,
244  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
245  UPtr< const IInterpolator< KeyType > >& rightInterpolator )
246 {
247  return CreateDiscrete( leftKey, rightKey, leftInterpolator, rightInterpolator );
248 }
249 
250 // ================================ //
251 //
252 template< typename KeyType >
254  Create ( const Key< KeyType >& leftKey,
255  const Key< KeyType >& rightKey,
256  UPtr< const IInterpolator< KeyType > >& leftInterpolator,
257  UPtr< const IInterpolator< KeyType > >& rightInterpolator )
258 {
259  return CreateLinear( leftKey, rightKey, leftInterpolator, rightInterpolator );
260 }
261 
262 
263 
264 } // DefaultInterpolators
Interpolators helpers functions.
Definition: DefaultInterpolators.cpp:14
Base class for interpolators.
Definition: IInterpolator.h:38
Definition: UPtr.h:10
Animation key.
Definition: IInterpolator.h:21
UPtr< IInterpolator< KeyType > > Create(InterpolatorType type, const Key< KeyType > &leftKey, const Key< KeyType > &rightKey, UPtr< const IInterpolator< KeyType > > &leftInterpolator, UPtr< const IInterpolator< KeyType > > &rightInterpolator)
Definition: DefaultInterpolators.h:166
Trait for enabling types for parameter animation.
Definition: DefaultInterpolators.h:26
Temporary interpolator for internal use.
Definition: IInterpolator.h:67