开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (18)
标签 (41)
master
clickhouse
clickhouse-new-tmp
clickhouse-old-2021年12月22日
suppress-msan-2
master-old-2021年12月22日
nm/fix-uninitialized-memory
cmake-3-19
clickhouse-patch-leshikus2
update
boringssl
2.15.3
clickhouse_old_2.11
ssl-default-verify-paths
CPP-747-experiment
gh-pages
2.0
1.0
2.15.2
2.15.1
2.15.0
2.14.1
2.14.0
2.13.0
2.12.0
2.11.0
2.10.0
2.10.0-beta1
2.9.0
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
master
分支 (18)
标签 (41)
master
clickhouse
clickhouse-new-tmp
clickhouse-old-2021年12月22日
suppress-msan-2
master-old-2021年12月22日
nm/fix-uninitialized-memory
cmake-3-19
clickhouse-patch-leshikus2
update
boringssl
2.15.3
clickhouse_old_2.11
ssl-default-verify-paths
CPP-747-experiment
gh-pages
2.0
1.0
2.15.2
2.15.1
2.15.0
2.14.1
2.14.0
2.13.0
2.12.0
2.11.0
2.10.0
2.10.0-beta1
2.9.0
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (18)
标签 (41)
master
clickhouse
clickhouse-new-tmp
clickhouse-old-2021年12月22日
suppress-msan-2
master-old-2021年12月22日
nm/fix-uninitialized-memory
cmake-3-19
clickhouse-patch-leshikus2
update
boringssl
2.15.3
clickhouse_old_2.11
ssl-default-verify-paths
CPP-747-experiment
gh-pages
2.0
1.0
2.15.2
2.15.1
2.15.0
2.14.1
2.14.0
2.13.0
2.12.0
2.11.0
2.10.0
2.10.0-beta1
2.9.0
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
cpp-driver
/
src
/
dse_polygon.cpp
cpp-driver
/
src
/
dse_polygon.cpp
dse_polygon.cpp 10.08 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
/*
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.
*/
#include "dse_polygon.hpp"
#include "dse_validate.hpp"
#include <assert.h>
#include <iomanip>
#include <sstream>
using namespace datastax;
using namespace datastax::internal;
using namespace datastax::internal::core;
using namespace datastax::internal::enterprise;
extern "C" {
DsePolygon* dse_polygon_new() { return DsePolygon::to(new enterprise::Polygon()); }
void dse_polygon_free(DsePolygon* polygon) { delete polygon->from(); }
void dse_polygon_reset(DsePolygon* polygon) { polygon->reset(); }
void dse_polygon_reserve(DsePolygon* polygon, cass_uint32_t num_rings,
cass_uint32_t total_num_points) {
polygon->reserve(num_rings, total_num_points);
}
CassError dse_polygon_start_ring(DsePolygon* polygon) { return polygon->start_ring(); }
CassError dse_polygon_add_point(DsePolygon* polygon, cass_double_t x, cass_double_t y) {
polygon->add_point(x, y);
return CASS_OK;
}
CassError dse_polygon_finish(DsePolygon* polygon) { return polygon->finish(); }
DsePolygonIterator* dse_polygon_iterator_new() {
return DsePolygonIterator::to(new PolygonIterator());
}
CassError dse_polygon_iterator_reset(DsePolygonIterator* iterator, const CassValue* value) {
return iterator->reset_binary(value);
}
CassError dse_polygon_iterator_reset_with_wkt_n(DsePolygonIterator* iterator, const char* wkt,
size_t wkt_length) {
return iterator->reset_text(wkt, wkt_length);
}
CassError dse_polygon_iterator_reset_with_wkt(DsePolygonIterator* iterator, const char* wkt) {
return dse_polygon_iterator_reset_with_wkt_n(iterator, wkt, SAFE_STRLEN(wkt));
}
void dse_polygon_iterator_free(DsePolygonIterator* iterator) { delete iterator->from(); }
cass_uint32_t dse_polygon_iterator_num_rings(const DsePolygonIterator* iterator) {
return iterator->num_rings();
}
CassError dse_polygon_iterator_next_num_points(DsePolygonIterator* iterator,
cass_uint32_t* num_points) {
return iterator->next_num_points(num_points);
}
CassError dse_polygon_iterator_next_point(DsePolygonIterator* iterator, cass_double_t* x,
cass_double_t* y) {
return iterator->next_point(x, y);
}
} // extern "C"
String Polygon::to_wkt() const {
// Special case empty polygon
if (num_rings_ == 0) {
return "POLYGON EMPTY";
}
OStringStream ss;
ss.precision(WKT_MAX_DIGITS);
ss << "POLYGON (";
const cass_byte_t* pos = bytes_.data() + WKB_HEADER_SIZE + sizeof(cass_uint32_t);
for (cass_uint32_t i = 0; i < num_rings_; ++i) {
if (i > 0) ss << ", ";
ss << "(";
cass_uint32_t num_points = decode_uint32(pos, native_byte_order());
pos += sizeof(cass_uint32_t);
for (cass_uint32_t j = 0; j < num_points; ++j) {
if (j > 0) ss << ", ";
ss << decode_double(pos, native_byte_order());
pos += sizeof(cass_double_t);
ss << " ";
ss << decode_double(pos, native_byte_order());
pos += sizeof(cass_double_t);
}
ss << ")";
}
ss << ")";
return ss.str();
}
CassError PolygonIterator::reset_binary(const CassValue* value) {
size_t size;
const cass_byte_t* pos;
WkbByteOrder byte_order;
cass_uint32_t num_rings;
CassError rc = validate_data_type(value, DSE_POLYGON_TYPE);
if (rc != CASS_OK) return rc;
rc = cass_value_get_bytes(value, &pos, &size);
if (rc != CASS_OK) return rc;
if (size < WKB_POLYGON_HEADER_SIZE) {
return CASS_ERROR_LIB_NOT_ENOUGH_DATA;
}
size -= WKB_POLYGON_HEADER_SIZE;
if (decode_header(pos, &byte_order) != WKB_GEOMETRY_TYPE_POLYGON) {
return CASS_ERROR_LIB_INVALID_DATA;
}
pos += WKB_HEADER_SIZE;
num_rings = decode_uint32(pos, byte_order);
pos += sizeof(cass_uint32_t);
const cass_byte_t* rings = pos;
const cass_byte_t* rings_end = pos + size;
for (cass_uint32_t i = 0; i < num_rings; ++i) {
cass_uint32_t num_points;
if (size < sizeof(cass_uint32_t)) {
return CASS_ERROR_LIB_NOT_ENOUGH_DATA;
}
size -= sizeof(cass_uint32_t);
num_points = decode_uint32(pos, byte_order);
pos += sizeof(cass_uint32_t);
if (size < 2 * num_points * sizeof(cass_double_t)) {
return CASS_ERROR_LIB_NOT_ENOUGH_DATA;
}
size -= 2 * num_points * sizeof(cass_double_t);
}
num_rings_ = num_rings;
binary_iterator_ = BinaryIterator(rings, rings_end, byte_order);
iterator_ = &binary_iterator_;
return CASS_OK;
}
CassError PolygonIterator::reset_text(const char* text, size_t size) {
cass_uint32_t num_rings = 0;
const bool skip_numbers = true;
WktLexer lexer(text, size, skip_numbers);
if (lexer.next_token() != WktLexer::TK_TYPE_POLYGON) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
// Validate format and count the number of rings
WktLexer::Token token = lexer.next_token();
// Special case "POLYGON EMPTY"
if (token == WktLexer::TK_EMPTY) {
return CASS_OK;
}
if (token != WktLexer::TK_OPEN_PAREN) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
token = lexer.next_token();
while (token != WktLexer::TK_EOF && token != WktLexer::TK_CLOSE_PAREN) {
// Start ring
if (token != WktLexer::TK_OPEN_PAREN) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
// Consume points in ring
token = lexer.next_token();
while (token != WktLexer::TK_EOF && token != WktLexer::TK_CLOSE_PAREN) {
// First number in point
if (token != WktLexer::TK_NUMBER) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
// Second number in point
token = lexer.next_token();
if (token != WktLexer::TK_NUMBER) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
// Check and skip "," token
token = lexer.next_token();
if (token == WktLexer::TK_COMMA) {
token = lexer.next_token();
// Verify there are more points
if (token != WktLexer::TK_NUMBER) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
}
}
// End ring
if (token != WktLexer::TK_CLOSE_PAREN) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
++num_rings;
// Check and skip "," token
token = lexer.next_token();
if (token == WktLexer::TK_COMMA) {
token = lexer.next_token();
// Verify there are more rings
if (token != WktLexer::TK_OPEN_PAREN) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
}
}
// Validate closing ")"
if (token != WktLexer::TK_CLOSE_PAREN) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
num_rings_ = num_rings;
text_iterator_ = TextIterator(text, size);
iterator_ = &text_iterator_;
return CASS_OK;
}
CassError PolygonIterator::BinaryIterator::next_num_points(cass_uint32_t* num_points) {
if (state_ != STATE_NUM_POINTS) {
return CASS_ERROR_LIB_INVALID_STATE;
}
uint32_t n = *num_points = decode_uint32(position_, byte_order_);
position_ += sizeof(cass_uint32_t);
points_end_ = position_ + n * 2 * sizeof(cass_double_t);
state_ = STATE_POINTS;
return CASS_OK;
}
CassError PolygonIterator::BinaryIterator::next_point(cass_double_t* x, cass_double_t* y) {
if (state_ != STATE_POINTS) {
return CASS_ERROR_LIB_INVALID_STATE;
}
*x = decode_double(position_, byte_order_);
position_ += sizeof(cass_double_t);
*y = decode_double(position_, byte_order_);
position_ += sizeof(cass_double_t);
if (position_ >= rings_end_) {
state_ = STATE_DONE;
} else if (position_ >= points_end_) {
state_ = STATE_NUM_POINTS;
}
return CASS_OK;
}
PolygonIterator::TextIterator::TextIterator(const char* text, size_t size)
: state_(STATE_NUM_POINTS)
, lexer_(text, size) {
WktLexer::Token token;
UNUSED_(token);
// Skip over "POLYGON (" tokens
token = lexer_.next_token();
assert(token == WktLexer::TK_TYPE_POLYGON);
token = lexer_.next_token();
assert(token == WktLexer::TK_OPEN_PAREN);
}
CassError PolygonIterator::TextIterator::next_num_points(cass_uint32_t* num_points) {
WktLexer::Token token;
token = lexer_.next_token();
*num_points = 0;
// If we're at the end of the text this will return WktLexer::TK_EOF
if (state_ != STATE_NUM_POINTS || token != WktLexer::TK_OPEN_PAREN) {
return CASS_ERROR_LIB_INVALID_STATE;
}
const bool skip_numbers = true;
WktLexer temp(lexer_, skip_numbers); // Read forward using a temp lexer
token = temp.next_token();
while (token != WktLexer::TK_EOF && token != WktLexer::TK_CLOSE_PAREN) {
// First number in point
assert(token == WktLexer::TK_NUMBER);
// Second number in point
token = temp.next_token();
assert(token == WktLexer::TK_NUMBER);
++(*num_points);
// Check and skip "," token
token = temp.next_token();
if (token == WktLexer::TK_COMMA) {
token = temp.next_token();
assert(token == WktLexer::TK_NUMBER);
}
}
assert(token == WktLexer::TK_CLOSE_PAREN);
state_ = STATE_POINTS;
return CASS_OK;
}
CassError PolygonIterator::TextIterator::next_point(cass_double_t* x, cass_double_t* y) {
WktLexer::Token token;
if (state_ != STATE_POINTS) {
return CASS_ERROR_LIB_INVALID_STATE;
}
// First number in point
token = lexer_.next_token();
assert(token == WktLexer::TK_NUMBER);
*x = lexer_.number();
// Second number in point
token = lexer_.next_token();
assert(token == WktLexer::TK_NUMBER);
*y = lexer_.number();
token = lexer_.next_token();
if (token == WktLexer::TK_CLOSE_PAREN) {
// Done with this ring
token = lexer_.next_token();
if (token == WktLexer::TK_CLOSE_PAREN) {
// Done with last ring
state_ = STATE_DONE;
} else {
// More rings
assert(token == WktLexer::TK_COMMA);
state_ = STATE_NUM_POINTS;
}
} else {
// More points
assert(token == WktLexer::TK_COMMA);
}
return CASS_OK;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

cpp-driver加速
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cyys/cpp-driver.git
git@gitee.com:cyys/cpp-driver.git
cyys
cpp-driver
cpp-driver
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /