MBSim |
Project Page |
00001 /* Copyright (C) 2004-2014 MBSim Development Team 00002 * 00003 * This library is free software; you can redistribute it and/or 00004 * modify it under the terms of the GNU Lesser General Public 00005 * License as published by the Free Software Foundation; either 00006 * version 2.1 of the License, or (at your option) any later version. 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public 00014 * License along with this library; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00016 * 00017 * Contact: martin.o.foerg@googlemail.com 00018 */ 00019 00020 #ifndef _MBSIM_PTR_H_ 00021 #define _MBSIM_PTR_H_ 00022 00023 #include <fmatvec/function.h> 00024 #include <mbsim/functions/basic_functions.h> 00025 00026 namespace MBSim { 00027 00032 template<typename T> 00033 class Ptr { 00034 public: 00038 Ptr() : p(NULL) {} 00040 Ptr(const Ptr<T> &src) : p(src.p) {} 00042 Ptr(T* src) : p(src) {} 00044 Ptr<T>& operator=(const Ptr<T> &src) { p=src.p; return *this; } 00046 Ptr<T>& operator=(T *src) { p=src; return *this; } 00048 T& operator*() const { return *p; } 00050 T* operator->() const { return p; } 00052 T* get() const { return p; } 00054 operator bool() const { return p!=NULL; } 00056 00057 00061 template<typename S> 00062 Ptr<T>& operator=(const Ptr<S> &src) { return operator=(src.get()); } 00064 template<typename S> 00065 Ptr(const Ptr<S> &src) { operator=(src.get()); } 00067 template<typename S> 00068 Ptr(S* src) { operator=(src); } 00069 00073 template<typename S> 00074 Ptr<T>& operator=(S *src); 00076 00077 private: 00078 T *p; 00079 }; 00080 00085 template<> 00086 template<> 00087 Ptr<fmatvec::Function<fmatvec::VecV(double)> >& Ptr<fmatvec::Function<fmatvec::VecV(double)> >::operator=(fmatvec::Function<double(double)> *src) { 00088 VectorValuedFunction<fmatvec::VecV> *vvf=new VectorValuedFunction<fmatvec::VecV>(); 00089 vvf->addComponent(src); 00090 p=vvf; 00091 return *this; 00092 } 00093 00094 // other "pointer casts" e.g. from Function<double(VecV)> to Function<double(double)> may be added here 00095 // like the one above. 00096 00097 } 00098 00099 #endif
1.8.0