-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprinter.h
executable file
·105 lines (85 loc) · 2.74 KB
/
printer.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
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
//
// printer.h
//
// This file contains the interface for the Printer class and some
// functions that will be used by both the SM and QL components.
#ifndef _HELPER
#define _HELPER
#include <iostream>
#include <cstring>
#include "redbase.h" // For definition of MAXNAME
#define MAXPRINTSTRING ((2*MAXNAME) + 5)
//
// DataAttrInfo
//
// This struct stores the information that is kept within in
// attribute catalog. It identifies a relation name, attribute name
// and the location type and length of the attribute.
//
struct DataAttrInfo
{
// Default constructor
DataAttrInfo() {
memset(relName, 0, MAXNAME + 1);
memset(attrName, 0, MAXNAME + 1);
};
// Copy constructor
DataAttrInfo( const DataAttrInfo &d ) {
strcpy (relName, d.relName);
strcpy (attrName, d.attrName);
offset = d.offset;
attrType = d.attrType;
attrLength = d.attrLength;
indexNo = d.indexNo;
};
DataAttrInfo& operator=(const DataAttrInfo &d) {
if (this != &d) {
strcpy (relName, d.relName);
strcpy (attrName, d.attrName);
offset = d.offset;
attrType = d.attrType;
attrLength = d.attrLength;
indexNo = d.indexNo;
}
return (*this);
};
char relName[MAXNAME+1]; // Relation name
char attrName[MAXNAME+1]; // Attribute name
int offset; // Offset of attribute
AttrType attrType; // Type of attribute
int attrLength; // Length of attribute
int indexNo; // Index number of attribute
};
// Print some number of spaces
void Spaces(int maxLength, int printedSoFar);
class Printer {
public:
// Constructor. Takes as arguments an array of attributes along with
// the length of the array.
Printer(const DataAttrInfo *attributes, const int attrCount);
~Printer();
void PrintHeader(std::ostream &c) const;
// Two flavors for the Print routine. The first takes a char* to the
// data and is useful when the data corresponds to a single record in
// a table -- since in this situation you can just send in the
// RecData. The second will be useful in the QL layer.
void Print(std::ostream &c, const char * const data);
void Print(std::ostream &c, const void * const data[]);
void PrintFooter(std::ostream &c) const;
private:
DataAttrInfo *attributes;
int attrCount;
// An array of strings for the header information
char **psHeader;
// Number of spaces between each attribute
int *spaces;
// The number of tuples printed
int iCount;
};
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#endif