~ubuntu-branches/ubuntu/oneiric/mpqc/oneiric

« back to all changes in this revision

Viewing changes to src/lib/util/container/artem.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2005-11-27 11:41:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127114149-zgz9r3gk50w8ww2q
Tags: 2.3.0-1
* New upstream release.
* debian/rules (SONAME): Activate awk snippet for automatic so-name
  detection again, resulting in a bump to `7' and making a `c2a' for
  the C++ allocator change unnecessary; closes: #339232.
* debian/patches/00list (08_gcc-4.0_fixes): Removed, no longer needed.
* debian/rules (test): Remove workarounds, do not abort build if tests
  fail.
* debian/ref: Removed.
* debian/control.in (libsc): Added Conflict against libsc6c2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// artem.h --- template for the Array class
3
 
//
4
 
// Copyright (C) 1996 Limit Point Systems, Inc.
5
 
//
6
 
// Author: Curtis Janssen <cljanss@limitpt.com>
7
 
// Maintainer: LPS
8
 
//
9
 
// This file is part of the SC Toolkit.
10
 
//
11
 
// The SC Toolkit is free software; you can redistribute it and/or modify
12
 
// it under the terms of the GNU Library General Public License as published by
13
 
// the Free Software Foundation; either version 2, or (at your option)
14
 
// any later version.
15
 
//
16
 
// The SC Toolkit 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
19
 
// GNU Library General Public License for more details.
20
 
//
21
 
// You should have received a copy of the GNU Library General Public License
22
 
// along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
23
 
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
 
//
25
 
// The U.S. Government is granted a limited license as per AL 91-7.
26
 
//
27
 
 
28
 
#ifdef __GNUG__
29
 
#pragma implementation
30
 
#endif
31
 
 
32
 
namespace sc {
33
 
    
34
 
template <class Type>
35
 
class Array {
36
 
  protected:
37
 
    int _length;
38
 
    int _managed;
39
 
    Type * _array;
40
 
  public:
41
 
    Array():_length(0),_managed(0),_array(0) {}
42
 
    Array(const Array<Type>&a):_length(0),_managed(0),_array(0) {operator=(a);}
43
 
    Array(Type* data,int size):_length(size),_managed(0),_array(data){}
44
 
    Array(int size):_length(0),_managed(0),_array(0) { set_length(size); }
45
 
    ~Array() { clear(); }
46
 
    //int length() const { return _length; };
47
 
    int size() const { return _length; };
48
 
    void clear() { set_length(0); }
49
 
    void set_length(int size) {
50
 
        if (_array && _managed) delete[] _array;
51
 
        _managed = 1;
52
 
        if (size) _array = new Type [ size ];
53
 
        else _array = 0;
54
 
        _length = size;
55
 
      }
56
 
    void resize(int size) {
57
 
        Type*tmp=_array;
58
 
        if (size) _array = new Type [ size ];
59
 
        else _array = 0;
60
 
        int maxi;
61
 
        if (size < _length) maxi = size;
62
 
        else maxi = _length;
63
 
        for (int i=0; i<maxi; i++) _array[i] = tmp[i];
64
 
        if (_managed && tmp) delete[] tmp;
65
 
        _managed = 1;
66
 
        _length = size;
67
 
      }
68
 
    Array<Type>& operator = (const Array<Type> & s) {
69
 
        if (_managed && _array) delete[] _array;
70
 
        _managed = 1;
71
 
        _length = s._length;
72
 
        if (_length) _array = new Type [ _length ];
73
 
        else _array = 0;
74
 
        for (int i=0; i<_length; i++) {
75
 
            _array[i] = s._array[i];
76
 
          }
77
 
        return (*this);
78
 
      }
79
 
    Type& operator[] (int i) const {
80
 
        if (i<0 || i>=_length) {
81
 
            ExEnv::err0() << "Array::operator[](" << i << ") "
82
 
                 << "out of range (" << _length << "0" << std::endl;
83
 
            abort();
84
 
          };
85
 
        return _array[i];
86
 
      }
87
 
    Type& operator() (int i) const {
88
 
        if (i<0 || i>=_length) {
89
 
            ExEnv::err0() << "Array::operator()(" << i << ") "
90
 
                 << "out of range (" << _length << "0" << std::endl;
91
 
            abort();
92
 
          };
93
 
        return _array[i];
94
 
      }
95
 
    void push_back(const Type &d) {
96
 
        resize(_length+1);
97
 
        _array[_length-1] = d;
98
 
    }
99
 
    void pop_back() {
100
 
        resize(_length-1);
101
 
    }
102
 
};
103
 
 
104
 
}
105
 
 
106
 
// ///////////////////////////////////////////////////////////////////////////
107
 
 
108
 
// Local Variables:
109
 
// mode: c++
110
 
// c-file-style: "CLJ"
111
 
// End: