rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
vectorarray.hpp
Go to the documentation of this file.
1 
7 //===============================================
8 // Include Guards
9 #ifndef VECTORARRAY_H_INCLUDED
10 #define VECTORARRAY_H_INCLUDED
11 
12 //===============================================
13 // Levels of debuging Guards
14 #ifdef DEBUGLVL2 // All Debugging calls
15 #define DEBUGLVL1
16 #define TEST_ALL
17 #endif
18 
19 #ifdef DEBUGLVL1 // Debugging of new features.
20 
21 #endif
22 
23 //=================================
24 // forward declared dependencies
25 // class foo; //when you only need a pointer not the actual object
26 // and to avoid circular dependencies
27 
28 //=================================
29 // included dependencies
30 #include <fstream>
31 #include <iostream>
32 #include <vector>
33 
34 #include "warning.hpp"
35 
36 //==================================
37 // Code
38 // NOTE: function in a class definition are IMPLICITELY INLINED
39 // ie replaced by their code at compile time
40 
41 // Template Class
42 
50 template <class T> class ArrayVec
51 {
52  protected:
53  std::vector<std::vector<T>> elems;
54  std::vector<int> dim;
55 
56  public:
57  void assign(int nR, int nC, T newelem);
58  void size(int &nR, int &nC) const
59  {
60  nR = elems.size();
61  if (nR > 0)
62  {
63  nC = elems[0].size();
64  }
65  };
66  int size() const
67  {
68  return (elems.size());
69  }
70  void clear()
71  {
72  for (int ii = 0; ii < int(elems.size()); ii++)
73  {
74  elems[ii].clear();
75  }
76  elems.clear();
77  }
78  void write(std::ostream &streamout, const char *sep = ", ") const;
79  std::vector<T> &operator[](const int a)
80  {
81  // [] Operator returns a reference to the corresponding elems.
82 #ifdef SAFE_ACCESS // adds a check in debug mode
83  if (((a) >= int(elems.size())) | (0 > a))
84  {
85  std::cerr << "Error in " << __PRETTY_FUNCTION__ << std::endl;
86  RSVS3D_ERROR_RANGE(" : Index is out of range");
87  }
88 #endif // SAFE_ACCESS
89  return (elems[a]);
90  }
91 
92  const std::vector<T> &operator[](const int a) const
93  {
94  // [] Operator returns a reference to the corresponding elems.
95 #ifdef SAFE_ACCESS // adds a check in debug mode
96  if (((a) >= int(elems.size())) | (0 > a))
97  {
98  std::cerr << "Error in " << __PRETTY_FUNCTION__ << std::endl;
99  RSVS3D_ERROR_RANGE(" : Index is out of range");
100  }
101 #endif // SAFE_ACCESS
102  return (elems[a]);
103  }
104 
105  ~ArrayVec<T>()
106  {
107  clear();
108  }
109 };
110 
111 #include "vectorarray_incl.cpp"
112 
113 #endif // SNAKEVEL_H_INCLUDED
Template class for vector of vectors (matrix).
Definition: vectorarray.hpp:51
File for the implementation of the class template vectorarray this .cpp file is INCLUDED as part of v...
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_RANGE(M)
Throw a range_error.
Definition: warning.hpp:173