-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtable.h
More file actions
77 lines (72 loc) · 2.15 KB
/
table.h
File metadata and controls
77 lines (72 loc) · 2.15 KB
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
// Header guard
#ifndef TABLE_H
#define TABLE_H
//
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <unordered_map>
#include <set>
#include <fstream>
class Table{
private:
std::string tableName;
std::string primaryKey;
int recordSize;
int totalSize;
int numOfRecords;
std::vector<std::string> columnNames;
std::map<std::string, std::string> columnTypesMap;
pthread_mutex_t m_lock;
pthread_mutex_t m_out;
std::set<int> lockedItems;
std::set<std::string> lockedItemsStr;
bool temporary;
bool dropped;
public :
Table(std::string tn, bool temp = false);
~Table();
void setPrimaryKey(std::string pk);
void setRecordSize(int size);
void incrementRecords();
void setTotalSize(int size);
void setNumOfRecords(int num);
void addColumn(std::string clmn);
void setColumnTypes(std::string columnName, std::string ctm);
void parseAndSetPrimaryKey(std::string pk);
void createTableFile();
std::ifstream* getiFile();
std::ofstream* getoFile(bool append=true);
void lockAppend();
void unlockAppend();
char* getNextRow(std::ifstream* ifs);
char* getNthRow(std::ifstream* ifs, int n);
std::string getRecordColumn(char* buffer, std::string col);
std::string getTableName();
std::string getPrimaryKey();
int getRecordSize();
int getTotalSize();
int getNumOfRecords();
std::vector<std::string> getColumnNames();
std::string getColumnType(std::string column);
std::string getColumnType(int i);
void print();
void setIfDropped(bool dropflag);
bool isTemporary();
bool isDropped();
std::string getFormattedMetaData();
std::string parseRecord(char* buffer, std::vector<std::string> fieldList);
bool updateRecord(std::string pk, char* buffer);
size_t getColumnByteSizeAt(int columnIndex);
size_t getColumnBytePosition(std::string clmn);
size_t getColumnByteSize(std::string);
size_t getIndexOfPrimaryKey();
bool isLocked(int rowpos_target, bool inside = false);
bool lock(int rowpos_target);
bool unlock(int rowpos_target);
bool isLocked(std::string rowpos_target, bool inside = false);
bool lock(std::string rowpos_target);
bool unlock(std::string rowpos_target);
};
#endif