Honeycomb  0.1
Component-Model Framework
Vec.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
6 
7 namespace honey
8 {
9 
10 namespace vec { namespace priv
11 {
13  template<sdt Dim, class Real_, int Options, class Alloc_>
14  struct Traits
15  {
17  typedef Real_ Real;
18  typedef Real ElemT;
19  static const sdt dim = Dim;
20  static const sdt rows = Options & matrix::Option::vecRow ? 1 : dim;
21  static const sdt cols = Options & matrix::Option::vecRow ? dim : 1;
22  static const int options = Options;
23  typedef Alloc_ Alloc;
24  };
25 } }
26 
27 template<sdt Dim, class Real, int Options, class Alloc>
28 struct matrix::priv::Traits<Vec<Dim,Real,Options,Alloc>> : vec::priv::Traits<Dim,Real,Options,Alloc> {};
29 
31 template<sdt Dim, class Real, int Options, class Alloc>
32 class Vec : public VecBase<Vec<Dim,Real,Options,Alloc>>
33 {
35 public:
36  using Super::s_size;
37 
39  Vec() {}
41  template<class Int>
42  explicit Vec(Int dim, typename std::enable_if<std::is_integral<Int>::value && s_size == matrix::dynamic>::type*_=0)
43  { mt_unused(_); this->resize(dim); }
45  explicit Vec(Real scalar) { this->fromScalar(scalar); }
47  Vec(const Real* a, sdt dim) { this->resize(dim); this->fromArray(a); }
49  Vec(const Alloc& alloc) { this->setAllocator(alloc); }
51  template<class T>
52  Vec(const MatrixBase<T>& rhs) { operator=(rhs); }
53 
55  template<class T>
56  Vec& operator=(const MatrixBase<T>& rhs) { Super::operator=(rhs); return *this; }
57 };
58 
63 
68 
69 
71 #define MATRIX_VEC_ADAPTER \
72 public: \
73  using Super::s_size; \
74  using typename Super::Alloc; \
75  \
76  Matrix() {} \
77  template<class Int> \
78  explicit Matrix(Int dim, typename std::enable_if<std::is_integral<Int>::value && s_size == matrix::dynamic>::type*_=0) \
79  : Super(dim) {} \
80  explicit Matrix(Real scalar) : Super(scalar) {} \
81  Matrix(const Real* a, sdt dim) : Super(a,dim) {} \
82  Matrix(const Alloc& alloc) : Super(alloc) {} \
83  template<class T> \
84  Matrix(const MatrixBase<T>& rhs) : Super(rhs) {} \
85  template<class T> \
86  Matrix& operator=(const MatrixBase<T>& rhs) { Super::operator=(rhs); return *this; } \
87 
88 template<sdt Dim, class Real, int Options, class Alloc_>
90 class Matrix<Dim,1,Real,Options,Alloc_> : public Vec<Dim,Real,Options,Alloc_>
91 {
94 };
95 
97 template<sdt Dim, class Real, int Options, class Alloc_>
98 class Matrix<1,Dim,Real,Options,Alloc_> : public Vec<Dim,Real, Options | matrix::Option::vecRow, Alloc_>
99 {
102 };
103 
104 }
MatrixS & fromScalar(Real f)
Initialize with scalar in every element.
Definition: Base.h:72
(m x n)-dimensional matrix
Definition: Matrix.h:24
Vec()
No init.
Definition: Vec.h:39
Vec(const Real *a, sdt dim)
Initialize from array with dimension dim
Definition: Vec.h:47
static const sdt dynamic
Definition: Traits.h:23
VecBase & operator=(const MatrixBase< T > &rhs)
Assign to row or column vector of any dimension. Asserts that if this vector has a fixed dimension th...
Definition: Base.h:35
Alloc_ Alloc
Definition: Vec.h:23
Vec(Int dim, typename std::enable_if< std::is_integral< Int >::value &&s_size==matrix::dynamic >::type *_=0)
Allocate elements for dimension size, only available if vector is dynamic.
Definition: Vec.h:42
7 bit alignment stored as log2, so max alignment is 2^15 byte boundary
Definition: Traits.h:32
N-dimensional vector traits.
Definition: Vec.h:14
Vec< matrix::dynamic, Float, matrix::Option::vecRow > VecRowN_f
Definition: Vec.h:66
Auto or dynamic vector storage.
Definition: Storage.h:45
#define mt_unused(Param)
Remove the unused parameter warning.
Definition: Meta.h:20
ptrdiff_t sdt
Size difference type, shorthand for ptrdiff_t.
Definition: Core.h:92
static const int options
Definition: Vec.h:22
Vec< matrix::dynamic, Double > VecN_d
Definition: Vec.h:62
Vec(Real scalar)
Construct uniform vector.
Definition: Vec.h:45
static const sdt rows
Definition: Vec.h:20
static auto _
Definition: Module.cpp:8
Vec< matrix::dynamic, Real, matrix::Option::vecRow > VecRowN
N-dimensional row vector types.
Definition: Vec.h:65
static const sdt dim
Definition: Vec.h:19
Vec< matrix::dynamic, Float > VecN_f
Definition: Vec.h:61
Real_ Real
Definition: Vec.h:17
N-dimensional vector.
Definition: Traits.h:12
static const sdt cols
Definition: Vec.h:21
Definition: Traits.h:20
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Real ElemT
Definition: Vec.h:18
T * alloc(szt count=1)
Allocate memory for count number of T objects. Objects are not constructed.
Definition: Allocator.h:31
Vector base class.
Definition: Base.h:11
Vec & operator=(const MatrixBase< T > &rhs)
Assign to row or column vector of any dimension. Asserts that if this vector has a fixed dimension th...
Definition: Vec.h:56
Numeral< Real >::Real_ Real_
Operations and constants for Real type. See Float_, Double_.
Definition: Real.h:25
Vec< matrix::dynamic > VecN
N-dimensional column vector types.
Definition: Vec.h:60
#define MATRIX_VEC_ADAPTER
It's not possible to inherit ctors, so this macro is required.
Definition: Vec.h:71
Vec(const MatrixBase< T > &rhs)
Construct from row or column vector of any dimension. Asserts that if this vector has a fixed dimensi...
Definition: Vec.h:52
Matrix base class.
Definition: Base.h:17
MatrixS & fromArray(const Num *a, bool rowMajor=true)
Initialize from array. If the array is in row-major format set rowMajor to true, otherwise set to fal...
Definition: Base.h:53
Vec< matrix::dynamic, Double, matrix::Option::vecRow > VecRowN_d
Definition: Vec.h:67
Global Honeycomb namespace.
Vec(const Alloc &alloc)
Construct with allocator, for a dynamic vector. Allocator element type must be int8.
Definition: Vec.h:49
priv::Storage< Vec< Dim, Real_, Options, Alloc_ > > Storage
Definition: Vec.h:16
VecS & resize(sdt dim)
Sets number of dimensions and reallocates only if different. All previous data is lost on reallocatio...
Definition: Base.h:69