source: trunk/yat/utility/Index.h @ 1797

Last change on this file since 1797 was 1797, checked in by Peter, 15 years ago

updating copyright statements

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