-
Notifications
You must be signed in to change notification settings - Fork 0
/
Record.h
65 lines (58 loc) · 1.98 KB
/
Record.h
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
//////////////////////////////////////////////////////////////////////////////
///
/// Record class:
/// @abstract Record is a "card" containing info fields about an item;
/// it reads and writes Records to binary files
///
/// @param the number of the fields in a Record as well as their length
/// are arbitrarily limited by the static private consts (20 atm)
/// @param formatting of a Record output is setw to the max field length,
/// fields are separated by |
///
/// @note uses concepts of reading and writing binary files using fstream,
///
//////////////////////////////////////////////////////////////////////////////
#ifndef RECORD_H
#define RECORD_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <vector>
using std::fstream;
using std::ostream;
using std::string;
using std::ios_base;
using std::cout;
using std::vector;
class Record {
typedef vector<string> vstr;
public:
Record() { // INLINED
for(size_t i=0; i<MAX_FIELDS_NUMBER; i++)
record[i][0] = '\0';
recno = -1;
}
Record(vstr fields) { // INLINED
for(size_t i=0; i<MAX_FIELDS_NUMBER; i++)
record[i][0] = '\0';
for(size_t i=0; i<fields.size(); i++)
strcpy(record[i], fields[i].c_str());
recno = -1;
}
// === MUTATORS === //
long long read(fstream& ins, long long recno);
void clear();
// === ACCESSORS === //
long long write(fstream& outs);
vstr get_fields() const;
bool is_empty() const;
friend ostream& operator<<(ostream& outs,
const Record& r);
private:
static const int MAX_FIELDS_NUMBER = 20;
static const int MAX_FIELD_SIZE = 20;
int recno;
char record[MAX_FIELDS_NUMBER][MAX_FIELD_SIZE];
};
#endif // RECORD_H