kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/common/indexing/RecordingOutputStream.h (about) 1 /* 2 * Copyright 2014 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef KYTHE_CXX_COMMON_INDEXING_RECORDING_OUTPUT_STREAM_H_ 18 #define KYTHE_CXX_COMMON_INDEXING_RECORDING_OUTPUT_STREAM_H_ 19 20 #include "KytheOutputStream.h" 21 22 namespace kythe { 23 24 /// \brief A `KytheOutputStream` that records all `Entry` instances in memory. 25 /// 26 /// This is intended to be used for testing only. 27 class RecordingOutputStream : public KytheOutputStream { 28 public: 29 void Emit(const FactRef& fact) override { 30 proto::Entry entry; 31 fact.Expand(&entry); 32 Emit(entry); 33 } 34 void Emit(const EdgeRef& edge) override { 35 proto::Entry entry; 36 edge.Expand(&entry); 37 entry.set_fact_name("/"); 38 Emit(entry); 39 } 40 void Emit(const OrdinalEdgeRef& edge) override { 41 proto::Entry entry; 42 edge.Expand(&entry); 43 entry.set_fact_name("/"); 44 Emit(entry); 45 } 46 47 /// \brief All entries that were emitted to this stream, in order. 48 const std::vector<kythe::proto::Entry>& entries() const { return entries_; } 49 50 private: 51 std::vector<kythe::proto::Entry> entries_; 52 53 /// \brief Append an entry to this stream's history. 54 void Emit(const kythe::proto::Entry& entry) { entries_.push_back(entry); } 55 }; 56 57 } // namespace kythe 58 59 #endif // KYTHE_CXX_COMMON_INDEXING_RECORDING_OUTPUT_STREAM_H_