SF2 C++ FRC Class Library
Sensor Fusion Framework (SF2) for FRC
Scalar.h
1 /* ============================================
2  SF2 source code is placed under the MIT license
3  Copyright (c) 2017 Kauai Labs
4 
5  Permission is hereby granted, free of charge, to any person obtaining a copy
6  of this software and associated documentation files (the "Software"), to deal
7  in the Software without restriction, including without limitation the rights
8  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  copies of the Software, and to permit persons to whom the Software is
10  furnished to do so, subject to the following conditions:
11 
12  The above copyright notice and this permission notice shall be included in
13  all copies or substantial portions of the Software.
14 
15  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  THE SOFTWARE.
22  ===============================================
23  */
24 
25 #ifndef SRC_QUANTITY_SCALAR_H_
26 #define SRC_QUANTITY_SCALAR_H_
27 
28 #include <forward_list>
29 using namespace std;
30 
31 #include "interpolation/IInterpolate.h"
32 #include "quantity/IQuantity.h"
33 #include "quantity/ICopy.h"
34 
35 class Scalar: public IInterpolate<Scalar>, public ICopy<Scalar>, public IQuantity {
36 
37  float value;
38 
39 public:
40  float get() {
41  return value;
42  }
43 
44  void set(float value) {
45  this->value = value;
46  }
47 
48  Scalar(float value) {
49  this->value = value;
50  }
51 
52  Scalar() {
53  value = 0;
54  }
55 
56  ~Scalar() {
57  }
58 
59  void copy(Scalar& t) {
60  set(t.get());
61  }
62 
63  Scalar *instantiate_copy() {
64  return new Scalar(this->value);
65  }
66 
67  /* time_ratio: interpolation ratio from 0.0 to 1.0. */
68  void interpolate(const Scalar& to, double time_ratio, Scalar& out) {
69  float delta = to.value - this->value;
70  float interpolated_value = this->value + delta;
71  out.set(interpolated_value);
72  }
73 
74  bool getPrintableString(vector<string>& printable_string) {
75  printable_string.push_back(std::to_string(value));
76  return true;
77  }
78 
79  bool getContainedQuantities(vector<IQuantity *>& quantities) {
80  return false;
81  }
82 
83  bool getContainedQuantityNames(vector<string>& quantity_names) {
84  return false;
85  }
86 };
87 
88 #endif /* SRC_QUANTITY_SCALAR_H_ */
Definition: ICopy.h:29
Definition: IQuantity.h:33
Definition: Scalar.h:35