diff --git a/Sofa/framework/Helper/CMakeLists.txt b/Sofa/framework/Helper/CMakeLists.txt index 8d0eaa5b603..c35b5b41344 100644 --- a/Sofa/framework/Helper/CMakeLists.txt +++ b/Sofa/framework/Helper/CMakeLists.txt @@ -55,8 +55,10 @@ set(HEADER_FILES ${SRC_ROOT}/init.h ${SRC_ROOT}/integer_id.h ${SRC_ROOT}/accessor/ReadAccessor.h + ${SRC_ROOT}/accessor/ReadAccessorFixedArray.h ${SRC_ROOT}/accessor/ReadAccessorVector.h ${SRC_ROOT}/accessor/WriteAccessor.h + ${SRC_ROOT}/accessor/WriteAccessorFixedArray.h ${SRC_ROOT}/accessor/WriteAccessorVector.h ${SRC_ROOT}/accessor/WriteOnlyAccessor.h ${SRC_ROOT}/io/BaseFileAccess.h diff --git a/Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessor.h b/Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessor.h index 2b0c5b44a1b..624990800b3 100644 --- a/Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessor.h +++ b/Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessor.h @@ -21,7 +21,9 @@ ******************************************************************************/ #pragma once +#include #include +#include namespace sofa::helper { @@ -70,6 +72,16 @@ class ReadAccessor const_reference operator* () const { return *vref; } }; +template +class ReadAccessor::value>> + : public ReadAccessorFixedArray< FixedArrayLikeType > +{ +public: + typedef ReadAccessorFixedArray< FixedArrayLikeType > Inherit; + typedef typename Inherit::container_type container_type; + ReadAccessor(const container_type& c) : Inherit(c) {} +}; + template class ReadAccessor::value> > diff --git a/Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessorFixedArray.h b/Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessorFixedArray.h new file mode 100644 index 00000000000..62e493e45eb --- /dev/null +++ b/Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessorFixedArray.h @@ -0,0 +1,65 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include +#include + +namespace sofa::helper +{ +////////////////////////// ReadAccessor for wrapping around fixed array like object ////////////////////// +/// ReadAccessor implementation class for fixed array types +template +class ReadAccessorFixedArray +{ +public: + typedef T container_type; + typedef const T const_container_type; + typedef typename container_type::size_type size_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::iterator iterator; + typedef typename container_type::const_iterator const_iterator; + +protected: + const container_type* vref; + +public: + ReadAccessorFixedArray(const container_type& container) : vref(&container) {} + + bool empty() const { return false; } + size_type size() const { return T::static_size; } + const_reference operator[](size_type i) const { return (*vref)[i]; } + + const_iterator begin() const { return vref->begin(); } + const_iterator end() const { return vref->end(); } + + ///////// Access the container for reading //////////////// + operator const_container_type& () const { return *vref; } + const_container_type* operator->() const { return vref; } + const_container_type& operator* () const { return *vref; } + const_container_type& ref() const { return *vref; } ///< this duplicate operator* (remove ?) + /////////////////////////////////////////////////////////// +}; + +} diff --git a/Sofa/framework/Helper/src/sofa/helper/accessor/WriteAccessor.h b/Sofa/framework/Helper/src/sofa/helper/accessor/WriteAccessor.h index e9691c28bbe..e1abe8b7442 100644 --- a/Sofa/framework/Helper/src/sofa/helper/accessor/WriteAccessor.h +++ b/Sofa/framework/Helper/src/sofa/helper/accessor/WriteAccessor.h @@ -21,7 +21,9 @@ ******************************************************************************/ #pragma once +#include #include +#include namespace sofa::helper { @@ -81,6 +83,16 @@ class WriteAccessor } }; +template +class WriteAccessor::value>> + : public WriteAccessorFixedArray< FixedArrayLikeType > +{ +public: + typedef WriteAccessorFixedArray< FixedArrayLikeType > Inherit; + typedef typename Inherit::container_type container_type; + WriteAccessor(container_type& c) : Inherit(c) {} +}; + template class WriteAccessor::value>> diff --git a/Sofa/framework/Helper/src/sofa/helper/accessor/WriteAccessorFixedArray.h b/Sofa/framework/Helper/src/sofa/helper/accessor/WriteAccessorFixedArray.h new file mode 100644 index 00000000000..0953e07da48 --- /dev/null +++ b/Sofa/framework/Helper/src/sofa/helper/accessor/WriteAccessorFixedArray.h @@ -0,0 +1,87 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +namespace sofa::helper +{ + +/// WriteAccessor implementation class for fixed array types +template +class WriteAccessorFixedArray +{ +public: + typedef T container_type; + typedef const T const_container_type; + typedef typename container_type::size_type size_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::iterator iterator; + typedef typename container_type::const_iterator const_iterator; + +protected: + container_type* vref; + +public: + WriteAccessorFixedArray(container_type& container) : vref(&container) {} + + ////// Capacity ////// + bool empty() const { return false; } + size_type size() const { return T::static_size; } + + ////// Element access ////// + reference operator[](size_type pos) { return (*vref)[pos]; } + const_reference operator[](size_type pos) const { return (*vref)[pos]; } + + reference front() { return vref->front(); } + const_reference front() const { return vref->front(); } + + reference back() { return vref->back(); } + const_reference back() const { return vref->back(); } + + + ////// Iterators ////// + const_iterator begin() const { return vref->begin(); } + iterator begin() { return vref->begin(); } + const_iterator end() const { return vref->end(); } + iterator end() { return vref->end(); } + + ////// Access the container in reading & writing ////// + operator container_type () { return *vref; } + container_type* operator->() { return vref; } + container_type& operator* () { return *vref; } + container_type& wref() { return *vref; } + /////////////////////////////////////////////////////// + + ///////// Access the container for reading //////////////// + operator const_container_type () const { return *vref; } + const_container_type* operator->() const { return vref; } + const_container_type& operator* () const { return *vref; } + + /// this one duplicate operator* + const container_type& ref() const { return *vref; } + /////////////////////////////////////////////////////////// +}; + +}