All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
VectorViewMvt.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_SCAL_META_VECTORVIEWMVT_HPP
#define STAN_MATH_PRIM_SCAL_META_VECTORVIEWMVT_HPP
#include <stan/math/prim/mat/meta/is_vector_like.hpp>
#include <stan/math/prim/scal/meta/is_vector_like.hpp>
#include <stan/math/prim/scal/meta/scalar_type_pre.hpp>
#include <stdexcept>
#include <vector>
namespace stan {
template <typename T, bool is_array
= stan::is_vector_like
<typename stan::math::value_type<T>::type>::value,
bool throw_if_accessed = false>
class VectorViewMvt {
public:
typedef typename scalar_type_pre<T>::type matrix_t;
explicit VectorViewMvt(matrix_t& m) : x_(&m) { }
explicit VectorViewMvt(std::vector<matrix_t>& vm) : x_(&vm[0]) { }
matrix_t& operator[](int i) {
if (throw_if_accessed)
throw std::out_of_range("VectorViewMvt: this cannot be accessed");
if (is_array)
return x_[i];
else
return x_[0];
}
private:
matrix_t* x_;
};
template <typename T, bool is_array, bool throw_if_accessed>
class VectorViewMvt<const T, is_array, throw_if_accessed> {
public:
typedef typename scalar_type_pre<T>::type matrix_t;
explicit VectorViewMvt(const matrix_t& m) : x_(&m) { }
explicit VectorViewMvt(const std::vector<matrix_t>& vm) : x_(&vm[0]) { }
const matrix_t& operator[](int i) const {
if (throw_if_accessed)
throw std::out_of_range("VectorViewMvt: this cannot be accessed");
if (is_array)
return x_[i];
else
return x_[0];
}
private:
const matrix_t* x_;
};
}
#endif
stan::scalar_type_pre::type
scalar_type_helper_pre< is_vector< typename stan::math::value_type< T >::type >::value, typename stan::math::value_type< T >::type, T >::type type
Definition: scalar_type_pre.hpp:42
stan::is_vector_like
Definition: is_vector_like.hpp:12
is_vector_like.hpp
stan::VectorViewMvt::VectorViewMvt
VectorViewMvt(std::vector< matrix_t > &vm)
Definition: VectorViewMvt.hpp:22
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::VectorViewMvt
VectorViewMvt(const std::vector< matrix_t > &vm)
Definition: VectorViewMvt.hpp:47
stan::VectorViewMvt::operator[]
matrix_t & operator[](int i)
Definition: VectorViewMvt.hpp:24
is_vector_like.hpp
scalar_type_pre.hpp
stan::math::out_of_range
void out_of_range(const char *function, const int max, const int index, const char *msg1="", const char *msg2="")
Throw an out_of_range exception with a consistently formatted message.
Definition: out_of_range.hpp:30
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::operator[]
const matrix_t & operator[](int i) const
Definition: VectorViewMvt.hpp:49
stan::VectorViewMvt::VectorViewMvt
VectorViewMvt(matrix_t &m)
Definition: VectorViewMvt.hpp:20
stan::VectorViewMvt
Definition: VectorViewMvt.hpp:16
stan::VectorViewMvt::matrix_t
scalar_type_pre< T >::type matrix_t
Definition: VectorViewMvt.hpp:18
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::VectorViewMvt
VectorViewMvt(const matrix_t &m)
Definition: VectorViewMvt.hpp:45
stan::VectorViewMvt< const T, is_array, throw_if_accessed >::matrix_t
scalar_type_pre< T >::type matrix_t
Definition: VectorViewMvt.hpp:43
stan::math::value_type
Primary template class for metaprogram to compute the type of values stored in a container.
Definition: value_type.hpp:21

[ Stan Home Page ] © 2011–2015, Stan Development Team.