1 /*
  2  *   Copyright (c) 2007, Michael Lehn
  3  *
  4  *   All rights reserved.
  5  *
  6  *   Redistribution and use in source and binary forms, with or without
  7  *   modification, are permitted provided that the following conditions
  8  *   are met:
  9  *
 10  *   1) Redistributions of source code must retain the above copyright
 11  *      notice, this list of conditions and the following disclaimer.
 12  *   2) Redistributions in binary form must reproduce the above copyright
 13  *      notice, this list of conditions and the following disclaimer in
 14  *      the documentation and/or other materials provided with the
 15  *      distribution.
 16  *   3) Neither the name of the FLENS development group nor the names of
 17  *      its contributors may be used to endorse or promote products derived
 18  *      from this software without specific prior written permission.
 19  *
 20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  */
 32 
 33 #ifndef FLENS_STORAGE_ARRAY_CONSTARRAYVIEW_H
 34 #define FLENS_STORAGE_ARRAY_CONSTARRAYVIEW_H 1
 35 
 36 namespace flens {
 37 
 38 template <typename T, typename I, typename A>
 39     class ArrayView;
 40 
 41 template <typename T, typename I, typename A>
 42     class Array;
 43 
 44 template <typename T,
 45           typename I = IndexOptions<>,
 46           typename A = std::allocator<T> >
 47 class ConstArrayView
 48 {
 49     public:
 50         typedef T                      ElementType;
 51         typedef typename I::IndexType  IndexType;
 52         typedef A                      Allocator;
 53 
 54         typedef ConstArrayView          ConstView;
 55         typedef ArrayView<T, I, A>      View;
 56         typedef Array<T, I, A>          NoView;
 57 
 58         static const IndexType          defaultIndexBase = I::defaultIndexBase;
 59 
 60         ConstArrayView(IndexType length,
 61                        const ElementType *data,
 62                        IndexType stride = IndexType(1),
 63                        IndexType firstIndex =  defaultIndexBase,
 64                        const Allocator &allocator = Allocator());
 65 
 66         ConstArrayView(const ConstArrayView &rhs);
 67 
 68         template <typename RHS>
 69             ConstArrayView(const RHS &rhs);
 70 
 71         ~ConstArrayView();
 72 
 73         //-- operators ---------------------------------------------------------
 74         const ElementType &
 75         operator()(IndexType index) const;
 76 
 77         //-- methods -----------------------------------------------------------
 78 
 79         IndexType
 80         firstIndex() const;
 81 
 82         IndexType
 83         lastIndex() const;
 84 
 85         IndexType
 86         length() const;
 87 
 88         IndexType
 89         stride() const;
 90 
 91         const ElementType *
 92         data() const;
 93 
 94         const Allocator &
 95         allocator() const;
 96 
 97         const ConstArrayView
 98         view(IndexType from, IndexType to,
 99              IndexType stride = IndexType(1),
100              IndexType firstViewIndex =  defaultIndexBase) const;
101 
102     private:
103         ConstArrayView &
104         operator=(const ConstArrayView &rhs);
105 
106         const ElementType *_data;
107         Allocator         _allocator;
108         IndexType         _length, _stride, _firstIndex;
109 };
110 
111 // namespace flens
112 
113 #endif // FLENS_STORAGE_ARRAY_CONSTARRAYVIEW_H