Chris@49
|
1 // Copyright (C) 2011-2012 Ryan Curtin
|
Chris@49
|
2 //
|
Chris@49
|
3 // This Source Code Form is subject to the terms of the Mozilla Public
|
Chris@49
|
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
|
Chris@49
|
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
Chris@49
|
6
|
Chris@49
|
7 //! \addtogroup SpValProxy
|
Chris@49
|
8 //! @{
|
Chris@49
|
9
|
Chris@49
|
10 /**
|
Chris@49
|
11 * Sparse value proxy class, meant to prevent 0s from being added to sparse
|
Chris@49
|
12 * matrices. T1 should be either SpMat or SpSubview, and if it's not, bad news
|
Chris@49
|
13 * is probably coming. This class only uses T1::add_element() and
|
Chris@49
|
14 * T1::delete_element().
|
Chris@49
|
15 */
|
Chris@49
|
16 template<typename T1>
|
Chris@49
|
17 class SpValProxy
|
Chris@49
|
18 {
|
Chris@49
|
19 public:
|
Chris@49
|
20
|
Chris@49
|
21 typedef typename T1::elem_type eT; // Convenience typedef
|
Chris@49
|
22
|
Chris@49
|
23 friend class SpMat<eT>;
|
Chris@49
|
24 friend class SpSubview<eT>;
|
Chris@49
|
25
|
Chris@49
|
26 /**
|
Chris@49
|
27 * Create the sparse value proxy.
|
Chris@49
|
28 * Otherwise, pass a pointer to a reference of the value.
|
Chris@49
|
29 */
|
Chris@49
|
30 arma_inline SpValProxy(uword row, uword col, T1& in_parent, eT* in_val_ptr = NULL);
|
Chris@49
|
31
|
Chris@49
|
32 //! For swapping operations.
|
Chris@49
|
33 arma_inline SpValProxy& operator=(const SpValProxy& rhs);
|
Chris@49
|
34 template<typename T2>
|
Chris@49
|
35 arma_inline SpValProxy& operator=(const SpValProxy<T2>& rhs);
|
Chris@49
|
36
|
Chris@49
|
37 //! Overload all of the potential operators.
|
Chris@49
|
38
|
Chris@49
|
39 //! First, the ones that could modify a value.
|
Chris@49
|
40 arma_inline SpValProxy& operator=(const eT rhs);
|
Chris@49
|
41 arma_inline SpValProxy& operator+=(const eT rhs);
|
Chris@49
|
42 arma_inline SpValProxy& operator-=(const eT rhs);
|
Chris@49
|
43 arma_inline SpValProxy& operator*=(const eT rhs);
|
Chris@49
|
44 arma_inline SpValProxy& operator/=(const eT rhs);
|
Chris@49
|
45
|
Chris@49
|
46 arma_inline SpValProxy& operator++();
|
Chris@49
|
47 arma_inline SpValProxy& operator--();
|
Chris@49
|
48 arma_inline eT operator++(const int);
|
Chris@49
|
49 arma_inline eT operator--(const int);
|
Chris@49
|
50
|
Chris@49
|
51 //! This will work for any other operations that do not modify a value.
|
Chris@49
|
52 arma_inline operator eT() const;
|
Chris@49
|
53
|
Chris@49
|
54
|
Chris@49
|
55 private:
|
Chris@49
|
56
|
Chris@49
|
57 // Deletes the element if it is zero. Does not check if val_ptr == NULL!
|
Chris@49
|
58 arma_inline arma_hot void check_zero();
|
Chris@49
|
59
|
Chris@49
|
60 uword row;
|
Chris@49
|
61 uword col;
|
Chris@49
|
62
|
Chris@49
|
63 eT* val_ptr;
|
Chris@49
|
64
|
Chris@49
|
65 T1& parent; // We will call this object if we need to insert or delete an element.
|
Chris@49
|
66 };
|
Chris@49
|
67
|
Chris@49
|
68
|
Chris@49
|
69
|
Chris@49
|
70 //! @}
|