10 #include "common/datatypes/Date.h"
11 #include "common/datatypes/Duration.h"
12 #include "common/thrift/ThriftTypes.h"
17 template <
class T,
class U>
46 static const Value kEmpty;
47 static const Value kNullValue;
48 static const Value kNullNaN;
49 static const Value kNullBadData;
50 static const Value kNullBadType;
51 static const Value kNullOverflow;
52 static const Value kNullUnknownProp;
53 static const Value kNullDivByZero;
54 static const Value kNullOutOfRange;
56 static const uint64_t kEmptyNullType;
57 static const uint64_t kNumericType;
61 enum class Type : uint64_t {
77 GEOGRAPHY = 1UL << 15,
79 NULLVALUE = 1UL << 63,
83 Value() : type_(Type::__EMPTY__) {}
92 Value(
const std::nullptr_t) =
delete;
93 Value(
const NullType& v);
97 Value(
const int8_t& v);
99 Value(
const int16_t& v);
101 Value(
const int32_t& v);
103 Value(
const int64_t& v);
105 Value(
const double& v);
107 Value(
const std::string& v);
108 Value(std::string&& v);
109 Value(
const char* v);
138 Type type()
const noexcept {
142 const std::string& typeName()
const;
143 static const std::string toString(Type type);
146 return type_ == Type::__EMPTY__;
148 bool isNull()
const {
149 return type_ == Type::NULLVALUE;
151 bool isBadNull()
const {
155 auto&
null = value_.nVal;
156 return null == NullType::NaN ||
null == NullType::BAD_DATA ||
null == NullType::BAD_TYPE ||
157 null == NullType::ERR_OVERFLOW ||
null == NullType::UNKNOWN_PROP ||
158 null == NullType::DIV_BY_ZERO ||
null == NullType::OUT_OF_RANGE;
160 bool isNumeric()
const {
161 return type_ == Type::INT || type_ == Type::FLOAT;
163 bool isBool()
const {
164 return type_ == Type::BOOL;
167 return type_ == Type::INT;
169 bool isFloat()
const {
170 return type_ == Type::FLOAT;
173 return type_ == Type::STRING;
175 bool isDate()
const {
176 return type_ == Type::DATE;
178 bool isTime()
const {
179 return type_ == Type::TIME;
181 bool isDateTime()
const {
182 return type_ == Type::DATETIME;
184 bool isVertex()
const {
185 return type_ == Type::VERTEX;
187 bool isEdge()
const {
188 return type_ == Type::EDGE;
190 bool isPath()
const {
191 return type_ == Type::PATH;
193 bool isList()
const {
194 return type_ == Type::LIST;
197 return type_ == Type::MAP;
200 return type_ == Type::SET;
202 bool isDataSet()
const {
203 return type_ == Type::DATASET;
205 bool isGeography()
const {
206 return type_ == Type::GEOGRAPHY;
208 bool isDuration()
const {
209 return type_ == Type::DURATION;
221 void setNull(
const NullType& v);
222 void setNull(NullType&& v);
223 void setBool(
const bool& v);
224 void setBool(
bool&& v);
225 void setInt(
const int8_t& v);
226 void setInt(int8_t&& v);
227 void setInt(
const int16_t& v);
228 void setInt(int16_t&& v);
229 void setInt(
const int32_t& v);
230 void setInt(int32_t&& v);
231 void setInt(
const int64_t& v);
232 void setInt(int64_t&& v);
233 void setFloat(
const double& v);
234 void setFloat(
double&& v);
235 void setStr(
const std::string& v);
236 void setStr(std::string&& v);
237 void setStr(
const char* v);
238 void setDate(
const Date& v);
239 void setDate(
Date&& v);
240 void setTime(
const Time& v);
241 void setTime(
Time&& v);
242 void setDateTime(
const DateTime& v);
244 void setVertex(
const Vertex& v);
245 void setVertex(
Vertex&& v);
246 void setVertex(std::unique_ptr<Vertex>&& v);
247 void setEdge(
const Edge& v);
248 void setEdge(
Edge&& v);
249 void setEdge(std::unique_ptr<Edge>&& v);
250 void setPath(
const Path& v);
251 void setPath(
Path&& v);
252 void setPath(std::unique_ptr<Path>&& v);
253 void setList(
const List& v);
254 void setList(
List&& v);
255 void setList(std::unique_ptr<List>&& v);
256 void setMap(
const Map& v);
257 void setMap(
Map&& v);
258 void setMap(std::unique_ptr<Map>&& v);
259 void setSet(
const Set& v);
260 void setSet(
Set&& v);
261 void setSet(std::unique_ptr<Set>&& v);
262 void setDataSet(
const DataSet& v);
264 void setDataSet(std::unique_ptr<DataSet>&& v);
267 void setGeography(std::unique_ptr<Geography>&& v);
268 void setDuration(
const Duration& v);
270 void setDuration(std::unique_ptr<Duration>&& v);
272 const NullType& getNull()
const;
273 const bool& getBool()
const;
274 const int64_t& getInt()
const;
275 const double& getFloat()
const;
276 const std::string& getStr()
const;
277 const Date& getDate()
const;
278 const Time& getTime()
const;
279 const DateTime& getDateTime()
const;
280 const Vertex& getVertex()
const;
281 const Vertex* getVertexPtr()
const;
282 const Edge& getEdge()
const;
283 const Edge* getEdgePtr()
const;
284 const Path& getPath()
const;
285 const Path* getPathPtr()
const;
286 const List& getList()
const;
287 const List* getListPtr()
const;
288 const Map& getMap()
const;
289 const Map* getMapPtr()
const;
290 const Set& getSet()
const;
291 const Set* getSetPtr()
const;
292 const DataSet& getDataSet()
const;
293 const DataSet* getDataSetPtr()
const;
295 const Geography* getGeographyPtr()
const;
296 const Duration& getDuration()
const;
297 const Duration* getDurationPtr()
const;
303 std::string moveStr();
317 NullType& mutableNull();
319 int64_t& mutableInt();
320 double& mutableFloat();
321 std::string& mutableStr();
335 static const Value&
null() noexcept {
339 std::string toString()
const;
341 Value toBool()
const;
342 Value toFloat()
const;
357 std::unique_ptr<std::string> sVal;
361 std::unique_ptr<Vertex> vVal;
362 std::unique_ptr<Edge> eVal;
363 std::unique_ptr<Path> pVal;
364 std::unique_ptr<List> lVal;
365 std::unique_ptr<Map> mVal;
366 std::unique_ptr<Set> uVal;
367 std::unique_ptr<DataSet> gVal;
368 std::unique_ptr<Geography> ggVal;
369 std::unique_ptr<Duration> duVal;
376 void destruct(T& val) {
381 void setN(
const NullType& v);
382 void setN(NullType&& v);
384 void setB(
const bool& v);
387 void setI(
const int64_t& v);
388 void setI(int64_t&& v);
390 void setF(
const double& v);
391 void setF(
double&& v);
393 void setS(
const std::string& v);
394 void setS(std::string&& v);
395 void setS(
const char* v);
396 void setS(std::unique_ptr<std::string> v);
398 void setD(
const Date& v);
401 void setT(
const Time& v);
407 void setV(
const std::unique_ptr<Vertex>& v);
408 void setV(std::unique_ptr<Vertex>&& v);
409 void setV(
const Vertex& v);
412 void setE(
const std::unique_ptr<Edge>& v);
413 void setE(std::unique_ptr<Edge>&& v);
414 void setE(
const Edge& v);
417 void setP(
const std::unique_ptr<Path>& v);
418 void setP(std::unique_ptr<Path>&& v);
419 void setP(
const Path& v);
422 void setL(
const std::unique_ptr<List>& v);
423 void setL(std::unique_ptr<List>&& v);
424 void setL(
const List& v);
427 void setM(
const std::unique_ptr<Map>& v);
428 void setM(std::unique_ptr<Map>&& v);
429 void setM(
const Map& v);
432 void setU(
const std::unique_ptr<Set>& v);
433 void setU(std::unique_ptr<Set>&& v);
434 void setU(
const Set& v);
437 void setG(
const std::unique_ptr<DataSet>& v);
438 void setG(std::unique_ptr<DataSet>&& v);
442 void setGG(
const std::unique_ptr<Geography>& v);
443 void setGG(std::unique_ptr<Geography>&& v);
447 void setDU(
const std::unique_ptr<Duration>& v);
448 void setDU(std::unique_ptr<Duration>&& v);
453 static_assert(
sizeof(
Value) == 16UL,
"The size of Value should be 16UL");
457 constexpr
auto kEpsilon = 1e-8;
473 bool operator<(
const Value& lhs,
const Value& rhs);
474 bool operator==(
const Value& lhs,
const Value& rhs);
475 bool operator!=(
const Value& lhs,
const Value& rhs);
476 bool operator>(
const Value& lhs,
const Value& rhs);
477 bool operator<=(
const Value& lhs,
const Value& rhs);
478 bool operator>=(
const Value& lhs,
const Value& rhs);
487 std::ostream& operator<<(std::ostream& os,
const Value::Type& type);
488 inline std::ostream& operator<<(std::ostream& os,
const Value& value) {
489 return os << value.toString();
492 inline uint64_t operator|(
const Value::Type& lhs,
const Value::Type& rhs) {
493 return static_cast<uint64_t
>(lhs) |
static_cast<uint64_t
>(rhs);
495 inline uint64_t operator|(
const uint64_t lhs,
const Value::Type& rhs) {
496 return lhs |
static_cast<uint64_t
>(rhs);
498 inline uint64_t operator|(
const Value::Type& lhs,
const uint64_t rhs) {
499 return static_cast<uint64_t
>(lhs) | rhs;
501 inline uint64_t operator&(
const Value::Type& lhs,
const Value::Type& rhs) {
502 return static_cast<uint64_t
>(lhs) &
static_cast<uint64_t
>(rhs);
504 inline uint64_t operator&(
const uint64_t lhs,
const Value::Type& rhs) {
505 return lhs &
static_cast<uint64_t
>(rhs);
507 inline uint64_t operator&(
const Value::Type& lhs,
const uint64_t rhs) {
508 return static_cast<uint64_t
>(lhs) & rhs;
517 struct hash<nebula::Value> {
518 std::size_t operator()(
const nebula::Value& h)
const noexcept;
522 struct hash<nebula::Value*> {
523 std::size_t operator()(
const nebula::Value* h)
const noexcept {
529 struct equal_to<nebula::Value*> {
531 return lhs == rhs ? true : (lhs !=
nullptr) && (rhs !=
nullptr) && (*lhs == *rhs);