| 220 | TableConstructor() : source_(nullptr), table_(nullptr) {} |
| 221 | ~TableConstructor() override { Reset(); } |
| 222 | Status FinishImpl(const Options& options, const KVMap& data) override { |
| 223 | Reset(); |
| 224 | StringSink sink; |
| 225 | TableBuilder builder(options, &sink); |
| 226 | |
| 227 | for (KVMap::const_iterator it = data.begin(); it != data.end(); ++it) { |
| 228 | builder.Add(it->first, it->second); |
| 229 | TF_CHECK_OK(builder.status()); |
| 230 | } |
| 231 | Status s = builder.Finish(); |
| 232 | TF_CHECK_OK(s) << s.ToString(); |
| 233 | |
| 234 | CHECK_EQ(sink.contents().size(), builder.FileSize()); |
| 235 | |
| 236 | // Open the table |
| 237 | source_ = new StringSource(sink.contents()); |
| 238 | Options table_options; |
| 239 | return Table::Open(table_options, source_, sink.contents().size(), &table_); |
| 240 | } |
| 241 | |
| 242 | Iterator* NewIterator() const override { return table_->NewIterator(); } |
| 243 | |