Simbody  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MatrixView_.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATRIX_MATRIXVIEW_H_
2 #define SimTK_SIMMATRIX_MATRIXVIEW_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2005-13 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
31 namespace SimTK {
32 
33 //==============================================================================
34 // MATRIX VIEW
35 //==============================================================================
43 template <class ELT> class MatrixView_ : public MatrixBase<ELT> {
44  typedef MatrixBase<ELT> Base;
45  typedef typename CNT<ELT>::Scalar S;
46  typedef typename CNT<ELT>::StdNumber StdNumber;
47 public:
48  // Default construction is suppressed.
49  // Uses default destructor.
50 
51  // Create a MatrixView_ handle using a given helper rep.
52  explicit MatrixView_(MatrixHelperRep<S>* hrep) : Base(hrep) {}
53 
54  // Copy constructor is shallow. CAUTION: despite const argument, this preserves writability
55  // if it was present in the source. This is necessary to allow temporary views to be
56  // created and used as lvalues.
58  : Base(MatrixCommitment(),
59  const_cast<MatrixHelper<S>&>(m.getHelper()),
60  typename MatrixHelper<S>::ShallowCopy()) {}
61 
62  // Copy assignment is deep but not reallocating.
64  Base::operator=(m); return *this;
65  }
66 
67  // Ask for shallow copy
68  MatrixView_(const MatrixHelper<S>& h) : Base(MatrixCommitment(), h, typename MatrixHelper<S>::ShallowCopy()) { }
69  MatrixView_(MatrixHelper<S>& h) : Base(MatrixCommitment(), h, typename MatrixHelper<S>::ShallowCopy()) { }
70 
71  MatrixView_& operator=(const Matrix_<ELT>& v) { Base::operator=(v); return *this; }
72  MatrixView_& operator=(const ELT& e) { Base::operator=(e); return *this; }
73 
74  template <class EE> MatrixView_& operator=(const MatrixBase<EE>& m)
75  { Base::operator=(m); return *this; }
76  template <class EE> MatrixView_& operator+=(const MatrixBase<EE>& m)
77  { Base::operator+=(m); return *this; }
78  template <class EE> MatrixView_& operator-=(const MatrixBase<EE>& m)
79  { Base::operator-=(m); return *this; }
80 
81  MatrixView_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; }
82  MatrixView_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; }
83  MatrixView_& operator+=(const ELT& r) { this->updDiag() += r; return *this; }
84  MatrixView_& operator-=(const ELT& r) { this->updDiag() -= r; return *this; }
85 
86  operator const Matrix_<ELT>&() const { return *reinterpret_cast<const Matrix_<ELT>*>(this); }
87  operator Matrix_<ELT>&() { return *reinterpret_cast<Matrix_<ELT>*>(this); }
88 
89 private:
90  // NO DATA MEMBERS ALLOWED
91  MatrixView_(); // default constructor suppressed (what's it a view of?)
92 };
93 
94 
95 
96 } //namespace SimTK
97 
98 #endif // SimTK_SIMMATRIX_MATRIXVIEW_H_
Here we define class MatrixHelper, the scalar-type templatized helper class for the more general...
Definition: MatrixHelper.h:79
MatrixView_ & operator*=(const StdNumber &t)
Definition: MatrixView_.h:81
MatrixView_ & operator=(const ELT &e)
Definition: MatrixView_.h:72
const MatrixHelper< Scalar > & getHelper() const
Definition: MatrixBase.h:865
MatrixView_ & operator-=(const MatrixBase< EE > &m)
Definition: MatrixView_.h:78
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
(Advanced) This class is identical to Matrix_ except that it has shallow (reference) copy and assignm...
Definition: BigMatrix.h:167
MatrixBase & operator=(const MatrixBase &b)
Definition: MatrixBase.h:201
MatrixView_ & operator=(const MatrixBase< EE > &m)
Definition: MatrixView_.h:74
MatrixBase & operator*=(const StdNumber &t)
Definition: MatrixBase.h:290
This is the common base class for Simbody's Vector_ and Matrix_ classes for handling large...
Definition: BigMatrix.h:163
MatrixView_(const MatrixHelper< S > &h)
Definition: MatrixView_.h:68
MatrixView_(const MatrixView_ &m)
Definition: MatrixView_.h:57
MatrixView_(MatrixHelperRep< S > *hrep)
Definition: MatrixView_.h:52
MatrixBase & operator/=(const StdNumber &t)
Definition: MatrixBase.h:291
MatrixBase & operator+=(const MatrixBase &r)
Definition: MatrixBase.h:292
MatrixView_ & operator=(const MatrixView_ &m)
Definition: MatrixView_.h:63
MatrixView_(MatrixHelper< S > &h)
Definition: MatrixView_.h:69
VectorView_< ELT > updDiag()
Select main diagonal (of largest leading square if rectangular) and return it as a writable view of t...
Definition: BigMatrix.h:245
MatrixView_ & operator=(const Matrix_< ELT > &v)
Definition: MatrixView_.h:71
MatrixView_ & operator-=(const ELT &r)
Definition: MatrixView_.h:84
A MatrixCommitment provides a set of acceptable matrix characteristics.
Definition: MatrixCharacteristics.h:831
MatrixBase & operator-=(const MatrixBase &r)
Definition: MatrixBase.h:293
MatrixView_ & operator+=(const MatrixBase< EE > &m)
Definition: MatrixView_.h:76
Definition: MatrixHelper.h:48
MatrixView_ & operator+=(const ELT &r)
Definition: MatrixView_.h:83
MatrixView_ & operator/=(const StdNumber &t)
Definition: MatrixView_.h:82
This is the matrix class intended to appear in user code for large, variable size matrices...
Definition: BigMatrix.h:168