Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 1 | //===- FDRLogBuilder.h - XRay FDR Log Building Utility --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | #ifndef LLVM_INCLUDE_LLVM_XRAY_FDRLOGBUILDER_H_ |
| 10 | #define LLVM_INCLUDE_LLVM_XRAY_FDRLOGBUILDER_H_ |
| 11 | |
| 12 | #include "llvm/XRay/FDRRecords.h" |
| 13 | |
| 14 | namespace llvm { |
| 15 | namespace xray { |
| 16 | |
| 17 | /// The LogBuilder class allows for creating ad-hoc collections of records |
| 18 | /// through the `add<...>(...)` function. An example use of this API is in |
| 19 | /// crafting arbitrary sequences of records: |
| 20 | /// |
| 21 | /// auto Records = LogBuilder() |
| 22 | /// .add<BufferExtents>(256) |
| 23 | /// .add<NewBufferRecord>(1) |
| 24 | /// .consume(); |
| 25 | /// |
| 26 | class LogBuilder { |
| 27 | std::vector<std::unique_ptr<Record>> Records; |
| 28 | |
| 29 | public: |
| 30 | template <class R, class... T> LogBuilder &add(T &&... A) { |
| 31 | Records.emplace_back(new R(std::forward<T>(A)...)); |
| 32 | return *this; |
| 33 | } |
| 34 | |
| 35 | std::vector<std::unique_ptr<Record>> consume() { return std::move(Records); } |
| 36 | }; |
| 37 | |
| 38 | } // namespace xray |
| 39 | } // namespace llvm |
| 40 | |
| 41 | #endif // LLVM_INCLUDE_LLVM_XRAY_FDRLOGBUILDER_H_ |