17#include "common/lang/string.h"
18#include "common/lang/memory.h"
19#include "common/type/attr_type.h"
20#include "common/type/data_type.h"
35 friend class BooleanType;
43 Value(AttrType attr_type,
char *data,
int length = 4) : attr_type_(attr_type) { this->set_data(data, length); }
45 explicit Value(
int val);
46 explicit Value(
float val);
47 explicit Value(
bool val);
48 explicit Value(
const char *s,
int len = 0);
60 return DataType::type_instance(result.attr_type())->
add(left, right, result);
63 static RC subtract(
const Value &left,
const Value &right,
Value &result)
65 return DataType::type_instance(result.attr_type())->
subtract(left, right, result);
68 static RC multiply(
const Value &left,
const Value &right,
Value &result)
70 return DataType::type_instance(result.attr_type())->
multiply(left, right, result);
75 return DataType::type_instance(result.attr_type())->
divide(left, right, result);
78 static RC negative(
const Value &value,
Value &result)
80 return DataType::type_instance(result.attr_type())->
negative(value, result);
83 static RC cast_to(
const Value &value, AttrType to_type,
Value &result)
85 return DataType::type_instance(value.attr_type())->
cast_to(value, to_type, result);
88 void set_type(AttrType type) { this->attr_type_ = type; }
89 void set_data(
char *data,
int length);
90 void set_data(
const char *data,
int length) { this->set_data(
const_cast<char *
>(data), length); }
91 void set_value(
const Value &value);
92 void set_boolean(
bool val);
94 string to_string()
const;
96 int compare(
const Value &other)
const;
98 const char *data()
const;
100 int length()
const {
return length_; }
101 AttrType attr_type()
const {
return attr_type_; }
109 float get_float()
const;
110 string get_string()
const;
111 bool get_boolean()
const;
114 void set_int(
int val);
115 void set_float(
float val);
116 void set_string(
const char *s,
int len = 0);
117 void set_string_from_other(
const Value &other);
120 AttrType attr_type_ = AttrType::UNDEFINED;
128 char *pointer_value_;
129 } value_ = {.int_value_ = 0};
固定长度的字符串类型
Definition: char_type.h:21
Definition: data_type.h:28
virtual RC divide(const Value &left, const Value &right, Value &result) const
计算 left / right,并将结果保存到 result 中
Definition: data_type.h:68
virtual RC cast_to(const Value &val, AttrType type, Value &result) const
将 val 转换为 type 类型,并将结果保存到 result 中
Definition: data_type.h:78
virtual RC subtract(const Value &left, const Value &right, Value &result) const
计算 left - right,并将结果保存到 result 中
Definition: data_type.h:58
virtual RC multiply(const Value &left, const Value &right, Value &result) const
计算 left * right,并将结果保存到 result 中
Definition: data_type.h:63
virtual RC add(const Value &left, const Value &right, Value &result) const
计算 left + right,并将结果保存到 result 中
Definition: data_type.h:53
virtual RC negative(const Value &val, Value &result) const
计算 -val,并将结果保存到 result 中
Definition: data_type.h:73
浮点型数据类型
Definition: float_type.h:20
整型类型
Definition: integer_type.h:20
属性的值
Definition: value.h:30
int get_int() const
Definition: value.cpp:234
bool own_data_
是否申请并占有内存, 目前对于 CHARS 类型 own_data_ 为true, 其余类型 own_data_ 为false
Definition: value.h:132
向量类型
Definition: vector_type.h:20