MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
value.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by Wangyunlai 2023/6/27
13//
14
15#pragma once
16
17#include <string>
18
23enum AttrType
24{
25 UNDEFINED,
26 CHARS,
27 INTS,
28 FLOATS,
29 BOOLEANS,
30};
31
32const char *attr_type_to_string(AttrType type);
33AttrType attr_type_from_string(const char *s);
34
39class Value
40{
41public:
42 Value() = default;
43
44 Value(AttrType attr_type, char *data, int length = 4) : attr_type_(attr_type)
45 {
46 this->set_data(data, length);
47 }
48
49 explicit Value(int val);
50 explicit Value(float val);
51 explicit Value(bool val);
52 explicit Value(const char *s, int len = 0);
53
54 Value(const Value &other) = default;
55 Value &operator=(const Value &other) = default;
56
57 void set_type(AttrType type)
58 {
59 this->attr_type_ = type;
60 }
61 void set_data(char *data, int length);
62 void set_data(const char *data, int length)
63 {
64 this->set_data(const_cast<char *>(data), length);
65 }
66 void set_int(int val);
67 void set_float(float val);
68 void set_boolean(bool val);
69 void set_string(const char *s, int len = 0);
70 void set_value(const Value &value);
71
72 std::string to_string() const;
73
74 int compare(const Value &other) const;
75
76 const char *data() const;
77 int length() const
78 {
79 return length_;
80 }
81
82 AttrType attr_type() const
83 {
84 return attr_type_;
85 }
86
87public:
92 int get_int() const;
93 float get_float() const;
94 std::string get_string() const;
95 bool get_boolean() const;
96
97private:
98 AttrType attr_type_ = UNDEFINED;
99 int length_ = 0;
100
101 union {
102 int int_value_;
103 float float_value_;
104 bool bool_value_;
105 } num_value_;
106 std::string str_value_;
107};
属性的值
Definition: value.h:40
int get_int() const
Definition: value.cpp:205