-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenericSampleSet.hpp
77 lines (61 loc) · 1.45 KB
/
GenericSampleSet.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef genomic_GenericSampleSet_h
#define genomic_GenericSampleSet
#include <algorithm>
#include <stdexcept>
#include "SampleSet.hpp"
#include "RawSampleSet.hpp"
#include "SegmentedSampleSet.hpp"
//template <typename V> class SegmentedSampleSet;
//template <typename V> class RawSampleSet;
// Generic sample set, chooses appropriately between possible types of sample set
// Use handle-body idiom
class GenericSampleSet : public SampleSet
{
public:
typedef SampleSet Base;
private:
// body representation
// N.B. can only point to derived classes of SampleSet other than this class
SampleSet* rep;
SampleSet* clone() const {
return new GenericSampleSet(*this);
}
void _read(fstream& file);
void _write(fstream& file);
public:
GenericSampleSet() : rep(NULL) {}
GenericSampleSet(const GenericSampleSet& other)
: rep(other.clone()) {}
GenericSampleSet& operator= (GenericSampleSet other) {
// pass other by value to automatically create temporary copy
std::swap(rep, other.rep);
}
~GenericSampleSet() {
clear();
}
void clear() {
delete rep;
rep = NULL;
}
void sort() {
if (rep != NULL) {
rep->sort();
}
}
data::Type type() {
return data::generic;
}
size_t size() {
if (rep != NULL) {
return rep->size();
}
return 0;
}
};
class invalid_conversion : public std::logic_error
{
public:
explicit invalid_conversion(const string& what_arg)
: std::logic_error("Invalid conversion. " + what_arg) {}
};
#endif