-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathttxdata.hpp
114 lines (83 loc) · 3.14 KB
/
ttxdata.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
#include <boost/range/iterator_range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/iterator.hpp>
#include <boost/log/trivial.hpp>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <iostream>
#include <stdexcept>
#include <map>
#include <fstream>
#include <assert.h>
#include <array>
#include <mutex>
typedef std::array <uint8_t, 40> ttxLineData;
#define LINES_PER_FIELD 10
#define FIELDS_PER_BUFFER 1000
#define LINES_PER_BUFFER LINES_PER_FIELD * FIELDS_PER_BUFFER
class ttxLine {
private:
public:
ttxLineData data;
// TODO: Can this be changed to ttxLineData *
const uint8_t * get_line() const;
friend std::istream& operator >>(std::istream & sb, ttxLine &line);
friend void operator >>(std::string & sb, ttxLine &line);
uint8_t &operator[](unsigned int i);
};
typedef uint8_t ttxLineNumber;
typedef std::shared_ptr<ttxLine> ttxLine_p;
typedef std::map<ttxLineNumber, ttxLine_p> ttxPageLines;
class ttxPageAddress {
private:
int magazine;
int page_number;
void parse_address(const std::string & addr_str);
public:
friend std::ostream & operator<<(std::ostream &os, const ttxPageAddress& p);
std::string to_str() const;
const int get_page_number() const;
const int get_magazine() const;
const int to_int() const;
bool operator< (const ttxPageAddress & addr) const;
ttxPageAddress(const std::string & addr_str);
};
typedef std::shared_ptr<ttxPageAddress> ttxPageAddress_p;
typedef std::vector<ttxPageAddress_p> ttxPageAddress_vector;
class ttxPage {
private:
public:
ttxPageLines lines;
ttxLine_p get_line(ttxLineNumber line_num);
ttxLine_p get_line(int index);
ttxLine_p new_line(ttxLineNumber line_num);
ttxLine_p &operator[](ttxLineNumber i);
};
typedef std::shared_ptr<ttxPage> ttxPage_p;
typedef std::map<ttxPageAddress, ttxPage_p> ttxPageEntry_map;
typedef std::pair<ttxPageAddress, ttxPage_p> ttxPageEntry;
typedef std::shared_ptr<ttxPageEntry> ttxPageEntry_p;
typedef std::pair<ttxLineNumber, ttxLine_p> ttxNumberedLine;
typedef std::shared_ptr<ttxNumberedLine> ttxNumberedLine_p;
class ttxDatastore {
private:
ttxDatastore();
ttxPageEntry_map page_list;
ttxPageEntry_map::iterator page_list_iterator;
std::mutex global_lock;
public:
typedef std::shared_ptr<ttxDatastore> pointer;
static ttxDatastore * get_instance();
ttxDatastore(const ttxDatastore&) = delete;
ttxDatastore& operator=(const ttxDatastore&) = delete;
void update_page_line(const ttxPageAddress & addr,
const ttxLineNumber & line_num,
const ttxLineData & line_data);
ttxPage_p get_page(const ttxPageAddress & addr);
void attach(const ttxPageEntry & new_page);
ttxPageEntry get_next_page_entry();
ttxPageEntry_p operator*();
ttxPageEntry_p operator++(int);
};