forked from apache/cassandra-cpp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdse_line_string.hpp
More file actions
137 lines (106 loc) · 3.58 KB
/
dse_line_string.hpp
File metadata and controls
137 lines (106 loc) · 3.58 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
Copyright (c) DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef DATASTAX_ENTERPRISE_INTERNAL_LINE_STRING_HPP
#define DATASTAX_ENTERPRISE_INTERNAL_LINE_STRING_HPP
#include "dse.h"
#include "allocated.hpp"
#include "dse_serialization.hpp"
#include "string.hpp"
#include "wkt.hpp"
#include "external.hpp"
namespace datastax { namespace internal { namespace enterprise {
class LineString : public Allocated {
public:
LineString() { reset(); }
const Bytes& bytes() const { return bytes_; }
void reset() {
num_points_ = 0;
bytes_.clear();
bytes_.reserve(WKB_HEADER_SIZE + // Header
sizeof(cass_uint32_t) + // Num points
4 * sizeof(cass_double_t)); // Simplest linestring is 2 points
encode_header_append(WKB_GEOMETRY_TYPE_LINESTRING, bytes_);
encode_append(0u, bytes_);
}
void reserve(cass_uint32_t num_points) {
bytes_.reserve(WKB_HEADER_SIZE + sizeof(cass_uint32_t) +
2 * num_points * sizeof(cass_double_t));
}
void add_point(cass_double_t x, cass_double_t y) {
encode_append(x, bytes_);
encode_append(y, bytes_);
num_points_++;
}
CassError finish() {
if (num_points_ == 1) {
return CASS_ERROR_LIB_INVALID_STATE;
}
encode(num_points_, WKB_HEADER_SIZE, bytes_);
return CASS_OK;
}
datastax::String to_wkt() const;
private:
cass_uint32_t num_points_;
Bytes bytes_;
};
class LineStringIterator : public Allocated {
public:
LineStringIterator()
: num_points_(0)
, iterator_(NULL) {}
cass_uint32_t num_points() const { return num_points_; }
CassError reset_binary(const CassValue* value);
CassError reset_text(const char* text, size_t size);
CassError next_point(cass_double_t* x, cass_double_t* y) {
if (iterator_ == NULL) {
return CASS_ERROR_LIB_INVALID_STATE;
}
return iterator_->next_point(x, y);
}
private:
class Iterator : public Allocated {
public:
virtual ~Iterator() {}
virtual CassError next_point(cass_double_t* x, cass_double_t* y) = 0;
};
class BinaryIterator : public Iterator {
public:
BinaryIterator() {}
BinaryIterator(const cass_byte_t* points_begin, const cass_byte_t* points_end,
WkbByteOrder byte_order)
: position_(points_begin)
, points_end_(points_end)
, byte_order_(byte_order) {}
virtual CassError next_point(cass_double_t* x, cass_double_t* y);
private:
const cass_byte_t* position_;
const cass_byte_t* points_end_;
WkbByteOrder byte_order_;
};
class TextIterator : public Iterator {
public:
TextIterator() {}
TextIterator(const char* text, size_t size);
virtual CassError next_point(cass_double_t* x, cass_double_t* y);
private:
WktLexer lexer_;
};
cass_uint32_t num_points_;
Iterator* iterator_;
BinaryIterator binary_iterator_;
TextIterator text_iterator_;
};
}}} // namespace datastax::internal::enterprise
EXTERNAL_TYPE(datastax::internal::enterprise::LineString, DseLineString)
EXTERNAL_TYPE(datastax::internal::enterprise::LineStringIterator, DseLineStringIterator)
#endif