Simbody  3.7
VectorView_.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATRIX_VECTORVIEW_H_
2 #define SimTK_SIMMATRIX_VECTORVIEW_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 // VECTOR VIEW
35 //==============================================================================
42 template <class ELT> class VectorView_ : public VectorBase<ELT> {
43  typedef VectorBase<ELT> Base;
44  typedef typename CNT<ELT>::Scalar S;
45  typedef typename CNT<ELT>::Number Number;
46  typedef typename CNT<ELT>::StdNumber StdNumber;
47  typedef VectorView_<ELT> T;
48  typedef VectorView_< typename CNT<ELT>::TNeg > TNeg;
49  typedef RowVectorView_< typename CNT<ELT>::THerm > THerm;
50 public:
51  // Default construction is suppressed.
52  // Uses default destructor.
53 
54  // Create a VectorView_ handle using a given helper rep.
55  explicit VectorView_(MatrixHelperRep<S>* hrep) : Base(hrep) {}
56 
57  // Copy constructor is shallow. CAUTION: despite const argument, this preserves writability
58  // if it was present in the source. This is necessary to allow temporary views to be
59  // created and used as lvalues.
61  : Base(const_cast<MatrixHelper<S>&>(v.getHelper()), typename MatrixHelper<S>::ShallowCopy()) { }
62 
63  // Copy assignment is deep but not reallocating.
65  Base::operator=(v); return *this;
66  }
67 
68  // Ask for shallow copy
69  explicit VectorView_(const MatrixHelper<S>& h) : Base(h, typename MatrixHelper<S>::ShallowCopy()) { }
70  explicit VectorView_(MatrixHelper<S>& h) : Base(h, typename MatrixHelper<S>::ShallowCopy()) { }
71 
72  VectorView_& operator=(const Base& b) { Base::operator=(b); return *this; }
73 
74  VectorView_& operator=(const ELT& v) { Base::operator=(v); return *this; }
75 
76  template <class EE> VectorView_& operator=(const VectorBase<EE>& m)
77  { Base::operator=(m); return*this; }
78  template <class EE> VectorView_& operator+=(const VectorBase<EE>& m)
79  { Base::operator+=(m); return*this; }
80  template <class EE> VectorView_& operator-=(const VectorBase<EE>& m)
81  { Base::operator-=(m); return*this; }
82 
83  VectorView_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; }
84  VectorView_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; }
85  VectorView_& operator+=(const ELT& b) { this->elementwiseAddScalarInPlace(b); return *this; }
86  VectorView_& operator-=(const ELT& b) { this->elementwiseSubtractScalarInPlace(b); return *this; }
87 
88 private:
89  // NO DATA MEMBERS ALLOWED
90  VectorView_(); // default construction suppressed (what's it a View of?)
91 };
92 
93 } //namespace SimTK
94 
95 #endif // SimTK_SIMMATRIX_VECTORVIEW_H_
Here we define class MatrixHelper<S>, the scalar-type templatized helper class for the more general...
Definition: MatrixHelper.h:79
VectorBase & operator-=(const VectorBase &r)
Definition: VectorBase.h:148
VectorBase & operator/=(const StdNumber &t)
Definition: VectorBase.h:146
VectorView_ & operator-=(const VectorBase< EE > &m)
Definition: VectorView_.h:80
Definition: MatrixHelper.h:48
VectorView_ & operator-=(const ELT &b)
Definition: VectorView_.h:86
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
MatrixBase & elementwiseSubtractScalarInPlace(const S &s)
Set M(i,j)-=s for every element of M and some value s.
VectorBase & operator=(const VectorBase &b)
Copy assignment is deep copy but behavior depends on type of lhs: if view, rhs must match...
Definition: VectorBase.h:138
K::Scalar Scalar
Definition: CompositeNumericalTypes.h:160
VectorView_ & operator=(const VectorBase< EE > &m)
Definition: VectorView_.h:76
VectorView_ & operator/=(const StdNumber &t)
Definition: VectorView_.h:84
VectorView_ & operator*=(const StdNumber &t)
Definition: VectorView_.h:83
VectorView_(const VectorView_ &v)
Definition: VectorView_.h:60
VectorBase & operator+=(const VectorBase &r)
Definition: VectorBase.h:147
VectorView_(const MatrixHelper< S > &h)
Definition: VectorView_.h:69
VectorView_ & operator+=(const ELT &b)
Definition: VectorView_.h:85
VectorView_(MatrixHelper< S > &h)
Definition: VectorView_.h:70
EStdNumber StdNumber
Definition: MatrixBase.h:99
VectorView_ & operator=(const ELT &v)
Definition: VectorView_.h:74
MatrixBase & elementwiseAddScalarInPlace(const S &s)
Set M(i,j)+=s for every element of M and some value s.
K::StdNumber StdNumber
Definition: CompositeNumericalTypes.h:163
VectorView_ & operator=(const VectorView_ &v)
Definition: VectorView_.h:64
VectorView_ & operator+=(const VectorBase< EE > &m)
Definition: VectorView_.h:78
const MatrixHelper< Scalar > & getHelper() const
Definition: MatrixBase.h:864
This is a dataless rehash of the MatrixBase class to specialize it for Vectors.
Definition: BigMatrix.h:164
VectorView_(MatrixHelperRep< S > *hrep)
Definition: VectorView_.h:55
This is the common base class for Simbody&#39;s Vector_ and Matrix_ classes for handling large...
Definition: BigMatrix.h:163
K::Number Number
Definition: CompositeNumericalTypes.h:162
VectorView_ & operator=(const Base &b)
Definition: VectorView_.h:72
(Advanced) This class is identical to Vector_ except that it has shallow (reference) copy and assignm...
Definition: BigMatrix.h:170
VectorBase & operator*=(const StdNumber &t)
Definition: VectorBase.h:145