Honeycomb  0.1
Component-Model Framework
Storage.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 
5 
6 namespace honey { namespace vec { namespace priv
7 {
8 
9 template<class Real, sdt Dim, szt Align> struct StorageFieldsMixin;
10 
12 template<class Subclass>
13 class StorageFields : public matrix::priv::StorageDense<Subclass>,
14  public StorageFieldsMixin< typename matrix::priv::Traits<Subclass>::Real,
15  matrix::priv::Traits<Subclass>::dim,
16  matrix::Option::getAlign< matrix::priv::Traits<Subclass>::options >::value >
17 {
19 public:
20  using Super::s_rows;
21  using Super::s_cols;
22  using Super::s_size;
23  using typename Super::Real;
24 
26  const Real& operator[](sdt i) const { this->assertIndex(i); return data()[i]; }
27  Real& operator[](sdt i) { this->assertIndex(i); return data()[i]; }
29  const Real& operator()(sdt i) const { return (*this)[i]; }
30  Real& operator()(sdt i) { return (*this)[i]; }
32  const Real& operator()(sdt row, sdt col) const { this->assertIndex(row,col); return data()[row|col]; }
33  Real& operator()(sdt row, sdt col) { this->assertIndex(row,col); return data()[row|col]; }
34 
35  sdt rows() const { return s_rows; }
36  sdt cols() const { return s_cols; }
37  sdt size() const { return s_size; }
38 
39  Real* data() { return &this->x; }
40  const Real* data() const { return &this->x; }
41 };
42 
44 template<class Subclass>
45 struct Storage : matrix::priv::Storage<Subclass>
46 {
48  using Super::data;
49  using typename Super::Real;
50 
52  const Real& operator[](sdt i) const { this->assertIndex(i); return data()[i]; }
53  Real& operator[](sdt i) { this->assertIndex(i); return data()[i]; }
54 
55  using Super::operator();
57  const Real& operator()(sdt row, sdt col) const { this->assertIndex(row,col); return data()[row|col]; }
58  Real& operator()(sdt row, sdt col) { this->assertIndex(row,col); return data()[row|col]; }
59 };
60 
61 } } }
Automatic (stack-compatible) vector storage that allows direct access to dimension fields...
Definition: Storage.h:13
Real & operator[](sdt i)
Definition: Storage.h:53
matrix::priv::Storage< Subclass > Super
Definition: Storage.h:47
const Real & operator[](sdt i) const
Access vector element at index.
Definition: Storage.h:26
Traits< Subclass >::Real Real
Definition: Storage.h:12
static const sdt s_cols
Definition: Storage.h:16
Real * data()
Definition: Storage.h:39
Auto or dynamic vector storage.
Definition: Storage.h:45
const Real & operator()(sdt row, sdt col) const
Access vector element with (row, column)
Definition: Storage.h:57
const Real & operator[](sdt i) const
Access vector element at index.
Definition: Storage.h:52
const Real * data() const
Definition: Storage.h:40
ptrdiff_t sdt
Size difference type, shorthand for ptrdiff_t.
Definition: Core.h:92
static const sdt s_rows
Definition: Storage.h:15
Real & operator()(sdt row, sdt col)
Definition: Storage.h:33
Chooses storage based on traits.
Definition: Storage.h:233
static const sdt s_size
Definition: Storage.h:17
void assertIndex(sdt i) const
Definition: Storage.h:50
Definition: Storage.h:10
sdt size() const
Definition: Storage.h:37
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Real & operator[](sdt i)
Definition: Storage.h:27
sdt rows() const
Definition: Storage.h:35
const Real & operator()(sdt i) const
Access vector element at index.
Definition: Storage.h:29
Real & operator()(sdt row, sdt col)
Definition: Storage.h:58
const Real & operator()(sdt row, sdt col) const
Access vector element with (row, column)
Definition: Storage.h:32
sdt cols() const
Definition: Storage.h:36
Global Honeycomb namespace.
Real & operator()(sdt i)
Definition: Storage.h:30