Developer Application Interface (ARC API) v4.5.8
ARC, Inc. GenIV Application Interface
CArcDebugStreamBuffer.h
1// +------------------------------------------------------------------------------------------------------------------+
2// | FILE: CArcDebugStreamBuffer.h ( GenIV ) |
3// +------------------------------------------------------------------------------------------------------------------+
4// | PURPOSE: This file defines the standard ARC debug stream buffer class, which is used to stream debug messages |
5// | to a std::array. This allows the performance of a C-style array with container access. |
6// | |
7// | AUTHOR: Scott Streit DATE: Feb 5, 2021 |
8// | |
9// | Copyright 2021 Astronomical Research Cameras, Inc. All rights reserved. |
10// +------------------------------------------------------------------------------------------------------------------+
13#pragma once
14
15#include <filesystem>
16#include <streambuf>
17#include <sstream>
18#include <array>
19#include <string>
20#include <cstring>
21
22using namespace std::string_literals;
23
24
25
26namespace arc
27{
28 namespace gen4
29 {
30
36 template<std::size_t SIZE, class CharT = char>
37 class CArcDebugStreamBuffer : public std::basic_streambuf<CharT>
38 {
39
40 public:
41
44 using Base = std::basic_streambuf<CharT>;
45
46 using char_type = typename Base::char_type;
47
51 {
52 m_pBuffer.reset( new char[ SIZE ] );
53
54 Base::setp( m_pBuffer.get(), m_pBuffer.get() + SIZE );
55 }
56
60 constexpr auto maxSize( void ) noexcept
61 {
62 return SIZE;
63 }
64
65
68 void reset( void ) noexcept
69 {
70 std::memset( m_pBuffer.get(), 0, SIZE );
71
72 this->pubseekpos( 0 );
73 }
74
75
80 void toFile( const std::filesystem::path& tFile ) const
81 {
82 if ( std::ofstream ofs( tFile ); ofs.is_open() )
83 {
84 for ( decltype( SIZE ) i = 0; i < SIZE; i++ )
85 {
86 ofs << m_pBuffer.get()[ i ];
87 }
88
89 ofs.close();
90 }
91
92 else
93 {
94 throw std::invalid_argument( "Failed to open file: \""s + tFile.string() + "\""s );
95 }
96 }
97
98 private:
99
102 std::unique_ptr<char[]> m_pBuffer;
103
104 };
105
106
107 } // end gen4 namespace
108} // end arc namespace
typename Base::char_type char_type
void toFile(const std::filesystem::path &tFile) const
std::basic_streambuf< CharT > Base
constexpr auto maxSize(void) noexcept
Definition: CArcBase.h:50