FDRLogBuilder.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===- FDRLogBuilder.h - XRay FDR Log Building Utility --------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_XRAY_FDRLOGBUILDER_H
  9. #define LLVM_XRAY_FDRLOGBUILDER_H
  10. #include "llvm/XRay/FDRRecords.h"
  11. namespace llvm {
  12. namespace xray {
  13. /// The LogBuilder class allows for creating ad-hoc collections of records
  14. /// through the `add<...>(...)` function. An example use of this API is in
  15. /// crafting arbitrary sequences of records:
  16. ///
  17. /// auto Records = LogBuilder()
  18. /// .add<BufferExtents>(256)
  19. /// .add<NewBufferRecord>(1)
  20. /// .consume();
  21. ///
  22. class LogBuilder {
  23. std::vector<std::unique_ptr<Record>> Records;
  24. public:
  25. template <class R, class... T> LogBuilder &add(T &&... A) {
  26. Records.emplace_back(new R(std::forward<T>(A)...));
  27. return *this;
  28. }
  29. std::vector<std::unique_ptr<Record>> consume() { return std::move(Records); }
  30. };
  31. } // namespace xray
  32. } // namespace llvm
  33. #endif // LLVM_XRAY_FDRLOGBUILDER_H