QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmlinearopiterator.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Andreas Gaida
5 Copyright (C) 2008 Ralph Schreyer
6 Copyright (C) 2008 Klaus Spanderen
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_linear_op_iterator_hpp
27#define quantlib_linear_op_iterator_hpp
28
29#include <ql/types.hpp>
30#include <numeric>
31#include <utility>
32#include <vector>
33
34namespace QuantLib {
35
37 public:
39 : index_(index) {}
40
41 explicit FdmLinearOpIterator(std::vector<Size> dim)
42 : index_(0),
43 dim_(std::move(dim)),
44 coordinates_(dim_.size(), 0) {}
45
46 FdmLinearOpIterator(std::vector<Size> dim, std::vector<Size> coordinates, Size index)
47 : index_(index), dim_(std::move(dim)), coordinates_(std::move(coordinates)) {}
48
49 void operator++() {
50 ++index_;
51 for (Size i=0; i < dim_.size(); ++i) {
52 if (++coordinates_[i] == dim_[i]) {
53 coordinates_[i] = 0;
54 }
55 else {
56 break;
57 }
58 }
59 }
60
61 // this is not really a dereference, but is intended to make this class compatible with range-bound for loops
63 return *this;
64 }
65
66 bool operator!=(const FdmLinearOpIterator& iterator) const {
67 return index_ != iterator.index_;
68 }
69
70 Size index() const {
71 return index_;
72 }
73
74 const std::vector<Size> & coordinates() const {
75 return coordinates_;
76 }
77
78 void swap(FdmLinearOpIterator& iter) noexcept {
79 std::swap(iter.index_, index_);
80 dim_.swap(iter.dim_);
81 coordinates_.swap(iter.coordinates_);
82 }
83
84 private:
86 std::vector<Size> dim_;
87 std::vector<Size> coordinates_;
88 };
89}
90
91#endif
bool operator!=(const FdmLinearOpIterator &iterator) const
FdmLinearOpIterator(std::vector< Size > dim)
FdmLinearOpIterator(std::vector< Size > dim, std::vector< Size > coordinates, Size index)
const std::vector< Size > & coordinates() const
const FdmLinearOpIterator & operator*() const
void swap(FdmLinearOpIterator &iter) noexcept
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.