yat/utility/Index.h

Code
Comments
Other
Rev Date Author Line
4200 19 Aug 22 peter 1 #ifndef _theplu_yat_utility_index_
4200 19 Aug 22 peter 2 #define _theplu_yat_utility_index_
1106 19 Feb 08 peter 3
1106 19 Feb 08 peter 4 // $Id$
1106 19 Feb 08 peter 5
1106 19 Feb 08 peter 6 /*
2119 12 Dec 09 peter 7   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2009 Peter Johansson
1106 19 Feb 08 peter 9
1437 25 Aug 08 peter 10   This file is part of the yat library, http://dev.thep.lu.se/yat
1106 19 Feb 08 peter 11
1106 19 Feb 08 peter 12   The yat library is free software; you can redistribute it and/or
1106 19 Feb 08 peter 13   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 14   published by the Free Software Foundation; either version 3 of the
1106 19 Feb 08 peter 15   License, or (at your option) any later version.
1106 19 Feb 08 peter 16
1106 19 Feb 08 peter 17   The yat library is distributed in the hope that it will be useful,
1106 19 Feb 08 peter 18   but WITHOUT ANY WARRANTY; without even the implied warranty of
1106 19 Feb 08 peter 19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1106 19 Feb 08 peter 20   General Public License for more details.
1106 19 Feb 08 peter 21
1106 19 Feb 08 peter 22   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 23   along with yat. If not, see <http://www.gnu.org/licenses/>.
1106 19 Feb 08 peter 24 */
1106 19 Feb 08 peter 25
1106 19 Feb 08 peter 26 #include "SmartPtr.h"
1106 19 Feb 08 peter 27
1106 19 Feb 08 peter 28 #include <vector>
1106 19 Feb 08 peter 29
1106 19 Feb 08 peter 30 namespace theplu {
1106 19 Feb 08 peter 31 namespace yat {
1106 19 Feb 08 peter 32 namespace utility {
1106 19 Feb 08 peter 33
1746 23 Jan 09 peter 34   /**
1746 23 Jan 09 peter 35      \brief Class for storing indices of, e.g., a MatrixLookup.
1746 23 Jan 09 peter 36
1746 23 Jan 09 peter 37      This class is basically a wrapper around std::vector<size_t>. The
1746 23 Jan 09 peter 38      major differences are that the class is constant and copying is
1746 23 Jan 09 peter 39      performed in constant time (shallow copy).
1746 23 Jan 09 peter 40    */
1106 19 Feb 08 peter 41   class Index
1106 19 Feb 08 peter 42   {
1106 19 Feb 08 peter 43   public:
1106 19 Feb 08 peter 44     /**
1528 24 Sep 08 peter 45        Read only iterator
1528 24 Sep 08 peter 46
1528 24 Sep 08 peter 47        \since New in yat 0.5
1528 24 Sep 08 peter 48      */
1528 24 Sep 08 peter 49     typedef std::vector<size_t>::const_iterator const_iterator;
1528 24 Sep 08 peter 50
1528 24 Sep 08 peter 51     /**
1106 19 Feb 08 peter 52        Creates an empty Index
1106 19 Feb 08 peter 53      */
1106 19 Feb 08 peter 54     Index(void);
1106 19 Feb 08 peter 55
1106 19 Feb 08 peter 56     /**
1106 19 Feb 08 peter 57        Created Index will satisfy a[i] = i.
1106 19 Feb 08 peter 58        \param n size of created Index
1106 19 Feb 08 peter 59     */
1485 09 Sep 08 peter 60     explicit Index(size_t n);
1106 19 Feb 08 peter 61
1106 19 Feb 08 peter 62     /**
1106 19 Feb 08 peter 63        Constructed Index c will satisfy c[i]=a[b[i]]
1106 19 Feb 08 peter 64      */
1106 19 Feb 08 peter 65     Index(const Index& a, const Index& b);
1106 19 Feb 08 peter 66
1106 19 Feb 08 peter 67     /**
1106 19 Feb 08 peter 68        \brief Constructor
1106 19 Feb 08 peter 69      */
1106 19 Feb 08 peter 70     explicit Index(const SmartPtr<const std::vector<size_t> >& vec);
1106 19 Feb 08 peter 71
1106 19 Feb 08 peter 72     /**
1134 23 Feb 08 peter 73        \brief Constructor
1134 23 Feb 08 peter 74
1134 23 Feb 08 peter 75        vec is copied
1134 23 Feb 08 peter 76      */
1134 23 Feb 08 peter 77     explicit Index(const std::vector<size_t>& vec);
1134 23 Feb 08 peter 78
1134 23 Feb 08 peter 79     /**
1528 24 Sep 08 peter 80        \return iterator pointing to first element of Index
1528 24 Sep 08 peter 81
1528 24 Sep 08 peter 82        \since New in yat 0.5
1528 24 Sep 08 peter 83      */
1528 24 Sep 08 peter 84     const_iterator begin(void) const;
1528 24 Sep 08 peter 85
1528 24 Sep 08 peter 86     /**
1528 24 Sep 08 peter 87        \return iterator pointing to element one passed last Index
1528 24 Sep 08 peter 88
1528 24 Sep 08 peter 89        \since New in yat 0.5
1528 24 Sep 08 peter 90      */
1528 24 Sep 08 peter 91     const_iterator end(void) const;
1528 24 Sep 08 peter 92
1528 24 Sep 08 peter 93     /**
1127 22 Feb 08 peter 94        \brief access operator
1127 22 Feb 08 peter 95     */
1127 22 Feb 08 peter 96     const size_t& operator[](size_t) const;
1106 19 Feb 08 peter 97
1106 19 Feb 08 peter 98     /**
1106 19 Feb 08 peter 99        \brief number of elements
1106 19 Feb 08 peter 100     */
1106 19 Feb 08 peter 101     size_t size(void) const;
1106 19 Feb 08 peter 102
1134 23 Feb 08 peter 103     /**
1134 23 Feb 08 peter 104        \return underlying vector
1134 23 Feb 08 peter 105     */
1134 23 Feb 08 peter 106     const std::vector<size_t>& vector(void) const;
1134 23 Feb 08 peter 107
1106 19 Feb 08 peter 108   private:
1106 19 Feb 08 peter 109     // using compiler generated copy
1106 19 Feb 08 peter 110     // Index(const Index&);
1106 19 Feb 08 peter 111     // const Index& operator=(const Index&);
1106 19 Feb 08 peter 112
1106 19 Feb 08 peter 113     SmartPtr<const std::vector<size_t> > index_;
1106 19 Feb 08 peter 114   };
1106 19 Feb 08 peter 115
1106 19 Feb 08 peter 116 }}} // of namespace utility, yat, and theplu
1106 19 Feb 08 peter 117
1106 19 Feb 08 peter 118 #endif