forked from datastax/cpp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterator.cpp
145 lines (122 loc) · 4.29 KB
/
iterator.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
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
/*
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 "iterator.hpp"
#include "collection_iterator.hpp"
#include "external.hpp"
#include "map_iterator.hpp"
#include "result_iterator.hpp"
#include "row_iterator.hpp"
#include "user_type_field_iterator.hpp"
extern "C" {
void cass_iterator_free(CassIterator* iterator) {
delete iterator->from();
}
cass_bool_t cass_iterator_next(CassIterator* iterator) {
return static_cast<cass_bool_t>(iterator->from()->next());
}
CassIteratorType cass_iterator_type(CassIterator* iterator) {
return iterator->type();
}
CassIterator* cass_iterator_from_result(const CassResult* result) {
return CassIterator::to(new cass::ResultIterator(result));
}
CassIterator* cass_iterator_from_row(const CassRow* row) {
return CassIterator::to(new cass::RowIterator(row));
}
CassIterator* cass_iterator_from_collection(const CassValue* value) {
if (value->is_null() || !value->is_collection()) {
return NULL;
}
return CassIterator::to(new cass::CollectionIterator(value));
}
CassIterator* cass_iterator_from_tuple(const CassValue* value) {
if (value->is_null() || !value->is_tuple()) {
return NULL;
}
return CassIterator::to(new cass::TupleIterator(value));
}
CassIterator* cass_iterator_from_map(const CassValue* value) {
if (value->is_null() || !value->is_map()) {
return NULL;
}
return CassIterator::to(new cass::MapIterator(value));
}
CassIterator* cass_iterator_fields_from_user_type(const CassValue* value) {
if (value->is_null() || !value->is_user_type()) {
return NULL;
}
return CassIterator::to(new cass::UserTypeFieldIterator(value));
}
CassError cass_iterator_get_user_type_field_name(const CassIterator* iterator,
const char** name,
size_t* name_length) {
if (iterator->type() != CASS_ITERATOR_TYPE_USER_TYPE_FIELD) {
return CASS_ERROR_LIB_BAD_PARAMS;
}
cass::StringRef field_name
= static_cast<const cass::UserTypeFieldIterator*>(
iterator->from())->field_name();
*name = field_name.data();
*name_length = field_name.size();
return CASS_OK;
}
const CassValue* cass_iterator_get_user_type_field_value(const CassIterator* iterator) {
if (iterator->type() != CASS_ITERATOR_TYPE_USER_TYPE_FIELD) {
return NULL;
}
return CassValue::to(
static_cast<const cass::UserTypeFieldIterator*>(
iterator->from())->field_value());
}
const CassRow* cass_iterator_get_row(const CassIterator* iterator) {
if (iterator->type() != CASS_ITERATOR_TYPE_RESULT) {
return NULL;
}
return CassRow::to(
static_cast<const cass::ResultIterator*>(
iterator->from())->row());
}
const CassValue* cass_iterator_get_column(const CassIterator* iterator) {
if (iterator->type() != CASS_ITERATOR_TYPE_ROW) {
return NULL;
}
return CassValue::to(
static_cast<const cass::RowIterator*>(
iterator->from())->column());
}
const CassValue* cass_iterator_get_value(const CassIterator* iterator) {
if (iterator->type() != CASS_ITERATOR_TYPE_COLLECTION &&
iterator->type() != CASS_ITERATOR_TYPE_TUPLE) {
return NULL;
}
return CassValue::to(
static_cast<const cass::ValueIterator*>(
iterator->from())->value());
}
const CassValue* cass_iterator_get_map_key(const CassIterator* iterator) {
if (iterator->type() != CASS_ITERATOR_TYPE_MAP) {
return NULL;
}
return CassValue::to(
static_cast<const cass::MapIterator*>(
iterator->from())->key());
}
const CassValue* cass_iterator_get_map_value(const CassIterator* iterator) {
if (iterator->type() != CASS_ITERATOR_TYPE_MAP) {
return NULL;
}
return CassValue::to(
static_cast<const cass::MapIterator*>(
iterator->from())->value());
}
} // extern "C"