Split VecBase into a separate file.
vec_common is required as some definitions are needed by both vectorwrapper and vec_base. I also wanted to keep all of the define_has_* macro invocations together, for clarity.
This commit is contained in:
parent
50ebba1c31
commit
e0e167b658
3 changed files with 162 additions and 89 deletions
115
include/vectorwrapper/implem_vec_base.hpp
Normal file
115
include/vectorwrapper/implem_vec_base.hpp
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015-2017 Michele "King_DuckZ" Santullo
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "implem_vec_common.hpp"
|
||||||
|
#include "sequence_bt.hpp"
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
#if defined VWR_OUTER_NAMESPACE
|
||||||
|
namespace VWR_OUTER_NAMESPACE {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace vwr {
|
||||||
|
namespace implem {
|
||||||
|
template <typename V>
|
||||||
|
Vec<V>& assign_same_type ( Vec<V>& parLeft, const Vec<V>& parRight );
|
||||||
|
|
||||||
|
template <typename V> struct is_vec {
|
||||||
|
enum { value = false };
|
||||||
|
};
|
||||||
|
template <typename V> struct is_vec<Vec<V>> {
|
||||||
|
typedef V vector_type;
|
||||||
|
enum { value = true };
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename V> struct get_wrapped_ifn {
|
||||||
|
typedef V type;
|
||||||
|
};
|
||||||
|
template <typename T> struct get_wrapped_ifn<Vec<T>> {
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename V1, typename V2>
|
||||||
|
struct directly_convertible {
|
||||||
|
enum {
|
||||||
|
value =
|
||||||
|
not HasGetAtMethod<VectorWrapperInfo<typename get_wrapped_ifn<V1>::type>>::value and
|
||||||
|
not HasGetAtMethod<VectorWrapperInfo<typename get_wrapped_ifn<V2>::type>>::value
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
class VecBase {
|
||||||
|
friend Vec<V>& assign_same_type<V> ( Vec<V>& parLeft, const Vec<V>& parRight );
|
||||||
|
public:
|
||||||
|
typedef V vector_type;
|
||||||
|
typedef typename VectorWrapperInfo<V>::scalar_type scalar_type;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
dimensions = VectorWrapperInfo<V>::dimensions
|
||||||
|
};
|
||||||
|
|
||||||
|
VecBase ( void ) = default;
|
||||||
|
template <typename T>
|
||||||
|
explicit VecBase ( const T& parInit, typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, bool>::type=false );
|
||||||
|
explicit VecBase ( const vector_type& parInit );
|
||||||
|
template <typename... Args>
|
||||||
|
VecBase ( scalar_type parX, scalar_type parY, Args... parArgs );
|
||||||
|
~VecBase ( void ) = default;
|
||||||
|
|
||||||
|
scalar_type& operator[] ( size_type parIndex );
|
||||||
|
const scalar_type& operator[] ( size_type parIndex ) const;
|
||||||
|
|
||||||
|
vector_type& data ( void ) { return m_wrapped; }
|
||||||
|
const vector_type& data ( void ) const { return m_wrapped; }
|
||||||
|
|
||||||
|
template <typename V2>
|
||||||
|
const typename std::enable_if<is_vec<V2>::value and directly_convertible<V, V2>::value, V2>::type& cast ( void ) const;
|
||||||
|
template <typename V2>
|
||||||
|
typename std::enable_if<is_vec<V2>::value and directly_convertible<V, V2>::value, V2>::type& cast ( void );
|
||||||
|
|
||||||
|
template <typename V2>
|
||||||
|
const typename std::enable_if<is_vec<V2>::value and not directly_convertible<V, V2>::value, V2>::type& cast ( void ) const;
|
||||||
|
template <typename V2>
|
||||||
|
typename std::enable_if<is_vec<V2>::value and not directly_convertible<V, V2>::value, V2>::type& cast ( void );
|
||||||
|
|
||||||
|
template <typename V2> VecBase& operator+= ( const VecBase<V2>& parOther );
|
||||||
|
template <typename V2> VecBase& operator-= ( const VecBase<V2>& parOther );
|
||||||
|
template <typename V2> VecBase& operator*= ( const VecBase<V2>& parOther );
|
||||||
|
template <typename V2> VecBase& operator/= ( const VecBase<V2>& parOther );
|
||||||
|
VecBase& operator+= ( const scalar_type& parOther );
|
||||||
|
VecBase& operator-= ( const scalar_type& parOther );
|
||||||
|
VecBase& operator*= ( const scalar_type& parOther );
|
||||||
|
VecBase& operator/= ( const scalar_type& parOther );
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <size_type... I, typename... Args>
|
||||||
|
void assign_values (const bt::number_seq<size_type, I...>&, Args... parArgs);
|
||||||
|
template <typename Op, typename V2, size_type... I>
|
||||||
|
void assign_values_op (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const VecBase<V2>& parOther);
|
||||||
|
template <typename Op, size_type... I>
|
||||||
|
void assign_values_op_scalar (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const scalar_type& parOther);
|
||||||
|
|
||||||
|
vector_type m_wrapped;
|
||||||
|
};
|
||||||
|
} //namespace implem
|
||||||
|
} //namespace vwr
|
||||||
|
|
||||||
|
#if defined VWR_OUTER_NAMESPACE
|
||||||
|
} //namespace VWR_OUTER_NAMESPACE
|
||||||
|
#endif
|
44
include/vectorwrapper/implem_vec_common.hpp
Normal file
44
include/vectorwrapper/implem_vec_common.hpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015-2017 Michele "King_DuckZ" Santullo
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "size_type.hpp"
|
||||||
|
#include "has_method.hpp"
|
||||||
|
|
||||||
|
#if defined VWR_OUTER_NAMESPACE
|
||||||
|
namespace VWR_OUTER_NAMESPACE {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace vwr {
|
||||||
|
namespace implem {
|
||||||
|
define_has_typedef(lower_vector_type, LowerVec);
|
||||||
|
define_has_typedef(higher_vector_type, HigherVec);
|
||||||
|
define_has_enum(offset_x, OffsetX);
|
||||||
|
define_has_method(get_at, GetAt);
|
||||||
|
define_has_enum(cast_ignore_trailing_properties, CastIgnoreTrailingProperties);
|
||||||
|
} //namespace implem
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
struct VectorWrapperInfo;
|
||||||
|
|
||||||
|
template <typename V, size_type S=VectorWrapperInfo<V>::dimensions>
|
||||||
|
class Vec;
|
||||||
|
} //namespace vwr
|
||||||
|
|
||||||
|
#if defined VWR_OUTER_NAMESPACE
|
||||||
|
} //namespace VWR_OUTER_NAMESPACE
|
||||||
|
#endif
|
|
@ -16,7 +16,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "has_method.hpp"
|
#include "implem_vec_base.hpp"
|
||||||
|
#include "implem_vec_common.hpp"
|
||||||
#include "sequence_bt.hpp"
|
#include "sequence_bt.hpp"
|
||||||
#include "size_type.hpp"
|
#include "size_type.hpp"
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
@ -32,22 +33,14 @@ namespace vwr {
|
||||||
template <typename V>
|
template <typename V>
|
||||||
struct VectorWrapperInfo;
|
struct VectorWrapperInfo;
|
||||||
|
|
||||||
template <typename V, size_type S=VectorWrapperInfo<V>::dimensions>
|
template <typename V, size_type S>
|
||||||
class Vec;
|
class Vec;
|
||||||
|
|
||||||
namespace implem {
|
namespace implem {
|
||||||
define_has_typedef(lower_vector_type, LowerVec);
|
|
||||||
define_has_typedef(higher_vector_type, HigherVec);
|
|
||||||
define_has_enum(offset_x, OffsetX);
|
|
||||||
define_has_method(get_at, GetAt);
|
|
||||||
define_has_enum(cast_ignore_trailing_properties, CastIgnoreTrailingProperties);
|
|
||||||
|
|
||||||
#if defined(VWR_WITH_IMPLICIT_CONVERSIONS)
|
#if defined(VWR_WITH_IMPLICIT_CONVERSIONS)
|
||||||
template <typename V1, typename V2, size_type D>
|
template <typename V1, typename V2, size_type D>
|
||||||
Vec<V1>& assign ( Vec<V1, D>& parLeft, const Vec<V2, D>& parRight );
|
Vec<V1>& assign ( Vec<V1, D>& parLeft, const Vec<V2, D>& parRight );
|
||||||
#endif
|
#endif
|
||||||
template <typename V>
|
|
||||||
Vec<V>& assign_same_type ( Vec<V>& parLeft, const Vec<V>& parRight );
|
|
||||||
|
|
||||||
template <typename T, size_type I> struct get_offset_enum_from_index;
|
template <typename T, size_type I> struct get_offset_enum_from_index;
|
||||||
template <typename T> struct get_offset_enum_from_index<T, 0> {
|
template <typename T> struct get_offset_enum_from_index<T, 0> {
|
||||||
|
@ -126,85 +119,6 @@ namespace vwr {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename V> struct is_vec {
|
|
||||||
enum { value = false };
|
|
||||||
};
|
|
||||||
template <typename V> struct is_vec<Vec<V>> {
|
|
||||||
typedef V vector_type;
|
|
||||||
enum { value = true };
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename V> struct get_wrapped_ifn {
|
|
||||||
typedef V type;
|
|
||||||
};
|
|
||||||
template <typename T> struct get_wrapped_ifn<Vec<T>> {
|
|
||||||
typedef T type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename V1, typename V2>
|
|
||||||
struct directly_convertible {
|
|
||||||
enum {
|
|
||||||
value =
|
|
||||||
not HasGetAtMethod<VectorWrapperInfo<typename get_wrapped_ifn<V1>::type>>::value and
|
|
||||||
not HasGetAtMethod<VectorWrapperInfo<typename get_wrapped_ifn<V2>::type>>::value
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename V>
|
|
||||||
class VecBase {
|
|
||||||
friend Vec<V>& assign_same_type<V> ( Vec<V>& parLeft, const Vec<V>& parRight );
|
|
||||||
public:
|
|
||||||
typedef V vector_type;
|
|
||||||
typedef typename VectorWrapperInfo<V>::scalar_type scalar_type;
|
|
||||||
|
|
||||||
enum {
|
|
||||||
dimensions = VectorWrapperInfo<V>::dimensions
|
|
||||||
};
|
|
||||||
|
|
||||||
VecBase ( void ) = default;
|
|
||||||
template <typename T>
|
|
||||||
explicit VecBase ( const T& parInit, typename std::enable_if<std::is_same<T, scalar_type>::value and not std::is_same<scalar_type, vector_type>::value, bool>::type=false );
|
|
||||||
explicit VecBase ( const vector_type& parInit );
|
|
||||||
template <typename... Args>
|
|
||||||
VecBase ( scalar_type parX, scalar_type parY, Args... parArgs );
|
|
||||||
~VecBase ( void ) = default;
|
|
||||||
|
|
||||||
scalar_type& operator[] ( size_type parIndex );
|
|
||||||
const scalar_type& operator[] ( size_type parIndex ) const;
|
|
||||||
|
|
||||||
vector_type& data ( void ) { return m_wrapped; }
|
|
||||||
const vector_type& data ( void ) const { return m_wrapped; }
|
|
||||||
|
|
||||||
template <typename V2>
|
|
||||||
const typename std::enable_if<is_vec<V2>::value and directly_convertible<V, V2>::value, V2>::type& cast ( void ) const;
|
|
||||||
template <typename V2>
|
|
||||||
typename std::enable_if<is_vec<V2>::value and directly_convertible<V, V2>::value, V2>::type& cast ( void );
|
|
||||||
|
|
||||||
template <typename V2>
|
|
||||||
const typename std::enable_if<is_vec<V2>::value and not directly_convertible<V, V2>::value, V2>::type& cast ( void ) const;
|
|
||||||
template <typename V2>
|
|
||||||
typename std::enable_if<is_vec<V2>::value and not directly_convertible<V, V2>::value, V2>::type& cast ( void );
|
|
||||||
|
|
||||||
template <typename V2> VecBase& operator+= ( const VecBase<V2>& parOther );
|
|
||||||
template <typename V2> VecBase& operator-= ( const VecBase<V2>& parOther );
|
|
||||||
template <typename V2> VecBase& operator*= ( const VecBase<V2>& parOther );
|
|
||||||
template <typename V2> VecBase& operator/= ( const VecBase<V2>& parOther );
|
|
||||||
VecBase& operator+= ( const scalar_type& parOther );
|
|
||||||
VecBase& operator-= ( const scalar_type& parOther );
|
|
||||||
VecBase& operator*= ( const scalar_type& parOther );
|
|
||||||
VecBase& operator/= ( const scalar_type& parOther );
|
|
||||||
|
|
||||||
private:
|
|
||||||
template <size_type... I, typename... Args>
|
|
||||||
void assign_values (const bt::number_seq<size_type, I...>&, Args... parArgs);
|
|
||||||
template <typename Op, typename V2, size_type... I>
|
|
||||||
void assign_values_op (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const VecBase<V2>& parOther);
|
|
||||||
template <typename Op, size_type... I>
|
|
||||||
void assign_values_op_scalar (Op parOp, const bt::number_seq<size_type, I...>& parSeq, const scalar_type& parOther);
|
|
||||||
|
|
||||||
vector_type m_wrapped;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, size_type S=VectorWrapperInfo<T>::dimensions>
|
template <typename T, size_type S=VectorWrapperInfo<T>::dimensions>
|
||||||
struct offsets_array_wrapper {
|
struct offsets_array_wrapper {
|
||||||
template <size_type... I>
|
template <size_type... I>
|
||||||
|
|
Loading…
Reference in a new issue