1
0

Field.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Field Class Prototypes
  8. --------------------------------------------------------------------------- */
  9. #ifndef __FIELD_H
  10. #define __FIELD_H
  11. #ifdef __ANDROID__
  12. #include <foundation/types.h> // TODO
  13. #else
  14. #include <bfc/platform/types.h>
  15. #endif
  16. class Table;
  17. #include <stdio.h>
  18. #define PUT_INT(y) data[pos]=(uint8_t)(y&255); data[pos+1]=(uint8_t)((y>>8)&255); data[pos+2]=(uint8_t)((y>>16)&255); data[pos+3]=(uint8_t)((y>>24)&255)
  19. #define GET_INT() (int)(data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  20. #define PUT_SHORT(y) data[pos]=(uint8_t)(y&255); data[pos+1]=(uint8_t)((y>>8)&255);
  21. #define GET_SHORT() (uint16_t)(data[pos]|(data[pos+1]<<8))
  22. #define PUT_PINT(y) data[*pos]=(uint8_t)(y&255); data[*pos+1]=(uint8_t)((y>>8)&255); data[*pos+2]=(uint8_t)((y>>16)&255); data[*pos+3]=(uint8_t)((y>>24)&255)
  23. extern float GET_FLOAT(const uint8_t *data, size_t pos);
  24. extern void PUT_FLOAT(float f, uint8_t *data, size_t pos);
  25. extern void PUT_BINARY(uint8_t *dest, const uint8_t *src, size_t size, size_t pos);
  26. extern void GET_BINARY(uint8_t *dest, const uint8_t *src, size_t size, size_t pos);
  27. #define PUT_CHAR(y) data[pos]=y
  28. #define GET_CHAR() data[pos]
  29. #define CHECK_CHAR(l) { if (l < 1) return; l--; }
  30. #define CHECK_INT(l) { if (l < 4) return; l-=4; }
  31. #define CHECK_INT64(l) { if (l < 8) return; l-=8; }
  32. #define CHECK_SHORT(l) { if (l < 2) return; l-=2; }
  33. #define CHECK_BIN(l, size) { if (l < size) return; l-=size; }
  34. #ifdef ASSERT
  35. #undef ASSERT
  36. #endif
  37. #define ASSERT(x) { \
  38. if (!(x)) \
  39. OutputDebugString("Assertion failed "); \
  40. }
  41. #define _CHECK_CHAR(l) { ASSERT(l >= 1); l-=1; }
  42. #define _CHECK_INT(l) { ASSERT(l >= 4); l-=4; }
  43. #define _CHECK_SHORT(l) { ASSERT(l >= 2); l-=2; }
  44. #define _CHECK_BIN(l, size) { ASSERT(l >= size); l-=size; }
  45. class Field //: public wa::lists::node_ptr
  46. {
  47. public:
  48. Field();
  49. virtual ~Field();
  50. virtual Field *Clone(Table *pTable);
  51. unsigned char GetFieldId(void)
  52. {
  53. return ID;
  54. }
  55. int GetType();
  56. size_t GetTotalSize();
  57. Field(int FieldPos);
  58. Field *ReadField(Table *pTable, int pos, uint32_t *next_position=0);
  59. Field *ReadField(Table *pTable, int pos, bool readTyped, uint32_t *next_position=0);
  60. void WriteField(Table *pTable, Field *previous_field, Field *next_field);
  61. virtual void ReadTypedData(const uint8_t *, size_t /*len*/) { };
  62. virtual void WriteTypedData(uint8_t *, size_t) { };
  63. virtual size_t GetDataSize(void)
  64. {
  65. return 0;
  66. }
  67. virtual int Compare(Field * /*Entry*/)
  68. {
  69. return 0;
  70. }
  71. virtual int Starts(Field * /*Entry*/)
  72. {
  73. return 0;
  74. }
  75. virtual int Contains(Field * /*Entry*/)
  76. {
  77. return 0;
  78. }
  79. virtual bool ApplyFilter(Field * /*Data*/, int /*flags*/)
  80. {
  81. return false;
  82. }
  83. uint32_t GetFieldPos(void);
  84. void InitField(void);
  85. union
  86. {
  87. struct
  88. {
  89. uint8_t ID;
  90. uint8_t Type;
  91. };
  92. uint32_t _dummy_union_thingy;
  93. };
  94. protected:
  95. uint32_t Pos;
  96. uint32_t MaxSizeOnDisk;
  97. };
  98. #endif