Simbody
3.5
|
00001 #ifndef SimTK_SIMMATRIX_VECTOR_H_ 00002 #define SimTK_SIMMATRIX_VECTOR_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 00030 namespace SimTK { 00031 00032 //============================================================================== 00033 // VECTOR 00034 //============================================================================== 00050 template <class ELT> class Vector_ : public VectorBase<ELT> { 00051 typedef typename CNT<ELT>::Scalar S; 00052 typedef typename CNT<ELT>::Number Number; 00053 typedef typename CNT<ELT>::StdNumber StdNumber; 00054 typedef typename CNT<ELT>::TNeg ENeg; 00055 typedef VectorBase<ELT> Base; 00056 typedef VectorBase<ENeg> BaseNeg; 00057 public: 00058 // Uses default destructor. 00059 00067 Vector_() : Base() {} 00068 00071 Vector_(const Vector_& src) : Base(src) {} 00072 00077 Vector_(const Base& src) : Base(src) {} // e.g., VectorView 00081 Vector_(const BaseNeg& src) : Base(src) {} 00082 00087 explicit Vector_(int m) : Base(m) { } 00092 Vector_(int m, const ELT* cppInitialValues) : Base(m, cppInitialValues) {} 00095 Vector_(int m, const ELT& initialValue) : Base(m, initialValue) {} 00096 00099 template <int M> 00100 explicit Vector_(const Vec<M,ELT>& v) : Base(M) { 00101 for (int i = 0; i < M; ++i) 00102 this->updElt(i, 0) = v(i); 00103 } 00117 Vector_(int m, const S* cppData, bool) 00118 : Base(m, Base::CppNScalarsPerElement, cppData) {} 00123 Vector_(int m, S* cppData, bool) 00124 : Base(m, Base::CppNScalarsPerElement, cppData) {} 00125 00129 Vector_(int m, int stride, const S* data, bool) 00130 : Base(m, stride, data) {} 00134 Vector_(int m, int stride, S* data, bool) 00135 : Base(m, stride, data) {} 00142 Vector_& operator=(const Vector_& src) 00143 { Base::operator=(src); return*this; } 00144 00148 template <class EE> Vector_& operator=(const VectorBase<EE>& src) 00149 { Base::operator=(src); return*this; } 00150 00152 Vector_& operator=(const ELT& v) { Base::operator=(v); return *this; } 00153 00157 template <class EE> Vector_& operator+=(const VectorBase<EE>& m) 00158 { Base::operator+=(m); return*this; } 00163 template <class EE> Vector_& operator-=(const VectorBase<EE>& m) 00164 { Base::operator-=(m); return*this; } 00165 00168 Vector_& operator*=(const StdNumber& t) { Base::operator*=(t); return *this; } 00171 Vector_& operator/=(const StdNumber& t) { Base::operator/=(t); return *this; } 00172 00176 Vector_& operator+=(const ELT& b) 00177 { this->elementwiseAddScalarInPlace(b); return *this; } 00181 Vector_& operator-=(const ELT& b) 00182 { this->elementwiseSubtractScalarInPlace(b); return *this; } 00191 std::string toString() const { 00192 std::stringstream stream; 00193 stream << (*this) ; 00194 return stream.str(); 00195 } 00197 const ELT& get(int i) const { return (*this)[i]; } 00199 void set(int i, const ELT& value) { (*this)[i]=value; } 00202 private: 00203 // NO DATA MEMBERS ALLOWED 00204 }; 00205 00206 } //namespace SimTK 00207 00208 #endif // SimTK_SIMMATRIX_VECTOR_H_