annotate SMART/Java/Python/Cpp/interval.hpp @ 24:452e051f6562

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:28:24 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 #ifndef INTERVAL_HPP
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 #define INTERVAL_HPP
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 #include <iostream>
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 #include <fstream>
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 using namespace std;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 typedef unsigned int Position;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 class Interval {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 public:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 Position start;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 Position end;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 Interval(unsigned int start = 0, unsigned int end = 0): start(start), end(end) { }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 Interval(Interval &i): start(i.start), end(i.end) { }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 bool include(Interval &interval) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 return ((start <= interval.start) && (end >= interval.end));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 void writeBinary(ofstream &stream) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 stream.write(reinterpret_cast<const char*>(&start), sizeof(Position));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 stream.write(reinterpret_cast<const char*>(&end), sizeof(Position));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 bool parseBinary(ifstream &stream) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 stream.read(reinterpret_cast<char*>(&start), sizeof(Position));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 stream.read(reinterpret_cast<char*>(&end), sizeof(Position));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 return (! stream.eof());
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 friend bool operator==(const Interval &i1, const Interval &i2) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 return ((i1.start == i2.start) && (i1.start == i2.end));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 friend bool operator<(const Interval &i1, const Interval &i2) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 if (i1.start < i2.start) return true;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 return ((i1.start == i2.start) && (i1.end > i2.end));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 };
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 #endif