field.h 850 字节
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 Field // TODO rename to Cell
羽飞's avatar
羽飞 已提交
8 9 10 11 12 13 14
{
public: 
  Field() = default;
  
  Field(FieldMeta *meta, char *data) : Field(nullptr, meta, data)
  {}
  Field(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 25 26

  int compare(const Field &other) const;

羽飞'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
};