00001
00002
00003
00004
00005
00006
00007
00008 #ifndef COMMON_H_
00009 #define COMMON_H_
00010
00016 #include <limits.h>
00017
00018 typedef unsigned int uint;
00019 typedef unsigned char uchar;
00020 typedef unsigned long ulong;
00021
00022 static const uint PF_PAGE_SIZE = 4096;
00023
00024 static const uint PF_BUFFER_SIZE = 40;
00025
00026 static const uint MAX_FILE_NAME = 255;
00027
00028
00029 static const uint MAX_STRING_LEN = 255;
00030
00031
00036 enum ReturnCode {
00037 RC_OK,
00038 RC_EOF,
00039 RC_PAGE_PINNED,
00040 RC_PAGE_NOT_IN_BUFFER,
00041 RC_PAGE_UNPINNED,
00042 RC_PAGE_FREE,
00043 RC_INVALID_PAGE,
00044 RC_FILE_OPEN,
00045 RC_CLOSED_FILE,
00046 RC_FILE_NOT_FOUND,
00047 RC_INVALID_ARGUMENT,
00048 RC_FILE_ALREADY_EXISTS,
00049 RC_PAGE_NOT_FOUND,
00050 RC_PAGE_NOT_DIRTY,
00051 RC_NOT_OPEN_FILE,
00052 RC_RECORD_TOO_LARGE,
00053 RC_RECORD_NOT_FOUND,
00054 RC_RECORD_ALREADY_IN_INDEX,
00055 RC_OUT_OF_MEMORY,
00056 RC_OUT_OF_BUFFER,
00057 RC_INCOMPLETE_READ,
00058 RC_INCOMPLETE_WRITE,
00059 RC_INCOMPLETE_HEADER_READ,
00060 RC_INCOMPLETE_HEADER_WRITE,
00061 RC_PAGE_IN_BUFFER,
00062 RC_INVALID_NAME,
00063 RC_UNIX,
00064 RC_CORRUPT_FILE,
00065 RC_FILE_TOO_BIG,
00066 RC_UNIMPLEMENTED,
00067 };
00068
00077 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
00078
00085 #define ARRAYSIZE(a) sizeof(a)/sizeof(a[0])
00086
00087
00091 enum AttributeType {
00092 INTEGER,
00093 FLOAT,
00094 STRING
00095 };
00096
00100 enum ComparisonOp {
00101 EQ_OP,
00102 LT_OP,
00103 GT_OP,
00104 LE_OP,
00105 GE_OP,
00106 NE_OP,
00107 NO_OP
00108 };
00109
00113 static const uint MAX_DATABASE_NAME = 32;
00117 static const uint MAX_RELATION_NAME = 32;
00121 static const uint MAX_ATTRIBUTE_NAME = 32;
00122
00126 struct AttributeInfo {
00127 char name[MAX_ATTRIBUTE_NAME];
00128 AttributeType type;
00129 int length;
00130 };
00131
00135 struct RelationAttributeInfo {
00136 char relName[MAX_RELATION_NAME];
00137 AttributeInfo attrInfo;
00138 };
00139
00143 struct RelationAttribute {
00144 char relName[MAX_RELATION_NAME];
00145 char attrName[MAX_ATTRIBUTE_NAME];
00146 };
00147
00154 struct TypedValue {
00155 AttributeType type;
00156 union {
00157 int value_i;
00158 float value_f;
00159 const char* value_str;
00160 };
00161 };
00162
00170 struct AttributeOrValue {
00171 bool isAttribute;
00172 union {
00173 RelationAttribute attribute;
00174 TypedValue value;
00175 };
00176 };
00177
00184 struct Condition {
00185 RelationAttribute left;
00186 ComparisonOp op;
00187 AttributeOrValue right;
00188 };
00189
00194 #define ATOMIC_DELETE(a) if (a != 0) { delete a; a = 0; }
00195
00200 #define ATOMIC_ARRAY_DELETE(a) if (a != 0) { delete[] a; a = 0; }
00201
00205 const char* OpToString(ComparisonOp op);
00206
00210 void printAttributeList(const RelationAttributeInfo* attributes, int count, bool includeTypes);
00211
00215 void printIndent(uint indent);
00216
00220 void printCondition(const Condition* condition);
00221
00225 void printValue(const TypedValue* value);
00226
00230 ComparisonOp reverse(ComparisonOp op);
00231
00232
00233
00234
00235
00236 #endif