UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
objectar.hpp
1 // objectar.hpp
2 // $Id: objectar.hpp,v 1.8 2007/10/23 13:50:45 guser1 Exp $
3 //-----------------------------------------------------------------------
4 #ifndef objectarH
5 #define objectarH
6 
7 #include <deque>
8 #include <vector>
9 #include <cassert>
10 
11 using namespace std;
12 
13 /*************************************************************
14  * Dynamic Array of any elements
15  *************************************************************/
16 template <class AnyType>
18 {
19 private:
20 
21  std::vector<AnyType> m_vData;
22 
23 public:
24 
25  objects_ar () {};
26  ~objects_ar() { clean();};
27 
28  AnyType& fetch (unsigned i) { assert(i < m_vData.size()); return m_vData[i]; };
29  AnyType get (unsigned i) const { assert(i < m_vData.size()); return m_vData[i]; };
30 
31  void insert (unsigned i, const AnyType val) { m_vData.insert(m_vData.begin() + i, val); };
32  void remove (unsigned i) {
33  assert(i >=0 && i < m_vData.size());
34  m_vData.erase(m_vData.begin()+i);
35  };
36  void exchange (unsigned i, unsigned j) {
37  assert(i >=0 && i < m_vData.size() && j >=0 && j < m_vData.size());
38  AnyType tmp=m_vData[i]; m_vData[i]=m_vData[j]; m_vData[j]=tmp;
39  };
40 
41 
42  void addh(const AnyType& val) { m_vData.push_back(val); };
43  void addhn(unsigned n) { m_vData.resize(m_vData.size()+n); };
44 
45  void clean() { m_vData.clear(); }
46  int count() const { return m_vData.size(); }
47 
48  AnyType& operator[] (unsigned i) { return fetch(i); };
49  AnyType operator() (unsigned i) const { return get(i); };
50 
51  std::vector<AnyType>& get_data() { return m_vData;}
52 };
53 
54 
55 class double_ar : public objects_ar<double> {};
56 class float_ar : public objects_ar<float> {};
57 class int_ar : public objects_ar<int> {};
58 
59 class bool_ar
60 {
61 private:
62 
63  std::deque<bool> m_vData;
64 
65 public:
66 
67  bool_ar () {};
68  ~bool_ar() {};
69 
70  bool& fetch (unsigned i) { assert(i < m_vData.size()); return m_vData[i]; };
71  bool get (unsigned i) const { assert(i < m_vData.size()); return m_vData[i]; };
72 
73  void insert (unsigned i, bool val) { m_vData.insert(m_vData.begin() + i, val); };
74  void addh(const bool& val) { m_vData.push_back(val); };
75  void addhn(unsigned n) { m_vData.resize(m_vData.size() + n); };
76 
77  void clean() { m_vData.clear(); }
78  int count() const { return m_vData.size(); }
79 
80  bool& operator[] (unsigned i) { return fetch(i); };
81  bool operator() (unsigned i) const { return get(i); };
82 
83  std::deque<bool>& get_data() { return m_vData;}
84 };
85 
86 #endif
Definition: objectar.hpp:59
Definition: objectar.hpp:57
Definition: objectar.hpp:55
Definition: objectar.hpp:56
Definition: objectar.hpp:17