PX4 Firmware
PX4 Autopilot Software http://px4.io
Scalar.hpp
Go to the documentation of this file.
1 /**
2  * @file Scalar.hpp
3  *
4  * Defines conversion of matrix to scalar.
5  *
6  * @author James Goppert <james.goppert@gmail.com>
7  */
8 
9 #pragma once
10 
11 #include "math.hpp"
12 
13 namespace matrix
14 {
15 
16 template<typename Type>
17 class Scalar
18 {
19 public:
20  Scalar() = delete;
21 
22  Scalar(const Matrix<Type, 1, 1> & other) :
23  _value{other(0,0)}
24  {
25  }
26 
27  Scalar(Type other) : _value(other)
28  {
29  }
30 
31  operator const Type &()
32  {
33  return _value;
34  }
35 
36  operator Matrix<Type, 1, 1>() const {
38  m(0, 0) = _value;
39  return m;
40  }
41 
42  operator Vector<Type, 1>() const {
44  m(0) = _value;
45  return m;
46  }
47 
48 private:
49  const Type _value;
50 
51 };
52 
54 
55 } // namespace matrix
56 
57 /* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
Scalar(const Matrix< Type, 1, 1 > &other)
Definition: Scalar.hpp:22
Scalar()=delete
Scalar< float > Scalarf
Definition: Scalar.hpp:53
const Type _value
Definition: Scalar.hpp:49
Scalar(Type other)
Definition: Scalar.hpp:27