susumu.yata
null+****@clear*****
Thu Oct 2 17:20:49 JST 2014
susumu.yata 2014-10-02 17:20:49 +0900 (Thu, 02 Oct 2014) New Revision: d49aa5666c6f38020644b05036bcc23d95d133c6 https://github.com/groonga/grnxx/commit/d49aa5666c6f38020644b05036bcc23d95d133c6 Message: Add a list of referrer columns to Table. (#71) Modified files: include/grnxx/table.hpp lib/grnxx/column.cpp lib/grnxx/table.cpp Modified: include/grnxx/table.hpp (+19 -0) =================================================================== --- include/grnxx/table.hpp 2014-10-02 11:58:54 +0900 (cdcb88f) +++ include/grnxx/table.hpp 2014-10-02 17:20:49 +0900 (ab1c21c) @@ -182,10 +182,29 @@ class Table { // unique_ptr<Expression> &&expression, // const GrouperOptions &options = GrouperOptions()) const; + // TODO: This member function should be hidden. + // + // Append a referrer column. + // + // On success, returns true. + // On failure, returns false and stores error information into "*error" if + // "error" != nullptr. + bool append_referrer_column(Error *error, Column *column); + + // TODO: This member function should be hidden. + // + // Append a referrer column. + // + // On success, returns true. + // On failure, returns false and stores error information into "*error" if + // "error" != nullptr. + bool remove_referrer_column(Error *error, Column *column); + private: DB *db_; Name name_; Array<unique_ptr<Column>> columns_; + Array<Column *> referrer_columns_; Column *key_column_; Int num_rows_; Int max_row_id_; Modified: lib/grnxx/column.cpp (+10 -0) =================================================================== --- lib/grnxx/column.cpp 2014-10-02 11:58:54 +0900 (2070201) +++ lib/grnxx/column.cpp 2014-10-02 17:20:49 +0900 (5f19004) @@ -400,6 +400,11 @@ unique_ptr<ColumnImpl<Int>> ColumnImpl<Int>::create( TypeTraits<Int>::default_value())) { return nullptr; } + if (column->ref_table()) { + if (!table->append_referrer_column(error, column.get())) { + return nullptr; + } + } return column; } @@ -879,6 +884,11 @@ unique_ptr<ColumnImpl<Vector<Int>>> ColumnImpl<Vector<Int>>::create( if (!column->headers_.resize(error, table->max_row_id() + 1, 0)) { return nullptr; } + if (column->ref_table()) { + if (!table->append_referrer_column(error, column.get())) { + return nullptr; + } + } return column; } Modified: lib/grnxx/table.cpp (+26 -2) =================================================================== --- lib/grnxx/table.cpp 2014-10-02 11:58:54 +0900 (b46b3a4) +++ lib/grnxx/table.cpp 2014-10-02 17:20:49 +0900 (9eddbb1) @@ -228,7 +228,7 @@ Column *Table::create_column(Error *error, if (!new_column) { return nullptr; } - columns_.push_back(error, std::move(new_column)); + columns_.push_back(nullptr, std::move(new_column)); return columns_.back().get(); } @@ -243,9 +243,13 @@ bool Table::remove_column(Error *error, const StringCRef &name) { static_cast<int>(name.size()), name.data()); return false; } - if (columns_[column_id].get() == key_column_) { + Column *column = columns_[column_id].get(); + if (column == key_column_) { key_column_ = nullptr; } + if (column->ref_table()) { + column->ref_table()->remove_referrer_column(nullptr, column); + } columns_.erase(column_id); return true; } @@ -478,10 +482,30 @@ unique_ptr<Table> Table::create(Error *error, return table; } +bool Table::append_referrer_column(Error *error, Column *column) { + if (column->ref_table() != this) { + GRNXX_ERROR_SET(error, INVALID_ARGUMENT, "Wrong column"); + return false; + } + return referrer_columns_.push_back(error, column); +} + +bool Table::remove_referrer_column(Error *error, Column *column) { + for (Int i = 0; i < referrer_columns_.size(); ++i) { + if (column == referrer_columns_[i]) { + referrer_columns_.erase(i); + return true; + } + } + GRNXX_ERROR_SET(error, NOT_FOUND, "Column not found"); + return false; +} + Table::Table() : db_(nullptr), name_(), columns_(), + referrer_columns_(), key_column_(nullptr), num_rows_(0), max_row_id_(MIN_ROW_ID - 1), -------------- next part -------------- HTML����������������������������...Download