forked from griddb/griddb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry_processor.cpp
102 lines (93 loc) · 3.3 KB
/
geometry_processor.cpp
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
/*
Copyright (c) 2017 TOSHIBA Digital Solutions Corporation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
@file
@brief Implementation of GeometryProcessor
*/
#include "geometry_processor.h"
#include "util/time.h"
#include "gs_error.h"
#include "message_row_store.h"
#include "schema.h"
#include "value_operator.h"
#include "value_processor.h"
#include "gis_point.h"
/*!
@brief Compare message field value with object field value
*/
int32_t GeometryProcessor::compare(TransactionContext &txn, ObjectManager &,
ColumnId columnId, MessageRowStore *messageRowStore,
uint8_t *objectRowField) {
const uint8_t *inputField;
uint32_t inputFieldSize;
messageRowStore->getField(columnId, inputField, inputFieldSize);
inputField +=
ValueProcessor::getEncodedVarSize(inputFieldSize);
uint32_t objectRowFieldSize = ValueProcessor::decodeVarSize(objectRowField);
objectRowField += ValueProcessor::getEncodedVarSize(
objectRowFieldSize);
if (objectRowFieldSize == 0) {
objectRowField = NULL;
}
return compareBinaryBinary(
txn, inputField, inputFieldSize, objectRowField, objectRowFieldSize);
}
/*!
@brief Compare object field values
*/
int32_t GeometryProcessor::compare(TransactionContext &txn, ObjectManager &,
ColumnType, uint8_t *srcObjectRowField, uint8_t *targetObjectRowField) {
int32_t result;
uint32_t srcObjectRowFieldSize = 0;
if (srcObjectRowField) {
srcObjectRowFieldSize =
ValueProcessor::decodeVarSize(srcObjectRowField);
srcObjectRowField += ValueProcessor::getEncodedVarSize(
srcObjectRowFieldSize);
if (srcObjectRowFieldSize == 0) {
srcObjectRowField = NULL;
}
}
uint32_t targetObjectRowFieldSize = 0;
if (targetObjectRowField) {
targetObjectRowFieldSize =
ValueProcessor::decodeVarSize(targetObjectRowField);
targetObjectRowField += ValueProcessor::getEncodedVarSize(
targetObjectRowFieldSize);
if (targetObjectRowFieldSize == 0) {
targetObjectRowField = NULL;
}
}
result = compareBinaryBinary(txn, srcObjectRowField, srcObjectRowFieldSize,
targetObjectRowField, targetObjectRowFieldSize);
return result;
}
/*!
@brief Set field value to message
*/
void GeometryProcessor::getField(TransactionContext &txn, ObjectManager &,
ColumnId columnId, const Value *objectValue, MessageRowStore *messageRowStore) {
const uint8_t *image = objectValue->getImage();
if (image != NULL) {
uint32_t dataSize = objectValue->size();
messageRowStore->setField(columnId, image, dataSize);
}
else {
Point *geometry = ALLOC_NEW(txn.getDefaultAllocator()) Point(txn);
util::XArray<uint8_t> binary(txn.getDefaultAllocator());
Geometry::serialize(geometry, binary);
uint32_t size = static_cast<uint32_t>(binary.size());
messageRowStore->setFieldForRawData(columnId, binary.data(), size);
}
}