File: callback_ostream.h

package info (click to toggle)
ldc 1%3A1.24.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 53,728 kB
  • sloc: cpp: 55,939; ansic: 10,599; sh: 958; makefile: 801; asm: 507; objc: 122; exp: 30; python: 12
file content (31 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//===-- callback_ostream.h - jit support ------------------------*- C++ -*-===//
//
//                         LDC – the LLVM D compiler
//
// This file is distributed under the Boost Software License. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
//
// Simple llvm::raw_ostream implementation which sink all input to provided
// callback. It uses llvm::function_ref so user must ensure callback lifetime.
//
//===----------------------------------------------------------------------===//

#pragma once

#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/raw_ostream.h"

class CallbackOstream : public llvm::raw_ostream {
  using CallbackT = llvm::function_ref<void(const char *, size_t)>;
  CallbackT callback;
  uint64_t currentPos = 0;

  void write_impl(const char *Ptr, size_t Size) override;

  uint64_t current_pos() const override;

public:
  explicit CallbackOstream(CallbackT c);
};