Simbody  3.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RowVectorView_.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATRIX_ROWVECTORVIEW_H_
2 #define SimTK_SIMMATRIX_ROWVECTORVIEW_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 // ROW VECTOR VIEW
35 //==============================================================================
42 template <class ELT> class RowVectorView_ : public RowVectorBase<ELT> {
43  typedef RowVectorBase<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 RowVectorView_<ELT> T;
50 public:
51  // Default construction is suppressed.
52  // Uses default destructor.
53 
54  // Create a RowVectorView_ handle using a given helper rep.
55  explicit RowVectorView_(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>&>(r.getHelper()), typename MatrixHelper<S>::ShallowCopy()) { }
62 
63  // Copy assignment is deep but not reallocating.
65  Base::operator=(r); return *this;
66  }
67 
68  // Ask for shallow copy
69  explicit RowVectorView_(const MatrixHelper<S>& h) : Base(h, typename MatrixHelper<S>::ShallowCopy()) { }
70  explicit RowVectorView_(MatrixHelper<S>& h) : Base(h, typename MatrixHelper<S>::ShallowCopy()) { }
71 
72  RowVectorView_& operator=(const Base& b) { Base::operator=(b); return *this; }
73 
74  RowVectorView_& operator=(const ELT& v) { Base::operator=(v); return *this; }
75 
76  template <class EE> RowVectorView_& operator=(const RowVectorBase<EE>& m)
77  { Base::operator=(m); return*this; }
78  template <class EE> RowVectorView_& operator+=(const RowVectorBase<EE>& m)
79  { Base::operator+=(m); return*this; }
80  template <class EE> RowVectorView_& operator-=(const RowVectorBase<EE>& m)
81  { Base::operator-=(m); return*this; }
82 
83  RowVectorView_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; }
84  RowVectorView_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; }
85  RowVectorView_& operator+=(const ELT& b) { this->elementwiseAddScalarInPlace(b); return *this; }
86  RowVectorView_& operator-=(const ELT& b) { this->elementwiseSubtractScalarInPlace(b); return *this; }
87 
88 private:
89  // NO DATA MEMBERS ALLOWED
90  RowVectorView_(); // default construction suppressed (what is it a view of?)
91 };
92 
93 } //namespace SimTK
94 
95 #endif // SimTK_SIMMATRIX_ROWVECTORVIEW_H_