table_meta.h 2.2 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11
/* 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. */

//
12
// Created by Meiyi & Wangyunlai on 2021/5/12.
羽飞's avatar
羽飞 已提交
13 14
//

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

#include <string>
#include <vector>

#include "rc.h"
#include "storage/common/field_meta.h"
#include "storage/common/index_meta.h"
#include "common/lang/serializable.h"

class TableMeta : public common::Serializable {
public:
  TableMeta() = default;
  ~TableMeta() = default;

  TableMeta(const TableMeta &other);

  void swap(TableMeta &other) noexcept;

  RC init(const char *name, int field_num, const AttrInfo attributes[]);

  RC add_index(const IndexMeta &index);

public:
L
Longda 已提交
39 40 41 42 43
  const char *name() const;
  const FieldMeta *trx_field() const;
  const FieldMeta *field(int index) const;
  const FieldMeta *field(const char *name) const;
  const FieldMeta *find_field_by_offset(int offset) const;
羽飞's avatar
羽飞 已提交
44
  const std::vector<FieldMeta> *field_metas() const { return &fields_; }
W
wangyunlai.wyl 已提交
45
  int field_num() const; // sys field included
羽飞's avatar
羽飞 已提交
46 47
  int sys_field_num() const;

L
Longda 已提交
48 49 50
  const IndexMeta *index(const char *name) const;
  const IndexMeta *find_index_by_field(const char *field) const;
  const IndexMeta *index(int i) const;
羽飞's avatar
羽飞 已提交
51 52 53 54 55
  int index_num() const;

  int record_size() const;

public:
L
Longda 已提交
56 57 58
  int serialize(std::ostream &os) const override;
  int deserialize(std::istream &is) override;
  int get_serial_size() const override;
羽飞's avatar
羽飞 已提交
59 60 61
  void to_string(std::string &output) const override;
  void desc(std::ostream &os) const;

L
Longda 已提交
62
protected:
羽飞's avatar
羽飞 已提交
63 64
  static RC init_sys_fields();

L
Longda 已提交
65 66 67 68
protected:
  std::string name_;
  std::vector<FieldMeta> fields_;  // 包含sys_fields
  std::vector<IndexMeta> indexes_;
羽飞's avatar
羽飞 已提交
69

L
Longda 已提交
70 71 72
  int record_size_ = 0;

  //@@@ TODO why used static variable?
羽飞's avatar
羽飞 已提交
73 74
  static std::vector<FieldMeta> sys_fields_;
};