source: trunk/yat/utility/Index.cc @ 1106

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

Fixes #316 - Index class

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1// $Id: Index.cc 1106 2008-02-19 04:28:42Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://trac.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Index.h"
25
26namespace theplu {
27namespace yat {
28namespace utility { 
29
30  Index::Index(void)
31    : index_(SmartPtr<const std::vector<size_t> >(new std::vector<size_t>))
32  {}
33
34
35  Index::Index(size_t n)
36  {
37    std::vector<size_t>* vec = new std::vector<size_t>;
38    vec->reserve(n);
39    for (size_t i=0; i<n; ++i)
40      vec->push_back(i);
41    index_ = SmartPtr<const std::vector<size_t> >(vec);
42  }
43
44
45  Index::Index(const SmartPtr<const std::vector<size_t> >& sp)
46    : index_(sp) {}
47
48
49  Index::Index(const Index& a, const Index& b)
50  {
51    std::vector<size_t>* vec = new std::vector<size_t>;
52    vec->reserve(b.size());
53    for (size_t i=0; i<b.size(); ++i)
54      vec->push_back(a[b[i]]);
55    index_ = SmartPtr<const std::vector<size_t> >(vec);
56  }
57
58
59  size_t Index::size(void) const
60  {
61    return index_->size();
62  }
63
64
65  const size_t& Index::operator[](size_t i) const
66  {
67    return (*index_)[i];
68  }
69
70}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.