1#ifndef CPPAD_CG_CODE_HANDLER_VECTOR_INCLUDED
2#define CPPAD_CG_CODE_HANDLER_VECTOR_INCLUDED
31class CodeHandlerVectorSync {
32 friend class CodeHandler<Base>;
34 CodeHandler<Base>* handler_;
37 inline CodeHandlerVectorSync(CodeHandler<Base>& handler) :
39 handler_->addVector(
this);
42 inline CodeHandlerVectorSync(
const CodeHandlerVectorSync& orig) :
43 handler_(orig.handler_) {
44 handler_->addVector(
this);
47 virtual ~CodeHandlerVectorSync() {
48 if (handler_ !=
nullptr)
49 handler_->removeVector(
this);
52 inline CodeHandler<Base>& getHandler()
const {
70template<
class Base,
class T>
73 using iterator =
typename std::vector<T>::iterator;
74 using const_iterator =
typename std::vector<T>::const_iterator;
75 using const_reverse_iterator =
typename std::vector<T>::const_reverse_iterator;
76 using reverse_iterator =
typename std::vector<T>::reverse_iterator;
77 using reference =
typename std::vector<T>::reference;
78 using const_reference =
typename std::vector<T>::const_reference;
90 inline CodeHandlerVector(
const CodeHandlerVector& orig) :
91 CodeHandlerVectorSync<Base>(orig),
99 inline void adjustSize() {
100 size_t s = this->handler_->getManagedNodesCount();
101 if (s >= data_.capacity()) {
102 data_.reserve(s * 3 / 2 + 1);
107 inline void adjustSize(
const OperationNode<Base>& node) {
108 CPPADCG_ASSERT_UNKNOWN(node.getCodeHandler() == this->handler_)
110 size_t p = node.getHandlerPosition();
111 if (p == (std::numeric_limits<
size_t>::max)())
112 throw CGException("An operation node is not managed by this code handler");
114 if (p >= data_.size())
118 inline reference get(const OperationNode<Base>& node) {
119 CPPADCG_ASSERT_UNKNOWN(node.getCodeHandler() == this->handler_)
121 size_t p = node.getHandlerPosition();
122 if (p == (std::numeric_limits<
size_t>::max)())
123 throw CGException("An operation node is not managed by this code handler");
124 CPPADCG_ASSERT_UNKNOWN(p < data_.size())
129 inline const_reference get(const OperationNode<Base>& node)
const {
130 CPPADCG_ASSERT_UNKNOWN(node.getCodeHandler() == this->handler_)
132 size_t p = node.getHandlerPosition();
133 if (p == (std::numeric_limits<
size_t>::max)())
134 throw CGException("An operation node is not managed by this code handler");
135 CPPADCG_ASSERT_UNKNOWN(p < data_.size())
140 inline
void set(const OperationNode<Base>& node,
142 CPPADCG_ASSERT_UNKNOWN(node.getCodeHandler() == this->handler_)
144 size_t p = node.getHandlerPosition();
145 if (p == (std::numeric_limits<
size_t>::max)())
146 throw CGException("An operation node is not managed by this code handler");
147 CPPADCG_ASSERT_UNKNOWN(p < data_.size())
149 data_[node.getHandlerPosition()] = val;
152 inline
size_t size()
const {
156 inline bool empty()
const {
157 return data_.empty();
160 inline void fill(
const T& v) {
161 std::fill(data_.begin(), data_.end(), v);
166 inline iterator begin() {
167 return data_.begin();
170 inline const_iterator begin()
const {
171 return data_.begin();
174 inline iterator end() {
178 inline const_iterator end()
const {
182 inline reverse_iterator rbegin() {
183 return data_.rbegin();
186 inline const_reverse_iterator rbegin()
const {
187 return data_.rbegin();
190 inline reverse_iterator rend() {
194 inline const_reverse_iterator rend()
const {
198 inline const_iterator cbegin() const noexcept {
199 return data_.cbegin();
202 inline const_iterator cend() const noexcept {
206 inline const_reverse_iterator crbegin() const noexcept {
207 return data_.crbegin();
210 inline const_reverse_iterator crend() const noexcept {
211 return data_.crend();
216 size_t end)
override {
217 if (start < data_.size()) {
218 end = std::min<size_t>(end, data_.size());
219 data_.erase(data_.begin() + start, data_.begin() + end);
virtual void nodesErased(size_t start, size_t end)=0
reference operator[](const OperationNode< Base > &node)
void nodesErased(size_t start, size_t end) override