TableInfo.hpp 2.4 KB
Newer Older
Philipp Götze's avatar
Philipp Götze committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2017 DBIS Group - TU Ilmenau, All Rights Reserved.
 *
 * This file is part of PTable.
 *
 * PTable is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PTable is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PTable.  If not, see <http://www.gnu.org/licenses/>.
 */

Philipp Götze's avatar
Philipp Götze committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#ifndef TableInfo_hpp_
#define TableInfo_hpp_

#include <memory>
#include <string>
#include <vector>

namespace ptable {

class ColumnInfo {
 public:
  enum ColumnType { Void_Type, Int_Type, Double_Type, String_Type };

  ColumnInfo(const std::string &n, ColumnType ct) : mColName(n), mColType(ct) {}

  const std::string &getName() const { return mColName; }

  const ColumnType &getType() const { return mColType; }

 private:
  std::string mColName;
  ColumnType mColType;
};

class TableInfo {
 public:
  typedef std::vector<ColumnInfo>::const_iterator ColumnIterator;

  TableInfo() {}

  TableInfo(const std::string &name, std::initializer_list<ColumnInfo> columns,
            ColumnInfo::ColumnType keyType = ColumnInfo::Void_Type)
    : mName(name), mColumns(columns), mKeyType(keyType) {}

  TableInfo(const std::string &name) : mName(name), mColumns(), mKeyType(ColumnInfo::Void_Type) {}

  const std::string &tableName() const { return mName; }

  std::string typeSignature() const;

  std::string generateTypeDef() const;

  ColumnInfo::ColumnType typeOfKey() const { return mKeyType; }

  int findColumnByName(const std::string &colName) const;
  const ColumnInfo &columnInfo(int pos) const { return mColumns[pos]; }

  void setColumns(const std::vector<ColumnInfo> &vec) { mColumns = vec; }

  ColumnIterator begin() const { return mColumns.begin(); }
  ColumnIterator end() const { return mColumns.end(); }

 private:
  std::string mName;
  std::vector<ColumnInfo> mColumns;
  ColumnInfo::ColumnType mKeyType;
};

typedef std::shared_ptr<TableInfo> TableInfoPtr;

} /* namespace ptable */

std::ostream &operator<<(std::ostream &os, ptable::ColumnInfo::ColumnType ct);

#endif /* TableInfo_hpp_ */