tuple_cell.h 1.6 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by WangYunlai on 2022/6/7.
//

羽飞's avatar
羽飞 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#pragma once

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

class TupleCell
{
public: 
  TupleCell() = default;
  
  TupleCell(FieldMeta *meta, char *data)
    : TupleCell(meta->type(), data)
  {}
  TupleCell(AttrType attr_type, char *data)
    : attr_type_(attr_type), data_(data)
  {}

  void set_type(AttrType type) { this->attr_type_ = type; }
羽飞's avatar
羽飞 已提交
34
  void set_length(int length) { this->length_ = length; }
羽飞's avatar
羽飞 已提交
35 36 37 38 39 40 41
  void set_data(char *data) { this->data_ = data; }
  void set_data(const char *data) { this->set_data(const_cast<char *>(data)); }

  void to_string(std::ostream &os) const;

  int compare(const TupleCell &other) const;

羽飞's avatar
羽飞 已提交
42 43 44 45 46
  const char *data() const
  {
    return data_;
  }

羽飞's avatar
羽飞 已提交
47 48
  int length() const { return length_; }

羽飞's avatar
羽飞 已提交
49 50 51 52
  AttrType attr_type() const
  {
    return attr_type_;
  }
羽飞's avatar
羽飞 已提交
53

羽飞's avatar
羽飞 已提交
54 55
private:
  AttrType attr_type_ = UNDEFINED;
羽飞's avatar
羽飞 已提交
56
  int length_ = -1;
羽飞's avatar
羽飞 已提交
57 58
  char *data_ = nullptr; // real data. no need to move to field_meta.offset
};