From e0e167b658df4688f77364d6fbc0644d14df206b Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 27 Jul 2018 23:08:36 +0100 Subject: [PATCH] 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. --- include/vectorwrapper/implem_vec_base.hpp | 115 ++++++++++++++++++++ include/vectorwrapper/implem_vec_common.hpp | 44 ++++++++ include/vectorwrapper/vectorwrapper.hpp | 92 +--------------- 3 files changed, 162 insertions(+), 89 deletions(-) create mode 100644 include/vectorwrapper/implem_vec_base.hpp create mode 100644 include/vectorwrapper/implem_vec_common.hpp diff --git a/include/vectorwrapper/implem_vec_base.hpp b/include/vectorwrapper/implem_vec_base.hpp new file mode 100644 index 0000000..b0c25a6 --- /dev/null +++ b/include/vectorwrapper/implem_vec_base.hpp @@ -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 + +#if defined VWR_OUTER_NAMESPACE +namespace VWR_OUTER_NAMESPACE { +#endif + +namespace vwr { + namespace implem { + template + Vec& assign_same_type ( Vec& parLeft, const Vec& parRight ); + + template struct is_vec { + enum { value = false }; + }; + template struct is_vec> { + typedef V vector_type; + enum { value = true }; + }; + + template struct get_wrapped_ifn { + typedef V type; + }; + template struct get_wrapped_ifn> { + typedef T type; + }; + + template + struct directly_convertible { + enum { + value = + not HasGetAtMethod::type>>::value and + not HasGetAtMethod::type>>::value + }; + }; + + template + class VecBase { + friend Vec& assign_same_type ( Vec& parLeft, const Vec& parRight ); + public: + typedef V vector_type; + typedef typename VectorWrapperInfo::scalar_type scalar_type; + + enum { + dimensions = VectorWrapperInfo::dimensions + }; + + VecBase ( void ) = default; + template + explicit VecBase ( const T& parInit, typename std::enable_if::value and not std::is_same::value, bool>::type=false ); + explicit VecBase ( const vector_type& parInit ); + template + 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 + const typename std::enable_if::value and directly_convertible::value, V2>::type& cast ( void ) const; + template + typename std::enable_if::value and directly_convertible::value, V2>::type& cast ( void ); + + template + const typename std::enable_if::value and not directly_convertible::value, V2>::type& cast ( void ) const; + template + typename std::enable_if::value and not directly_convertible::value, V2>::type& cast ( void ); + + template VecBase& operator+= ( const VecBase& parOther ); + template VecBase& operator-= ( const VecBase& parOther ); + template VecBase& operator*= ( const VecBase& parOther ); + template VecBase& operator/= ( const VecBase& 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 + void assign_values (const bt::number_seq&, Args... parArgs); + template + void assign_values_op (Op parOp, const bt::number_seq& parSeq, const VecBase& parOther); + template + void assign_values_op_scalar (Op parOp, const bt::number_seq& parSeq, const scalar_type& parOther); + + vector_type m_wrapped; + }; + } //namespace implem +} //namespace vwr + +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif diff --git a/include/vectorwrapper/implem_vec_common.hpp b/include/vectorwrapper/implem_vec_common.hpp new file mode 100644 index 0000000..1a9b038 --- /dev/null +++ b/include/vectorwrapper/implem_vec_common.hpp @@ -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 + struct VectorWrapperInfo; + + template ::dimensions> + class Vec; +} //namespace vwr + +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif diff --git a/include/vectorwrapper/vectorwrapper.hpp b/include/vectorwrapper/vectorwrapper.hpp index 93e11be..66efe28 100644 --- a/include/vectorwrapper/vectorwrapper.hpp +++ b/include/vectorwrapper/vectorwrapper.hpp @@ -16,7 +16,8 @@ #pragma once -#include "has_method.hpp" +#include "implem_vec_base.hpp" +#include "implem_vec_common.hpp" #include "sequence_bt.hpp" #include "size_type.hpp" #include @@ -32,22 +33,14 @@ namespace vwr { template struct VectorWrapperInfo; - template ::dimensions> + template class Vec; 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) template Vec& assign ( Vec& parLeft, const Vec& parRight ); #endif - template - Vec& assign_same_type ( Vec& parLeft, const Vec& parRight ); template struct get_offset_enum_from_index; template struct get_offset_enum_from_index { @@ -126,85 +119,6 @@ namespace vwr { }; }; - template struct is_vec { - enum { value = false }; - }; - template struct is_vec> { - typedef V vector_type; - enum { value = true }; - }; - - template struct get_wrapped_ifn { - typedef V type; - }; - template struct get_wrapped_ifn> { - typedef T type; - }; - - template - struct directly_convertible { - enum { - value = - not HasGetAtMethod::type>>::value and - not HasGetAtMethod::type>>::value - }; - }; - - template - class VecBase { - friend Vec& assign_same_type ( Vec& parLeft, const Vec& parRight ); - public: - typedef V vector_type; - typedef typename VectorWrapperInfo::scalar_type scalar_type; - - enum { - dimensions = VectorWrapperInfo::dimensions - }; - - VecBase ( void ) = default; - template - explicit VecBase ( const T& parInit, typename std::enable_if::value and not std::is_same::value, bool>::type=false ); - explicit VecBase ( const vector_type& parInit ); - template - 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 - const typename std::enable_if::value and directly_convertible::value, V2>::type& cast ( void ) const; - template - typename std::enable_if::value and directly_convertible::value, V2>::type& cast ( void ); - - template - const typename std::enable_if::value and not directly_convertible::value, V2>::type& cast ( void ) const; - template - typename std::enable_if::value and not directly_convertible::value, V2>::type& cast ( void ); - - template VecBase& operator+= ( const VecBase& parOther ); - template VecBase& operator-= ( const VecBase& parOther ); - template VecBase& operator*= ( const VecBase& parOther ); - template VecBase& operator/= ( const VecBase& 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 - void assign_values (const bt::number_seq&, Args... parArgs); - template - void assign_values_op (Op parOp, const bt::number_seq& parSeq, const VecBase& parOther); - template - void assign_values_op_scalar (Op parOp, const bt::number_seq& parSeq, const scalar_type& parOther); - - vector_type m_wrapped; - }; - template ::dimensions> struct offsets_array_wrapper { template