ARB
refs.h
Go to the documentation of this file.
1 #ifndef REFS_H
2 #define REFS_H
3 
4 #ifndef INPUT_FORMAT_H
5 #include "input_format.h"
6 #endif
7 #ifndef RDP_INFO_H
8 #include "rdp_info.h"
9 #endif
10 
11 template <typename REF>
12 class Refs : virtual Noncopyable {
13  REF *ref;
14  int size;
15 public:
16  Refs() {
17  ref = NULp;
18  size = 0;
19  }
20  ~Refs() {
21  delete [] ref;
22  }
23 
24  void resize(int new_size) {
25  ca_assert(new_size >= size);
26  if (new_size>size) {
27  REF *new_ref = new REF[new_size];
28  for (int i = 0; i<size; ++i) {
29  new_ref[i] = ref[i];
30  }
31  delete [] ref;
32  ref = new_ref;
33  size = new_size;
34  }
35  }
36 
37  int get_count() const { return size; }
38 
39  const REF& get_ref(int num) const {
40  ca_assert(num >= 0);
41  ca_assert(num < get_count());
42  return ref[num];
43  }
44  REF& get_ref(int num) {
45  ca_assert(num >= 0);
46  ca_assert(num < get_count());
47  return ref[num];
48  }
49 };
50 
51 template<typename REF>
52 class RefContainer {
53  Refs<REF> refs;
54 
55 public:
57  void resize_refs(int new_size) { refs.resize(new_size); }
58  int get_refcount() const { return refs.get_count(); }
59  bool has_refs() const { return get_refcount() > 0; }
60  const REF& get_ref(int num) const { return refs.get_ref(num); }
61  const REF& get_latest_ref() const { return get_ref(get_refcount()-1); }
62  REF& get_ref(int num) { return refs.get_ref(num); }
63  REF& get_latest_ref() { return get_ref(get_refcount()-1); }
65 };
66 
67 #else
68 #error refs.h included twice
69 #endif // REFS_H
bool has_refs() const
Definition: refs.h:59
#define ca_assert(cond)
Definition: global.h:33
Definition: refs.h:12
#define INPLACE_RECONSTRUCT(type, this)
Definition: arbtools.h:49
REF & get_latest_ref()
Definition: refs.h:63
const REF & get_ref(int num) const
Definition: refs.h:39
REF & get_ref(int num)
Definition: refs.h:44
const REF & get_ref(int num) const
Definition: refs.h:60
const REF & get_latest_ref() const
Definition: refs.h:61
int get_count() const
Definition: refs.h:37
REF & get_ref(int num)
Definition: refs.h:62
Refs()
Definition: refs.h:16
~Refs()
Definition: refs.h:20
#define NULp
Definition: cxxforward.h:116
REF & get_new_ref()
Definition: refs.h:64
void resize(int new_size)
Definition: refs.h:24
void reinit_refs()
Definition: refs.h:56
void resize_refs(int new_size)
Definition: refs.h:57
int get_refcount() const
Definition: refs.h:58