/*! \file Carray.h * \brief classes to interface raw C arrays (prototypes) * * ---------------------------------------------------------------------------- * * $Id$ * \author Thomas Forbriger * \date 14/05/2011 * * classes to interface raw C arrays (prototypes) * * Copyright (c) 2011 by Thomas Forbriger (BFO Schiltach) * * ---- * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * ---- * * * REVISIONS and CHANGES * - 14/05/2011 V1.0 Thomas Forbriger * * ============================================================================ */ // include guard #ifndef AFF_CARRAY_H_VERSION #define AFF_CARRAY_H_VERSION \ "AFF_CARRAY_H V1.0 " #define AFF_CARRAY_H_CVSID \ "$Id$" #include #include namespace aff { /*! \brief Interface class to raw memory (C style array) * */ template class ConstCArray { public: /*! \name Various types * * In particular due to our concept of const-correctness we need * several typedefs to declare types derived from the element type of * the array. * * \sa \ref sec_design_interface_typedef * \sa \ref sec_design_const */ //@{ //! Type of array to be interfaced typedef aff::ConstArray Tarray; //! Type of representation typedef Tarray::Trepresentation Trepresentation; //! Type of shape typedef Tarray::Tshape Tshape; //! we use this for one of the access operators typedef Tshape::TSizeVec TSizeVec; //! Element type typedef Tarray::Tvalue Tvalue; //! Type of pointer to element typedef Tarray::Tpointer Tpointer; //! Type of reference to element typedef Tarray::Treference Treference; //! const element type typedef Tarray::Tconst_value Tconst_value; //! Type of pointer to const element typedef Tarray::Tconst_pointer Tconst_pointer; //! Type of reference to const element typedef Tarray::Tconst_reference Tconst_reference; //! Type of this array typedef ConstCArray Tcontainer; //! Type of the array of const values typedef Tcontainer Tcontainer_of_const; //! Short for Tcontainer_of_const typedef Tcontainer Tcoc; //@} /*-----------------------------------------------------------------*/ /*! \name Constructors * * No copy constructors or copy operators are provided since this is * provided as an interface class only. */ //@{ //! construct from shape and representation ConstCArray(const Tarray& array) : Mrepresentation(array.representation()) { } //@} /*------------------------------------------------------------------*/ /*! \name Shape access */ //@{ //! size of dimension \par i const Tsize& size(const Tsubscript& i) const { return (Msize[i]); } //! stride of dimension \par i const Tsize& stride(const Tsubscript& i) const { return Mstride[i]; } //! size of dimensions const TSizeVec& size() const { return (Msize); } //! strides of dimensions const TSizeVec& stride() const { return Mstride; } //@} /*-----------------------------------------------------------------*/ /*! \name Memory access * */ //@{ //! return pointer to first element in Fortran layout Tconst_pointer pointer() const { return(&Mrepresentation[this->offset()]); } /*! \brief return type-casted pointer to first element in Fortran * layout * * The cast checks for const-correctness and type-size. But you have * to ensure that there is a meaningful relation between both types * involved. * * \sa aff::util::SizeCheckedCast */ template TT* castedpointer() const { return(SizeCheckedCast::cast(this->pointer())); } //@} protected: //! pass offset to derived class const TSizeVec::Tvalue& offset() const { return Moffset; } private: //! representation member Trepresentation Mrepresentation; //! sizes of dimensions TSizeVec Msize; //! strides of dimensions TSizeVec Mstride; //! offset to first index TSizeVec::Tvalue Moffset; }; // class ConstCArray /*======================================================================*/ /*! \brief Interface class to raw memory (C style array) * * See aff::ConstCArray for the basic concepts used here. * * \sa aff::ConstCArray */ template class CArray: public ConstCArray { public: /*! \name Various types * * In particular due to our concept of const-correctness we need * several typedefs to declare types derived from the element type of * the array. * * \sa \ref sec_design_interface_typedef * \sa \ref sec_design_const */ //@{ //! Type of array to be interfaced typedef aff::Array Tarray; //! Base class typedef aff::ConstCArray Tbase; //! Type of representation typedef Tarray::Trepresentation Trepresentation; //! Type of shape typedef Tarray::Tshape Tshape; //! we use this for one of the access operators typedef Tshape::TSizeVec TSizeVec; //! Element type typedef Tarray::Tvalue Tvalue; //! Type of pointer to element typedef Tarray::Tpointer Tpointer; //! Type of reference to element typedef Tarray::Treference Treference; //! const element type typedef Tarray::Tconst_value Tconst_value; //! Type of pointer to const element typedef Tarray::Tconst_pointer Tconst_pointer; //! Type of reference to const element typedef Tarray::Tconst_reference Tconst_reference; //! Type of this array typedef CArray Tcontainer; //! Type of the array of const values typedef Tbase Tcontainer_of_const; //! Short for Tcontainer_of_const typedef Tcontainer Tcoc; //@} /*-----------------------------------------------------------------*/ /*! \name Constructors * * No copy constructors or copy operators are provided since this is * provided as an interface class only. */ //@{ //! construct from shape and representation Array(const Tarray& array) : Tbase(array), Mrepresentation(array.representation()) { } //@} /*-----------------------------------------------------------------*/ /*! \name Memory access * */ //@{ //! return pointer to first element in Fortran layout Tpointer pointer() const { return(&Mrepresentation[this->offset()]); } /*! \brief return type-casted pointer to first element in Fortran * layout * * The cast checks for const-correctness and type-size. But you have * to ensure that there is a meaningful relation between both types * involved. * * \sa aff::util::SizeCheckedCast */ template TT* castedpointer() const { return(SizeCheckedCast::cast(this->pointer())); } //@} private: //! my (mutable) data representation Trepresentation Mrepresentation; }; // class CArray } // namespace aff #endif // AFF_CARRAY_H_VERSION (includeguard) /* ----- END OF Carray.h ----- */