Simbody
3.5
|
00001 #ifndef SimTK_SIMMATRIX_MATRIXVIEW_H_ 00002 #define SimTK_SIMMATRIX_MATRIXVIEW_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm): SimTKcommon * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2005-13 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00031 namespace SimTK { 00032 00033 //============================================================================== 00034 // MATRIX VIEW 00035 //============================================================================== 00043 template <class ELT> class MatrixView_ : public MatrixBase<ELT> { 00044 typedef MatrixBase<ELT> Base; 00045 typedef typename CNT<ELT>::Scalar S; 00046 typedef typename CNT<ELT>::StdNumber StdNumber; 00047 public: 00048 // Default construction is suppressed. 00049 // Uses default destructor. 00050 00051 // Create a MatrixView_ handle using a given helper rep. 00052 explicit MatrixView_(MatrixHelperRep<S>* hrep) : Base(hrep) {} 00053 00054 // Copy constructor is shallow. CAUTION: despite const argument, this preserves writability 00055 // if it was present in the source. This is necessary to allow temporary views to be 00056 // created and used as lvalues. 00057 MatrixView_(const MatrixView_& m) 00058 : Base(MatrixCommitment(), 00059 const_cast<MatrixHelper<S>&>(m.getHelper()), 00060 typename MatrixHelper<S>::ShallowCopy()) {} 00061 00062 // Copy assignment is deep but not reallocating. 00063 MatrixView_& operator=(const MatrixView_& m) { 00064 Base::operator=(m); return *this; 00065 } 00066 00067 // Ask for shallow copy 00068 MatrixView_(const MatrixHelper<S>& h) : Base(MatrixCommitment(), h, typename MatrixHelper<S>::ShallowCopy()) { } 00069 MatrixView_(MatrixHelper<S>& h) : Base(MatrixCommitment(), h, typename MatrixHelper<S>::ShallowCopy()) { } 00070 00071 MatrixView_& operator=(const Matrix_<ELT>& v) { Base::operator=(v); return *this; } 00072 MatrixView_& operator=(const ELT& e) { Base::operator=(e); return *this; } 00073 00074 template <class EE> MatrixView_& operator=(const MatrixBase<EE>& m) 00075 { Base::operator=(m); return *this; } 00076 template <class EE> MatrixView_& operator+=(const MatrixBase<EE>& m) 00077 { Base::operator+=(m); return *this; } 00078 template <class EE> MatrixView_& operator-=(const MatrixBase<EE>& m) 00079 { Base::operator-=(m); return *this; } 00080 00081 MatrixView_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; } 00082 MatrixView_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; } 00083 MatrixView_& operator+=(const ELT& r) { this->updDiag() += r; return *this; } 00084 MatrixView_& operator-=(const ELT& r) { this->updDiag() -= r; return *this; } 00085 00086 operator const Matrix_<ELT>&() const { return *reinterpret_cast<const Matrix_<ELT>*>(this); } 00087 operator Matrix_<ELT>&() { return *reinterpret_cast<Matrix_<ELT>*>(this); } 00088 00089 private: 00090 // NO DATA MEMBERS ALLOWED 00091 MatrixView_(); // default constructor suppressed (what's it a view of?) 00092 }; 00093 00094 00095 00096 } //namespace SimTK 00097 00098 #endif // SimTK_SIMMATRIX_MATRIXVIEW_H_