field.h 745 字节
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#pragma once

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

class Field
{
public: 
  Field() = default;
  
  Field(FieldMeta *meta, char *data) : Field(nullptr, meta, data)
  {}
  Field(Table *table, FieldMeta *meta, char *data)
    : table_(table), meta_(meta), data_(data)
  {}

  void set_table(Table *table) { this->table_ = table; }
  void set_meta(const FieldMeta *meta) { this->meta_ = meta; }
  void set_data(char *data) { this->data_ = data; }

  const FieldMeta *meta() const { return meta_; }
  void to_string(std::ostream &os) const;
private:
  Table *table_ = nullptr;
  const FieldMeta *meta_ = nullptr;
  char *data_ = nullptr; // real data. no need to move to field_meta.offset
};