tuple_cell.h 2.0 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
#pragma once

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

羽飞's avatar
羽飞 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
class TupleCellSpec
{
public: 
  TupleCellSpec(const char *table_name, const char *field_name, const char *alias = nullptr);
  TupleCellSpec(const char *alias);

  const char *table_name() const { return table_name_.c_str(); }
  const char *field_name() const { return field_name_.c_str(); }
  const char *alias() const { return alias_.c_str(); }

private:
  std::string table_name_;
  std::string field_name_;
  std::string alias_;
};

羽飞's avatar
羽飞 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49
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
羽飞 已提交
50
  void set_length(int length) { this->length_ = length; }
羽飞's avatar
羽飞 已提交
51 52 53 54 55 56 57
  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
羽飞 已提交
58 59 60 61 62
  const char *data() const
  {
    return data_;
  }

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

羽飞's avatar
羽飞 已提交
65 66 67 68
  AttrType attr_type() const
  {
    return attr_type_;
  }
羽飞's avatar
羽飞 已提交
69

羽飞's avatar
羽飞 已提交
70 71
private:
  AttrType attr_type_ = UNDEFINED;
羽飞's avatar
羽飞 已提交
72
  int length_ = -1;
羽飞's avatar
羽飞 已提交
73 74
  char *data_ = nullptr; // real data. no need to move to field_meta.offset
};