ReferenceVector.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2004 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Util/units/ReferenceVector.h
10 
11 #ifndef __ReferenceVector_h
12 #define __ReferenceVector_h
13 
14 #include "ReferenceAble.h"
15 #include <typeinfo>
16 #include <string>
17 
18 #ifdef _DEBUG
19 #include <iostream>
20 using namespace std;
21 #endif
22 
23 namespace Reference {
24 
26  template<class Type, bool active = true> class Vector
27  {
28 
29  public:
30 
32  Vector ()
33  { }
34 
36  Vector (const Vector& v)
37  { elements = v.elements; }
38 
40  ~Vector ()
41  { }
42 
44  Vector& operator = (const Vector& v)
45  { elements = v.elements; return *this; }
46 
48  Reference::To<Type,active>& operator [] (unsigned index)
49  { check (index); return elements[index]; }
50 
52  const Reference::To<Type,active>& operator [] (unsigned index) const
53  { check (index); return elements[index]; }
54 
56  void resize (unsigned n)
57  { elements.resize (n); }
58 
60  unsigned size () const
61  { return elements.size(); }
62 
63  private:
64 
66  std::vector< Reference::To<Type,active> > elements;
67 
69  void check (unsigned index) const
70  {
71  if (index >= elements.size())
72  throw Error (InvalidParam, "Reference::Vector::check",
73  "index=%u >= size=%u", index, elements.size());
74  }
75 
76  };
77 }
78 
79 #endif // #ifndef __ReferenceVector_h
80 
Contains two basic classes that simplify dynamic memory management.
Definition: HeapTracked.h:17
Vector.
Definition: Vector.h:22
A convenient exception handling class.
Definition: Error.h:54
Template class manages Reference::Able objects.
Definition: Reference.h:74
A smart pointer that gets invalidated when its target is destroyed.
Definition: ReferenceVector.h:31

Generated using doxygen 1.8.17