Chris@49: // Copyright (C) 2011-2012 Ryan Curtin Chris@49: // Chris@49: // This Source Code Form is subject to the terms of the Mozilla Public Chris@49: // License, v. 2.0. If a copy of the MPL was not distributed with this Chris@49: // file, You can obtain one at http://mozilla.org/MPL/2.0/. Chris@49: Chris@49: //! \addtogroup SpValProxy Chris@49: //! @{ Chris@49: Chris@49: /** Chris@49: * Sparse value proxy class, meant to prevent 0s from being added to sparse Chris@49: * matrices. T1 should be either SpMat or SpSubview, and if it's not, bad news Chris@49: * is probably coming. This class only uses T1::add_element() and Chris@49: * T1::delete_element(). Chris@49: */ Chris@49: template Chris@49: class SpValProxy Chris@49: { Chris@49: public: Chris@49: Chris@49: typedef typename T1::elem_type eT; // Convenience typedef Chris@49: Chris@49: friend class SpMat; Chris@49: friend class SpSubview; Chris@49: Chris@49: /** Chris@49: * Create the sparse value proxy. Chris@49: * Otherwise, pass a pointer to a reference of the value. Chris@49: */ Chris@49: arma_inline SpValProxy(uword row, uword col, T1& in_parent, eT* in_val_ptr = NULL); Chris@49: Chris@49: //! For swapping operations. Chris@49: arma_inline SpValProxy& operator=(const SpValProxy& rhs); Chris@49: template Chris@49: arma_inline SpValProxy& operator=(const SpValProxy& rhs); Chris@49: Chris@49: //! Overload all of the potential operators. Chris@49: Chris@49: //! First, the ones that could modify a value. Chris@49: arma_inline SpValProxy& operator=(const eT rhs); Chris@49: arma_inline SpValProxy& operator+=(const eT rhs); Chris@49: arma_inline SpValProxy& operator-=(const eT rhs); Chris@49: arma_inline SpValProxy& operator*=(const eT rhs); Chris@49: arma_inline SpValProxy& operator/=(const eT rhs); Chris@49: Chris@49: arma_inline SpValProxy& operator++(); Chris@49: arma_inline SpValProxy& operator--(); Chris@49: arma_inline eT operator++(const int); Chris@49: arma_inline eT operator--(const int); Chris@49: Chris@49: //! This will work for any other operations that do not modify a value. Chris@49: arma_inline operator eT() const; Chris@49: Chris@49: Chris@49: private: Chris@49: Chris@49: // Deletes the element if it is zero. Does not check if val_ptr == NULL! Chris@49: arma_inline arma_hot void check_zero(); Chris@49: Chris@49: uword row; Chris@49: uword col; Chris@49: Chris@49: eT* val_ptr; Chris@49: Chris@49: T1& parent; // We will call this object if we need to insert or delete an element. Chris@49: }; Chris@49: Chris@49: Chris@49: Chris@49: //! @}