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

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

working on ticket:234

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: Index.cc 1126 2008-02-22 22:31:39Z 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 std::vector<size_t>& vec)
50    : index_(SmartPtr<const std::vector<size_t> >(new std::vector<size_t>(vec))) 
51  {}
52
53
54  Index::Index(const Index& a, const Index& b)
55  {
56    std::vector<size_t>* vec = new std::vector<size_t>;
57    vec->reserve(b.size());
58    for (size_t i=0; i<b.size(); ++i)
59      vec->push_back(a[b[i]]);
60    index_ = SmartPtr<const std::vector<size_t> >(vec);
61  }
62
63
64  size_t Index::size(void) const
65  {
66    return index_->size();
67  }
68
69
70  const std::vector<size_t>& Index::vector(void) const
71  {
72    return *index_;
73  }
74
75
76  const size_t& Index::operator[](size_t i) const
77  {
78    return (*index_)[i];
79  }
80
81}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.