Loop Timing Witness
Native controller and runtime interfaces; hardware qualification pending
Toggle main menu visibility
Loading...
Searching...
No Matches
exclusive_output.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: AGPL-3.0-or-later
2
// Commercial license available
3
// © Concepts 1996–2026 Miroslav Šotek. All rights reserved.
4
// © Code 2020–2026 Miroslav Šotek. All rights reserved.
5
// ORCID: 0009-0009-3560-0851
6
// Contact: www.anulum.li | protoscience@anulum.li
7
// Loop Timing Witness — exclusive native output stream ownership
8
12
13
#ifndef WITNESS_EXCLUSIVE_OUTPUT_H
14
#define WITNESS_EXCLUSIVE_OUTPUT_H
15
#include <cstdio>
16
#include "
refusal.h
"
17
#include <stdexcept>
18
19
namespace
witness {
21
enum class
OutputFormat
{
22
text
,
23
binary
24
};
25
26
class
ExclusiveOutput
{
27
std::FILE *file;
28
29
public
:
31
ExclusiveOutput
(
const
char
*path,
OutputFormat
format,
const
char
*error)
32
: file(std::fopen(path, format ==
OutputFormat
::
binary
?
"wbx"
:
"wx"
)) {
33
if
(!file)
34
throw
witness::RuntimeRefused
(error);
35
}
36
37
~ExclusiveOutput
() {
38
if
(file)
39
std::fclose(file);
40
}
41
ExclusiveOutput
(
const
ExclusiveOutput
&) =
delete
;
42
ExclusiveOutput
&operator=(
const
ExclusiveOutput
&) =
delete
;
44
bool
is_open
() const noexcept {
return
file !=
nullptr
; }
46
std::FILE *
stream
(
const
char
*closed_error)
const
{
47
if
(!file)
48
throw
witness::RuntimeRefused
(closed_error);
49
return
file;
50
}
51
52
int
close
(
const
char
*closed_error) {
53
auto
*owned =
stream
(closed_error);
54
file =
nullptr
;
55
return
std::fclose(owned);
56
}
57
};
58
}
// namespace witness
59
#endif
witness::ExclusiveOutput
Definition
exclusive_output.h:26
witness::ExclusiveOutput::is_open
bool is_open() const noexcept
Definition
exclusive_output.h:44
witness::ExclusiveOutput::close
int close(const char *closed_error)
Definition
exclusive_output.h:52
witness::ExclusiveOutput::ExclusiveOutput
ExclusiveOutput(const char *path, OutputFormat format, const char *error)
Definition
exclusive_output.h:31
witness::ExclusiveOutput::stream
std::FILE * stream(const char *closed_error) const
Definition
exclusive_output.h:46
witness::ExclusiveOutput::~ExclusiveOutput
~ExclusiveOutput()
Definition
exclusive_output.h:37
witness::RuntimeRefused
Definition
refusal.h:19
witness::OutputFormat
OutputFormat
Definition
exclusive_output.h:21
witness::OutputFormat::text
@ text
Definition
exclusive_output.h:22
witness::OutputFormat::binary
@ binary
Definition
exclusive_output.h:23
refusal.h
runtime
exclusive_output.h
Generated by
1.18.0