/* * Copyright 2015-2020 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" #include #if defined VWR_OUTER_NAMESPACE namespace VWR_OUTER_NAMESPACE { #endif namespace vwr { template struct VectorWrapperInfo; typedef decltype(sizeof(int)) vwr_size_t; template ::dimensions> 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); template >::value and std::is_standard_layout::value> struct VecGetter; template struct VecGetter { static typename VectorWrapperInfo::scalar_type& get_at ( T& parVec, size_type parIndex ); }; template struct VecGetter { private: static_assert(HasGetAtMethod>::value, "You must provide a get_at() static method for this vector_type"); typedef typename VectorWrapperInfo::scalar_type scalar_type; typedef T vector_type; using get_at_func = decltype(&VectorWrapperInfo::get_at)(size_type, vector_type&); using get_at_rettype = typename std::result_of::type; static_assert(not std::is_rvalue_reference::value, "rvalue ref return types not implemented"); static_assert(std::is_lvalue_reference::value, "Read-only vectors not implemented"); public: static get_at_rettype get_at ( T& parVec, size_type parIndex ); }; template struct get_offset_enum_from_index; template struct get_offset_enum_from_index { static constexpr vwr_size_t value = VectorWrapperInfo::offset_x; }; template struct get_offset_enum_from_index { static constexpr vwr_size_t value = VectorWrapperInfo::offset_y; }; template struct get_offset_enum_from_index { static constexpr vwr_size_t value = VectorWrapperInfo::offset_z; }; template struct get_offset_enum_from_index { static constexpr vwr_size_t value = VectorWrapperInfo::offset_w; }; template ::dimensions> struct min_offset { static constexpr vwr_size_t value = ( static_cast(get_offset_enum_from_index::value) < static_cast(min_offset::value) ? static_cast(get_offset_enum_from_index::value) : static_cast(min_offset::value) ); }; template struct min_offset { static constexpr vwr_size_t value = get_offset_enum_from_index::value; }; } //namespace implem } //namespace vwr #if defined VWR_OUTER_NAMESPACE } //namespace VWR_OUTER_NAMESPACE #endif