Last change
on this file was
7623,
checked in by westram, 14 years ago
|
- merge from dev [7450] [7452] [7456] [7457] [7458] [7459] [7460] [7461] [7464] [7465] [7466] [7467] [7468] [7469] [7482]
- tweaked compiler options
- activated -Weffc++
- postfilter warnings where Scott Meyers' advices are too general.
- base classes should not always have virtual destructors, since that renders tiny classes useless and
- members should not always be initialized via initialization list, since that often violates the DRY principle
- fix gcc's inability to detect that Noncopyable implements a private copy-ctor and op=
- this slows down complete ARB recompilation by ~5%
- added -Wold-style-cast (inactive)
- removed -Wno-non-template-friend added in [7447]
- postcompile.pl
- added option —original to show unmodified compiler output
- declared op= for classes which had a copy-ctor
- moved op= macros to arbtools.h
- derived classes containing pointers from Noncopyable (use Noncopyable virtually) or
- made them copyable if needed (awt_mask_item, KnownDB, Code, AWT_registered_itemtype, GEN_gene, PosGene, PartialSequence, PlugIn, Range, Convaln_exception)
- other related changes
- mask destruction working now
|
File size:
1.7 KB
|
Line | |
---|
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 = NULL; |
---|
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: |
---|
56 | void reinit_refs() { INPLACE_RECONSTRUCT(Refs<REF>, &refs); } |
---|
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); } |
---|
64 | REF& get_new_ref() { resize_refs(get_refcount()+1); return get_latest_ref(); } |
---|
65 | }; |
---|
66 | |
---|
67 | #else |
---|
68 | #error refs.h included twice |
---|
69 | #endif // REFS_H |
---|
Note: See
TracBrowser
for help on using the repository browser.