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

Last change on this file since 1746 was 1746, checked in by Peter, 14 years ago

Merged patch release 0.4.3 to the trunk. Delta 0.4.3 - 0.4.2.

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