state_vector.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #ifndef STATE_VECTOR_H
34 #define STATE_VECTOR_H
35 
36 #include <float.h>
37 #include <memory>
38 #include <array>
39 
40 #include <tuw_control/utils.h>
42 
43 namespace tuw
44 {
48 class StateVector;
49 using StateVectorSPtr = std::shared_ptr<StateVector>;
50 using StateVectorConstSPtr = std::shared_ptr<StateVector const>;
51 using StateVectorUPtr = std::unique_ptr<StateVector>;
52 using StateVectorConstUPtr = std::unique_ptr<StateVector const>;
53 
54 class StateVector : public State
55 {
56  // special class member functions
57 public:
58  StateVector(State* _parent) : State(_parent)
59  {
61  }
62 
63 public:
65  {
67  }
68 
69 public:
70  virtual ~StateVector() = default;
71 
72 public:
73  StateVector(const StateVector&) = default;
74 
75 public:
76  StateVector& operator=(const StateVector&) = default;
77 
78 public:
79  StateVector(StateVector&&) = default;
80 
81 public:
82  StateVector& operator=(StateVector&&) = default;
83 
84  // implementation of virtual functions
85 public:
86  virtual StateSPtr cloneState() const override
87  {
88  return std::shared_ptr<StateVector>(new StateVector(*this));
89  }
90 
91 public:
92  virtual double& value(const std::size_t& _i) override
93  {
94  return values_[_i];
95  }
96 
97 public:
98  virtual const double& value(const std::size_t& _i) const override
99  {
100  return values_[_i];
101  }
102 
103 public:
104  virtual size_t valueSize() const override
105  {
106  return values_.size();
107  }
108 
109 public:
110  virtual void resize(const std::size_t& _i) override
111  {
112  values_.resize(_i);
113  }
114 
116 public:
117  std::vector<double>& valuesVector()
118  {
119  return values_;
120  }
122 public:
123  const std::vector<double>& valuesVector() const
124  {
125  return values_;
126  }
127 
128 protected:
129  std::vector<double> values_;
130 };
131 }
132 
133 #endif // STATE_VECTOR_H
std::shared_ptr< State > StateSPtr
Definition: state.h:129
std::vector< double > & valuesVector()
Reference to the state variables array.
virtual double & value(const std::size_t &_i) override
Access state variable based on index _i.
StateVector(State *_parent)
std::shared_ptr< StateVector > StateVectorSPtr
virtual ~StateVector()=default
std::unique_ptr< StateVector const > StateVectorConstUPtr
std::shared_ptr< StateVector const > StateVectorConstSPtr
std::unique_ptr< StateVector > StateVectorUPtr
virtual StateSPtr cloneState() const override
Clone-to-base-class-ptr function.
virtual void resize(const std::size_t &_i) override
Generic tree-like recursive structure that allows sub-structure access as well as ordered (array-like...
Definition: state.h:135
StateVector & operator=(const StateVector &)=default
virtual size_t valueSize() const override
Size of the state variables.
const std::vector< double > & valuesVector() const
Const reference to the variables array.
virtual const double & value(const std::size_t &_i) const override
Const access state variable based on index _i.
Implementation of State for a dynamic size vector of double values.
void callRootUpdateSize()
Calls (if present) the parent updateSize procedure. Otherwise performs root updateSize.
Definition: state.h:380
std::vector< double > values_
State array container.


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:22