aboutsummaryrefslogtreecommitdiff
path: root/Src/nde/Int64Field.cpp
blob: e26e4f6ff2e2b42c5c4bfde4af102514bb9b56f3 (plain) (blame)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* ---------------------------------------------------------------------------
                           Nullsoft Database Engine
                             --------------------
                        codename: Near Death Experience
--------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------

 Int64Field Class
Field data layout:
[8 bytes] value
--------------------------------------------------------------------------- */

#include "nde.h"
#include "Int64Field.h"
#include <time.h>

//---------------------------------------------------------------------------
Int64Field::Int64Field(int64_t Val)
{
	InitField();
	Type = FIELD_INT64;
	Value = Val;
}

//---------------------------------------------------------------------------
void Int64Field::InitField(void)
{
	Type = FIELD_INT64;
	Value = 0;
}

//---------------------------------------------------------------------------
Int64Field::Int64Field()
{
	InitField();
}

//---------------------------------------------------------------------------
Int64Field::~Int64Field()
{
}

//---------------------------------------------------------------------------
void Int64Field::ReadTypedData(const uint8_t *data, size_t len)
{
	CHECK_INT64(len);
	Value = *((int64_t *)data);
}

//---------------------------------------------------------------------------
void Int64Field::WriteTypedData(uint8_t *data, size_t len)
{
	CHECK_INT64(len);
	*((int64_t *)data) = Value;
}

//---------------------------------------------------------------------------
int64_t Int64Field::GetValue(void)
{
	return Value;
}

//---------------------------------------------------------------------------
void Int64Field::SetValue(int64_t Val)
{
	Value = Val;
}

//---------------------------------------------------------------------------
size_t Int64Field::GetDataSize(void)
{
	return sizeof(int64_t);
}

//---------------------------------------------------------------------------
int Int64Field::Compare(Field *Entry)
{
	if (!Entry) return -1;
	return GetValue() < ((Int64Field*)Entry)->GetValue() ? -1 : (GetValue() > ((Int64Field*)Entry)->GetValue() ? 1 : 0);
}

//---------------------------------------------------------------------------
bool Int64Field::ApplyFilter(Field *Data, int op)
{
	bool r;
	switch (op)
	{
		case FILTER_EQUALS:
			r = Value == ((Int64Field *)Data)->GetValue();
			break;
		case FILTER_NOTEQUALS:
			r = Value != ((Int64Field *)Data)->GetValue();
			break;
		case FILTER_NOTCONTAINS:
			r = (bool)!(Value & ((Int64Field *)Data)->GetValue());
			break;
		case FILTER_CONTAINS:
			r = !!(Value & ((Int64Field *)Data)->GetValue());
			break;
		case FILTER_ABOVE:
			r = (bool)(Value > ((Int64Field *)Data)->GetValue());
			break;
		case FILTER_BELOW:
			r = (bool)(Value < ((Int64Field *)Data)->GetValue());
			break;
		case FILTER_BELOWOREQUAL:
			r = (bool)(Value <= ((Int64Field *)Data)->GetValue());
			break;
		case FILTER_ABOVEOREQUAL:
			r = (bool)(Value >= ((Int64Field *)Data)->GetValue());
			break;
		case FILTER_ISEMPTY:
			r = (Value == 0 || Value == -1);
			break;
		case FILTER_ISNOTEMPTY:
			r = !(Value == 0 || Value == -1);
			break;
		default:
			r = true;
			break;
	}
	return r;
}