table_meta.h 2.1 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11
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. */

//
羽飞's avatar
羽飞 已提交
12
// Created by 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

#include <string>
#include <vector>

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

羽飞's avatar
羽飞 已提交
25 26
class TableMeta : public common::Serializable
{
羽飞's avatar
羽飞 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39
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 已提交
40 41 42 43 44
  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;
L
Longda Feng 已提交
45 46 47 48
  const std::vector<FieldMeta> *field_metas() const
  {
    return &fields_;
  }
羽飞's avatar
羽飞 已提交
49 50
  auto trx_fields() const -> const std::pair<const FieldMeta *, int>;
  
L
Longda Feng 已提交
51
  int field_num() const;  // sys field included
羽飞's avatar
羽飞 已提交
52 53
  int sys_field_num() const;

L
Longda 已提交
54 55 56
  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
羽飞 已提交
57 58 59 60 61
  int index_num() const;

  int record_size() const;

public:
L
Longda 已提交
62 63 64
  int serialize(std::ostream &os) const override;
  int deserialize(std::istream &is) override;
  int get_serial_size() const override;
羽飞's avatar
羽飞 已提交
65 66 67
  void to_string(std::string &output) const override;
  void desc(std::ostream &os) const;

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

L
Longda 已提交
73
  int record_size_ = 0;
羽飞's avatar
羽飞 已提交
74
};