field.h 874 字节
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6
#pragma once

#include <iostream>
#include "storage/common/table.h"
#include "storage/common/field_meta.h"

羽飞's avatar
羽飞 已提交
7
class TupleCell // TODO rename to Cell
羽飞's avatar
羽飞 已提交
8 9
{
public: 
羽飞's avatar
羽飞 已提交
10
  TupleCell() = default;
羽飞's avatar
羽飞 已提交
11
  
羽飞's avatar
羽飞 已提交
12
  TupleCell(FieldMeta *meta, char *data) : TupleCell(nullptr, meta, data)
羽飞's avatar
羽飞 已提交
13
  {}
羽飞's avatar
羽飞 已提交
14
  TupleCell(Table *table, FieldMeta *meta, char *data)
羽飞's avatar
羽飞 已提交
15
    : table_(table), attr_type_(meta->type()), data_(data)
羽飞's avatar
羽飞 已提交
16 17 18
  {}

  void set_table(Table *table) { this->table_ = table; }
羽飞's avatar
羽飞 已提交
19
  void set_type(AttrType type) { this->attr_type_ = type; }
羽飞's avatar
羽飞 已提交
20
  void set_data(char *data) { this->data_ = data; }
羽飞's avatar
羽飞 已提交
21
  void set_data(const char *data) { this->set_data(const_cast<char *>(data)); }
羽飞's avatar
羽飞 已提交
22 23

  void to_string(std::ostream &os) const;
羽飞's avatar
羽飞 已提交
24

羽飞's avatar
羽飞 已提交
25
  int compare(const TupleCell &other) const;
羽飞's avatar
羽飞 已提交
26

羽飞's avatar
羽飞 已提交
27 28
private:
  Table *table_ = nullptr;
羽飞's avatar
羽飞 已提交
29
  AttrType attr_type_ = UNDEFINED;
羽飞's avatar
羽飞 已提交
30 31
  char *data_ = nullptr; // real data. no need to move to field_meta.offset
};