yat/utility/BasicVector.h

Code
Comments
Other
Rev Date Author Line
3605 27 Jan 17 peter 1 #ifndef _theplu_yat_utility_basic_vector
3605 27 Jan 17 peter 2 #define _theplu_yat_utility_basic_vector
3605 27 Jan 17 peter 3
3605 27 Jan 17 peter 4 // $Id$
3605 27 Jan 17 peter 5
3605 27 Jan 17 peter 6 /*
3605 27 Jan 17 peter 7   Copyright (C) 2017 Peter Johansson
3605 27 Jan 17 peter 8
3605 27 Jan 17 peter 9   This file is part of the yat library, http://dev.thep.lu.se/yat
3605 27 Jan 17 peter 10
3605 27 Jan 17 peter 11   The yat library is free software; you can redistribute it and/or
3605 27 Jan 17 peter 12   modify it under the terms of the GNU General Public License as
3605 27 Jan 17 peter 13   published by the Free Software Foundation; either version 3 of the
3605 27 Jan 17 peter 14   License, or (at your option) any later version.
3605 27 Jan 17 peter 15
3605 27 Jan 17 peter 16   The yat library is distributed in the hope that it will be useful,
3605 27 Jan 17 peter 17   but WITHOUT ANY WARRANTY; without even the implied warranty of
3605 27 Jan 17 peter 18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3605 27 Jan 17 peter 19   General Public License for more details.
3605 27 Jan 17 peter 20
3605 27 Jan 17 peter 21   You should have received a copy of the GNU General Public License
3605 27 Jan 17 peter 22   along with yat. If not, see <http://www.gnu.org/licenses/>.
3605 27 Jan 17 peter 23 */
3605 27 Jan 17 peter 24
3605 27 Jan 17 peter 25 #include <gsl/gsl_vector.h>
3605 27 Jan 17 peter 26
3605 27 Jan 17 peter 27 #include <cstddef>
3605 27 Jan 17 peter 28
3605 27 Jan 17 peter 29 namespace theplu {
3605 27 Jan 17 peter 30 namespace yat {
3605 27 Jan 17 peter 31 namespace utility {
3605 27 Jan 17 peter 32
3605 27 Jan 17 peter 33   /**
3605 27 Jan 17 peter 34      yat uses template expression to implement fast linear algebra
3605 27 Jan 17 peter 35      operators such as Vector and Matrix multiplication.
3605 27 Jan 17 peter 36
3605 27 Jan 17 peter 37      This class defines the interface for a vector and is the base
3605 27 Jan 17 peter 38      class of both VectorBase and VectorExpression. Functions that
3605 27 Jan 17 peter 39      work on both usual VectorBase and on [temporary] VectorExpression
3605 27 Jan 17 peter 40      pass a BasicVector<T>.
3605 27 Jan 17 peter 41
3605 27 Jan 17 peter 42      The class only defines the interface and does not implement
3605 27 Jan 17 peter 43      anything. All functions must be implemented by derived classes.
3605 27 Jan 17 peter 44
3605 27 Jan 17 peter 45      \since new in yat 0.15
3605 27 Jan 17 peter 46   */
3605 27 Jan 17 peter 47   template<class Derived>
3605 27 Jan 17 peter 48   class BasicVector
3605 27 Jan 17 peter 49   {
3605 27 Jan 17 peter 50   public:
3605 27 Jan 17 peter 51     /**
3605 27 Jan 17 peter 52        Class that inherits from BasicVector
3605 27 Jan 17 peter 53      */
3605 27 Jan 17 peter 54     typedef Derived derived_type;
3605 27 Jan 17 peter 55
3605 27 Jan 17 peter 56     /**
3605 27 Jan 17 peter 57        \brief access element \a i
3605 27 Jan 17 peter 58      */
3605 27 Jan 17 peter 59     double operator()(size_t i) const
3605 27 Jan 17 peter 60     {  return (*static_cast<const Derived*>(this))(i);  }
3605 27 Jan 17 peter 61
3605 27 Jan 17 peter 62     /**
3605 27 Jan 17 peter 63        \return a gsl vector pointer
3605 27 Jan 17 peter 64      */
3605 27 Jan 17 peter 65     const gsl_vector* gsl_vector_p(void) const
3605 27 Jan 17 peter 66     {  return static_cast<const Derived*>(this)->gsl_vector_p();  }
3605 27 Jan 17 peter 67
3605 27 Jan 17 peter 68     /**
3605 27 Jan 17 peter 69        \return number of elements in vector
3605 27 Jan 17 peter 70      */
3605 27 Jan 17 peter 71     size_t size(void) const
3605 27 Jan 17 peter 72     {  return static_cast<const Derived*>(this)->size();  }
3605 27 Jan 17 peter 73   };
3605 27 Jan 17 peter 74
3605 27 Jan 17 peter 75 }}} // of namespace utility, yat, and theplu
3605 27 Jan 17 peter 76
3605 27 Jan 17 peter 77 #endif