1
0

Int64Field.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Int64Field Class
  8. Field data layout:
  9. [8 bytes] value
  10. --------------------------------------------------------------------------- */
  11. #include "nde.h"
  12. #include "Int64Field.h"
  13. #include <time.h>
  14. //---------------------------------------------------------------------------
  15. Int64Field::Int64Field(int64_t Val)
  16. {
  17. InitField();
  18. Type = FIELD_INT64;
  19. Value = Val;
  20. }
  21. //---------------------------------------------------------------------------
  22. void Int64Field::InitField(void)
  23. {
  24. Type = FIELD_INT64;
  25. Value = 0;
  26. }
  27. //---------------------------------------------------------------------------
  28. Int64Field::Int64Field()
  29. {
  30. InitField();
  31. }
  32. //---------------------------------------------------------------------------
  33. Int64Field::~Int64Field()
  34. {
  35. }
  36. //---------------------------------------------------------------------------
  37. void Int64Field::ReadTypedData(const uint8_t *data, size_t len)
  38. {
  39. CHECK_INT64(len);
  40. Value = *((int64_t *)data);
  41. }
  42. //---------------------------------------------------------------------------
  43. void Int64Field::WriteTypedData(uint8_t *data, size_t len)
  44. {
  45. CHECK_INT64(len);
  46. *((int64_t *)data) = Value;
  47. }
  48. //---------------------------------------------------------------------------
  49. int64_t Int64Field::GetValue(void)
  50. {
  51. return Value;
  52. }
  53. //---------------------------------------------------------------------------
  54. void Int64Field::SetValue(int64_t Val)
  55. {
  56. Value = Val;
  57. }
  58. //---------------------------------------------------------------------------
  59. size_t Int64Field::GetDataSize(void)
  60. {
  61. return sizeof(int64_t);
  62. }
  63. //---------------------------------------------------------------------------
  64. int Int64Field::Compare(Field *Entry)
  65. {
  66. if (!Entry) return -1;
  67. return GetValue() < ((Int64Field*)Entry)->GetValue() ? -1 : (GetValue() > ((Int64Field*)Entry)->GetValue() ? 1 : 0);
  68. }
  69. //---------------------------------------------------------------------------
  70. bool Int64Field::ApplyFilter(Field *Data, int op)
  71. {
  72. bool r;
  73. switch (op)
  74. {
  75. case FILTER_EQUALS:
  76. r = Value == ((Int64Field *)Data)->GetValue();
  77. break;
  78. case FILTER_NOTEQUALS:
  79. r = Value != ((Int64Field *)Data)->GetValue();
  80. break;
  81. case FILTER_NOTCONTAINS:
  82. r = (bool)!(Value & ((Int64Field *)Data)->GetValue());
  83. break;
  84. case FILTER_CONTAINS:
  85. r = !!(Value & ((Int64Field *)Data)->GetValue());
  86. break;
  87. case FILTER_ABOVE:
  88. r = (bool)(Value > ((Int64Field *)Data)->GetValue());
  89. break;
  90. case FILTER_BELOW:
  91. r = (bool)(Value < ((Int64Field *)Data)->GetValue());
  92. break;
  93. case FILTER_BELOWOREQUAL:
  94. r = (bool)(Value <= ((Int64Field *)Data)->GetValue());
  95. break;
  96. case FILTER_ABOVEOREQUAL:
  97. r = (bool)(Value >= ((Int64Field *)Data)->GetValue());
  98. break;
  99. case FILTER_ISEMPTY:
  100. r = (Value == 0 || Value == -1);
  101. break;
  102. case FILTER_ISNOTEMPTY:
  103. r = !(Value == 0 || Value == -1);
  104. break;
  105. default:
  106. r = true;
  107. break;
  108. }
  109. return r;
  110. }