Developer Application Interface (ARC API) v4.5.8
ARC, Inc. GenIV Application Interface
CArcLog.h
1// +------------------------------------------------------------------------------------------------------------------+
2// | FILE: CArcLog.h ( GenIV ) |
3// +------------------------------------------------------------------------------------------------------------------+
4// | PURPOSE: This file defines the ARC logging class. This is used for command logging. |
5// | |
6// | AUTHOR: Scott Streit DATE: Sept 25, 2014 |
7// | |
8// | Copyright 2013 Astronomical Research Cameras, Inc. All rights reserved. |
9// +------------------------------------------------------------------------------------------------------------------+
12#pragma once
13
14#ifdef _WINDOWS
15 #pragma warning( disable: 4251 )
16#endif
17
18#ifdef __cpp_lib_format
19 #include <format>
20#endif
21
22#include <mutex>
23#include <queue>
24#include <string>
25#include <sstream>
26#include <cstdint>
27#include <cstdarg>
28
29#include <CArcBase.h>
30#include <CArcDeviceDllMain.h>
31
32
33namespace arc
34{
35 namespace gen4
36 {
37
39 typedef std::queue<std::string>::size_type qsize_t;
40
41
46 class GEN4_CARCDEVICE_API CArcLog : arc::gen4::CArcBase
47 {
48 public:
49
52 CArcLog( void );
53
56 ~CArcLog( void ) = default;
57
62 void setMaxSize( const qsize_t uiSize = Q_MAX );
63
68 void enable( const bool bEnable = true );
69
73 bool isEnabled( void ) const noexcept;
74
81 void put( const std::string& sText );
82
89 #ifdef __cpp_lib_format
90 template <typename... Args>
91 void put( std::string_view sFormat, const Args&... args )
92 {
93 if ( !m_bEnabled ) { return; }
94
95 std::lock_guard<std::mutex> lockGaurd( m_mutex );
96
97 //
98 // Check the Q size. Dump the oldest if
99 // the Q is too big.
100 //
101 if ( m_sQueue.size() >= Q_MAX )
102 {
103 m_sQueue.pop();
104 }
105
106 m_sQueue.emplace( std::format( sFormat, std::forward<Args>( args )... ) );
107 }
108 #else
109 void put( const char* pszFmt, ... );
110 #endif
111
116 const std::string next( void );
117
123 const std::string last( void );
124
128 std::size_t count( void ) const noexcept;
129
134 bool empty( void ) const noexcept;
135
140 CArcLog& operator<<( std::string const& sText );
141
142 private:
143
144// void queueInit( void );
145
147 static qsize_t Q_MAX;
148
150 std::queue<std::string> m_sQueue;
151
153 mutable std::mutex m_mutex;
154
156 bool m_bEnabled;
157 };
158
159
162 using pLogger_t = std::weak_ptr<arc::gen4::CArcLog>;
163
164
165 } // end gen4 namespace
166} // end arc namespace
void put(const std::string &sText)
~CArcLog(void)=default
const std::string next(void)
CArcLog & operator<<(std::string const &sText)
void setMaxSize(const qsize_t uiSize=Q_MAX)
const std::string last(void)
void put(const char *pszFmt,...)
bool isEnabled(void) const noexcept
std::size_t count(void) const noexcept
void enable(const bool bEnable=true)
bool empty(void) const noexcept
std::weak_ptr< arc::gen4::CArcLog > pLogger_t
Definition: CArcLog.h:162
std::queue< std::string >::size_type qsize_t
Definition: CArcLog.h:39
Definition: CArcBase.h:50