|
| 1 | +/* |
| 2 | + Copyright (c) 2017 TOSHIBA Digital Solutions Corporation. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#ifndef _FIELD_H_ |
| 18 | +#define _FIELD_H_ |
| 19 | + |
| 20 | +#include "gridstore.h" |
| 21 | +#include <iostream> |
| 22 | +#include <string.h> |
| 23 | + |
| 24 | +using namespace std; |
| 25 | + |
| 26 | +namespace griddb { |
| 27 | + |
| 28 | +struct Field { |
| 29 | + GSChar *name; |
| 30 | + GSType type; |
| 31 | + GSValue value; |
| 32 | + Field() : name(NULL), type(GS_TYPE_STRING) { |
| 33 | + memset(&value, 0, sizeof(GSValue)); |
| 34 | + }; |
| 35 | + |
| 36 | + ~Field() { |
| 37 | + switch (type){ |
| 38 | + case GS_TYPE_STRING: |
| 39 | + if (value.asString) { |
| 40 | + free(const_cast<GSChar*>(value.asString)); |
| 41 | + value.asString = NULL; |
| 42 | + } |
| 43 | + break; |
| 44 | + case GS_TYPE_BLOB: |
| 45 | + if (value.asBlob.data) { |
| 46 | + free(const_cast<void*>(value.asBlob.data)); |
| 47 | + value.asBlob.data = NULL; |
| 48 | + } |
| 49 | + break; |
| 50 | + case GS_TYPE_INTEGER_ARRAY: |
| 51 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 52 | + if (value.asIntegerArray.elements) { |
| 53 | + free(const_cast<int32_t*> (value.asIntegerArray.elements)); |
| 54 | + } |
| 55 | +#else |
| 56 | + if (value.asArray.elements.asInteger) { |
| 57 | + free(const_cast<int32_t*> (value.asArray.elements.asInteger)); |
| 58 | + } |
| 59 | +#endif |
| 60 | + break; |
| 61 | + case GS_TYPE_STRING_ARRAY: |
| 62 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 63 | + if (value.asStringArray.elements) { |
| 64 | + for (int j = 0; j < value.asStringArray.size; j++) { |
| 65 | + if (value.asStringArray.elements[j]) { |
| 66 | + free(const_cast<GSChar*> (value.asStringArray.elements[j])); |
| 67 | + } |
| 68 | + } |
| 69 | + free(const_cast<GSChar**> (value.asStringArray.elements)); |
| 70 | + } |
| 71 | +#else |
| 72 | + if (value.asArray.elements.asString) { |
| 73 | + for (int j = 0; j < value.asArray.length; j++) { |
| 74 | + if (value.asArray.elements.asString[j]) { |
| 75 | + free(const_cast<GSChar*> (value.asArray.elements.asString[j])); |
| 76 | + } |
| 77 | + } |
| 78 | + free(const_cast<GSChar**> (value.asArray.elements.asString)); |
| 79 | + } |
| 80 | +#endif |
| 81 | + break; |
| 82 | + case GS_TYPE_BOOL_ARRAY: |
| 83 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 84 | + if (value.asBoolArray.elements) { |
| 85 | + free(const_cast<GSBool*> (value.asBoolArray.elements)); |
| 86 | + } |
| 87 | +#else |
| 88 | + if (value.asArray.elements.asBool) { |
| 89 | + free(const_cast<GSBool*> (value.asArray.elements.asBool)); |
| 90 | + } |
| 91 | +#endif |
| 92 | + break; |
| 93 | + case GS_TYPE_BYTE_ARRAY: |
| 94 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 95 | + if (value.asByteArray.elements) { |
| 96 | + free(const_cast<int8_t*> (value.asByteArray.elements)); |
| 97 | + value.asByteArray.elements = NULL; |
| 98 | + } |
| 99 | +#else |
| 100 | + if (value.asArray.elements.asByte) { |
| 101 | + free(const_cast<int8_t*> (value.asArray.elements.asByte)); |
| 102 | + value.asArray.elements.asByte = NULL; |
| 103 | + } |
| 104 | +#endif |
| 105 | + break; |
| 106 | + case GS_TYPE_SHORT_ARRAY: |
| 107 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 108 | + if (value.asShortArray.elements) { |
| 109 | + free(const_cast<int16_t*> (value.asShortArray.elements)); |
| 110 | + } |
| 111 | +#else |
| 112 | + if (value.asArray.elements.asShort) { |
| 113 | + free(const_cast<int16_t*> (value.asArray.elements.asShort)); |
| 114 | + } |
| 115 | +#endif |
| 116 | + break; |
| 117 | + case GS_TYPE_LONG_ARRAY: |
| 118 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 119 | + if (value.asLongArray.elements) { |
| 120 | + free(const_cast<int64_t*> (value.asLongArray.elements)); |
| 121 | + } |
| 122 | +#else |
| 123 | + if (value.asArray.elements.asLong) { |
| 124 | + free(const_cast<int64_t*> (value.asArray.elements.asLong)); |
| 125 | + } |
| 126 | +#endif |
| 127 | + break; |
| 128 | + case GS_TYPE_FLOAT_ARRAY: |
| 129 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 130 | + if (value.asFloatArray.elements) { |
| 131 | + free(const_cast<float*> (value.asFloatArray.elements)); |
| 132 | + } |
| 133 | +#else |
| 134 | + if (value.asArray.elements.asFloat) { |
| 135 | + free(const_cast<float*> (value.asArray.elements.asFloat)); |
| 136 | + } |
| 137 | +#endif |
| 138 | + break; |
| 139 | + case GS_TYPE_DOUBLE_ARRAY: |
| 140 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 141 | + if (value.asDoubleArray.elements) { |
| 142 | + free(const_cast<double*> (value.asDoubleArray.elements)); |
| 143 | + } |
| 144 | +#else |
| 145 | + if (value.asArray.elements.asDouble) { |
| 146 | + free(const_cast<double*> (value.asArray.elements.asDouble)); |
| 147 | + } |
| 148 | +#endif |
| 149 | + break; |
| 150 | + case GS_TYPE_TIMESTAMP_ARRAY: |
| 151 | +#if GS_COMPATIBILITY_VALUE_1_1_106 |
| 152 | + if (value.asTimestampArray.elements) { |
| 153 | + free(const_cast<GSTimestamp*> (value.asTimestampArray.elements)); |
| 154 | + } |
| 155 | +#else |
| 156 | + if (value.asArray.elements.asTimestamp) { |
| 157 | + free(const_cast<GSTimestamp*> (value.asArray.elements.asTimestamp)); |
| 158 | + } |
| 159 | +#endif |
| 160 | + break; |
| 161 | + } |
| 162 | + } |
| 163 | +}; |
| 164 | + |
| 165 | +} |
| 166 | + |
| 167 | +#endif /* _FIELD_H_ */ |
0 commit comments