OpenBarnyard
 
Loading...
Searching...
No Matches
TUtil Class Reference

#include <TUtil.h>

Inheritance diagram for TUtil:
TSingleton< TUtil >

Classes

struct  LogEvent
 
struct  TOSHIParams
 

Public Types

enum  LogType {
  LogType_Info , LogType_Warning , LogType_Error , LogType_Critical ,
  LogType_NUMOF
}
 

Public Member Functions

 TUtil ()
 
 ~TUtil ()=default
 
- Public Member Functions inherited from TSingleton< TUtil >
 TSingleton (const TSingleton &)=delete
 
 TSingleton (const TSingleton &&)=delete
 
TSingletonoperator= (const TSingleton &)=delete
 
TSingletonoperator= (const TSingleton &&)=delete
 

Static Public Member Functions

static constexpr const TCHARLogTypeToString (LogType a_eType)
 
static TBOOL ToshiCreate (const TOSHIParams &a_rToshiParams)
 
static void ToshiDestroy ()
 
static const TCHARGetTime ()
 
static void MemSet (void *ptr, TINT value, TSIZE size)
 
static void * MemCopy (void *dst, const void *src, TSIZE size)
 
static void MemClear (void *ptr, TSIZE size)
 
static TINT MemCompare (const void *ptr1, const void *ptr2, TSIZE size)
 
static void * MemMove (void *dst, const void *src, TSIZE size)
 
template<class T>
static void Fill (T *a_pStart, T *a_pEnd, const T &a_rcValue=T())
 
static void Log (const TCHAR *a_szFormat,...)
 
static void Log (LogType a_eLogType, const TCHAR *a_szFormat,...)
 
static void TrimLog (const TCHAR *fileExtension, TSIZE trimTo)
 
static void LogDown ()
 
static void LogUp ()
 
static void LogConsole (const TCHAR *a_szFormat,...)
 
static void LogSet (TLogFile *a_logFile)
 
static TLogFileGetCurrentLogFile ()
 
static TEmitter< TUtil, TUtil::LogEvent > & GetLogEmitter ()
 
static TMutexGetGlobalMutex ()
 
static TPString8PoolSetTPStringPool (TPString8Pool *a_pStringPool)
 
static TPString8PoolGetTPStringPool ()
 
static const TOSHIParamsGetToshiParameters ()
 
static void CRCInitialise ()
 
static TUINT32 CRC32 (void *buffer, TUINT32 len)
 
- Static Public Member Functions inherited from TSingleton< TUtil >
static TFORCEINLINE TUtilCreateSingleton (Args &&... args)
 
static TFORCEINLINE D * CreateSingleton (Args &&... args)
 
static TFORCEINLINE void DestroySingleton ()
 
static TFORCEINLINE TUtilGetSingletonSafe ()
 
static TFORCEINLINE TBOOL IsSingletonCreated ()
 
static TFORCEINLINE TUtilGetSingleton ()
 

Static Public Attributes

static constexpr const TCHARkTypeStrings []
 
static TUINT32 s_aiCRC32LUT [(256)] = {}
 

Additional Inherited Members

- Protected Member Functions inherited from TSingleton< TUtil >
TFORCEINLINE TSingleton ()
 
TFORCEINLINE ~TSingleton ()
 
- Static Protected Attributes inherited from TSingleton< TUtil >
static TUtilms_pSingleton
 

Detailed Description

Definition at line 13 of file TUtil.h.

Member Enumeration Documentation

◆ LogType

Enumerator
LogType_Info 
LogType_Warning 
LogType_Error 
LogType_Critical 
LogType_NUMOF 

Definition at line 20 of file TUtil.h.

21 {
27 };
@ LogType_Warning
Definition TUtil.h:23
@ LogType_Info
Definition TUtil.h:22
@ LogType_Critical
Definition TUtil.h:25
@ LogType_NUMOF
Definition TUtil.h:26
@ LogType_Error
Definition TUtil.h:24

Constructor & Destructor Documentation

◆ TUtil()

TUtil::TUtil ( )

Definition at line 142 of file TUtil.cpp.

143 : m_LogEmitter( this )
144{
145 m_pDefaultLogFile = TNULL;
146 m_pCurrentLogFile = TNULL;
147}
#define TNULL
Definition Typedefs.h:23

◆ ~TUtil()

TUtil::~TUtil ( )
default

Member Function Documentation

◆ CRC32()

TUINT32 TUtil::CRC32 ( void * buffer,
TUINT32 len )
static

Definition at line 201 of file TUtil.cpp.

202{
203 TBYTE* bytes = (TBYTE*)buffer;
204 TUINT32 crc = 0;
205
206 while ( len-- )
207 crc = crc32upd( s_aiCRC32LUT, crc, *bytes++ );
208
209 return CRC32POST( crc );
210}
#define crc32upd(crctab, crc, c)
Definition TUtil.h:176
#define CRC32POST(crc)
Definition TUtil.h:174
uint32_t TUINT32
Definition Typedefs.h:13
uint8_t TBYTE
Definition Typedefs.h:19
static TUINT32 s_aiCRC32LUT[(256)]
Definition TUtil.h:183

◆ CRCInitialise()

void TUtil::CRCInitialise ( )
static

Definition at line 182 of file TUtil.cpp.

183{
184 TUINT32 crc;
185
186 for ( TINT i = 0; i < CRC_TABSIZE; i++ )
187 {
188 crc = i;
189 for ( TINT j = 8; j > 0; j-- )
190 {
191 if ( crc & 1 )
192 crc = ( crc >> 1 ) ^ CRC32POLY;
193 else
194 crc >>= 1;
195 }
196 s_aiCRC32LUT[ i ] = crc;
197 }
198}
#define CRC_TABSIZE
Definition TUtil.h:179
#define CRC32POLY
Definition TUtil.h:173
int TINT
Definition Typedefs.h:7

◆ Fill()

template<class T>
static void TUtil::Fill ( T * a_pStart,
T * a_pEnd,
const T & a_rcValue = T() )
inlinestatic

Definition at line 96 of file TUtil.h.

97 {
98 for ( ; a_pStart != a_pEnd; a_pStart++ )
99 *a_pStart = a_rcValue;
100 }

◆ GetCurrentLogFile()

static TLogFile * TUtil::GetCurrentLogFile ( )
inlinestatic

Definition at line 116 of file TUtil.h.

116{ return ms_pSingleton->m_pCurrentLogFile; }
static TUtil * ms_pSingleton
Definition TSingleton.h:71

◆ GetGlobalMutex()

static TMutex & TUtil::GetGlobalMutex ( )
inlinestatic

Definition at line 119 of file TUtil.h.

119{ return ms_oGlobalMutex; }

◆ GetLogEmitter()

static TEmitter< TUtil, TUtil::LogEvent > & TUtil::GetLogEmitter ( )
inlinestatic

Definition at line 117 of file TUtil.h.

117{ return ms_pSingleton->m_LogEmitter; }

◆ GetTime()

const TCHAR * TUtil::GetTime ( )
static

Definition at line 54 of file TUtil_Win.cpp.

55{
56 time_t t = time( NULL );
57 TCHAR* str = ctime( &t );
58 return strtok( str, "\n" );
59}
char TCHAR
Definition Typedefs.h:20

◆ GetToshiParameters()

static const TOSHIParams & TUtil::GetToshiParameters ( )
inlinestatic

Definition at line 129 of file TUtil.h.

130 {
131 return ms_oToshiParams;
132 }

◆ GetTPStringPool()

static TPString8Pool * TUtil::GetTPStringPool ( )
inlinestatic

Definition at line 123 of file TUtil.h.

124 {
125 TASSERT( ms_poStringPool != TNULL );
126 return *ms_poStringPool;
127 }
#define TASSERT(X,...)
Definition Defines.h:138

◆ Log() [1/2]

void TUtil::Log ( const TCHAR * a_szFormat,
... )
static

Definition at line 65 of file TUtil.cpp.

66{
68 {
69 auto pLogFile = GetCurrentLogFile();
70
71 T2FormatString2048 formatString;
72
73 va_list args;
74 va_start( args, a_szFormat );
75 formatString.FormatV( a_szFormat, args );
76 va_end( args );
77
78 pLogFile->Log( LogType_Info, ms_oToshiParams.szLogAppName, ms_oToshiParams.szLogAppDirName, formatString.Get() );
79 GetLogEmitter().Throw( LogEvent( pLogFile, LogType_Info, formatString.Get() ) );
80 }
81}
T2FormatString< 2048, T2StringTraits< TCHAR > > T2FormatString2048
Definition T2String.h:246
constexpr CharType * Get()
Definition T2String.h:204
void FormatV(const CharType *a_szFormat, va_list a_Args)
Definition T2String.h:183
void Throw(Data *pData)
Definition TEvent.h:56
static TFORCEINLINE TBOOL IsSingletonCreated()
Definition TSingleton.h:43
static TEmitter< TUtil, TUtil::LogEvent > & GetLogEmitter()
Definition TUtil.h:117
static TLogFile * GetCurrentLogFile()
Definition TUtil.h:116

◆ Log() [2/2]

void TUtil::Log ( LogType a_eLogType,
const TCHAR * a_szFormat,
... )
static

Definition at line 83 of file TUtil.cpp.

84{
85 auto pLogFile = GetCurrentLogFile();
86
87 if ( pLogFile )
88 {
89 T2FormatString2048 formatString;
90
91 va_list args;
92 va_start( args, a_szFormat );
93 formatString.FormatV( a_szFormat, args );
94 va_end( args );
95
96 pLogFile->Log( a_eLogType, ms_oToshiParams.szLogAppName, ms_oToshiParams.szLogAppDirName, formatString.Get() );
97 GetLogEmitter().Throw( LogEvent( pLogFile, a_eLogType, formatString.Get() ) );
98 }
99}

◆ LogConsole()

void TUtil::LogConsole ( const TCHAR * a_szFormat,
... )
static

Definition at line 111 of file TUtil.cpp.

112{
113 auto pLogFile = GetCurrentLogFile();
114
115 if ( pLogFile )
116 {
117 T2FormatString2048 formatString;
118
119 va_list args;
120 va_start( args, a_szFormat );
121 formatString.FormatV( a_szFormat, args );
122 va_end( args );
123
124 OutputDebugStringA( formatString.Get() );
125 printf( formatString.Get() );
126 }
127}

◆ LogDown()

void TUtil::LogDown ( )
static

Definition at line 101 of file TUtil.cpp.

102{
103 TUtil::GetSingletonSafe()->m_pCurrentLogFile->Down();
104}
void Down()
Definition TLogFile.cpp:165
static TFORCEINLINE TUtil * GetSingletonSafe()
Definition TSingleton.h:37

◆ LogSet()

void TUtil::LogSet ( TLogFile * a_logFile)
static

Definition at line 129 of file TUtil.cpp.

130{
131 Log( "Changing log file." );
132 TUtil* pUtil = TUtil::GetSingleton();
133
134 if ( pUtil->m_pCurrentLogFile )
135 {
136 pUtil->m_pCurrentLogFile->Close();
137 }
138
139 pUtil->m_pCurrentLogFile = ( !a_pLogFile ) ? pUtil->m_pDefaultLogFile : a_pLogFile;
140}
void Close()
Definition TLogFile.cpp:69
static TFORCEINLINE TUtil * GetSingleton()
Definition TSingleton.h:49
static void Log(const TCHAR *a_szFormat,...)
Definition TUtil.cpp:65
TUtil()
Definition TUtil.cpp:142

◆ LogTypeToString()

static constexpr const TCHAR * TUtil::LogTypeToString ( LogType a_eType)
inlinestaticconstexpr

Definition at line 36 of file TUtil.h.

37 {
38 TSTATICASSERT( Toshi::TUtil::LogType_NUMOF == TARRAYSIZE( kTypeStrings ) );
39
40 return a_eType >= LogType_Info && a_eType < LogType_NUMOF ?
41 kTypeStrings[ a_eType ] :
42 "UNKNOWN";
43 }
#define TARRAYSIZE(ARRAY)
Definition Defines.h:70
#define TSTATICASSERT(...)
Definition Defines.h:67
static constexpr const TCHAR * kTypeStrings[]
Definition TUtil.h:29

◆ LogUp()

void TUtil::LogUp ( )
static

Definition at line 106 of file TUtil.cpp.

107{
108 TUtil::GetSingletonSafe()->m_pCurrentLogFile->Up();
109}
void Up()
Definition TLogFile.cpp:171

◆ MemClear()

static void TUtil::MemClear ( void * ptr,
TSIZE size )
inlinestatic

Definition at line 91 of file TUtil.h.

91{ std::memset( ptr, 0, size ); }

◆ MemCompare()

static TINT TUtil::MemCompare ( const void * ptr1,
const void * ptr2,
TSIZE size )
inlinestatic

Definition at line 92 of file TUtil.h.

92{ return std::memcmp( ptr1, ptr2, size ); }

◆ MemCopy()

static void * TUtil::MemCopy ( void * dst,
const void * src,
TSIZE size )
inlinestatic

Definition at line 90 of file TUtil.h.

90{ return std::memcpy( dst, src, size ); }

◆ MemMove()

static void * TUtil::MemMove ( void * dst,
const void * src,
TSIZE size )
inlinestatic

Definition at line 93 of file TUtil.h.

93{ return std::memmove( dst, src, size ); }

◆ MemSet()

static void TUtil::MemSet ( void * ptr,
TINT value,
TSIZE size )
inlinestatic

Definition at line 89 of file TUtil.h.

89{ std::memset( ptr, value, size ); }

◆ SetTPStringPool()

static TPString8Pool * TUtil::SetTPStringPool ( TPString8Pool * a_pStringPool)
inlinestatic

Definition at line 121 of file TUtil.h.

121{ return std::exchange( *ms_poStringPool, a_pStringPool ); }

◆ ToshiCreate()

TBOOL TUtil::ToshiCreate ( const TOSHIParams & a_rToshiParams)
static

Definition at line 149 of file TUtil.cpp.

150{
151 ms_oToshiParams = a_rToshiParams;
152
154 CreateKernelInterface();
156 CreateTPStringPool();
157 Create();
158
159 return TTRUE;
160}
#define TTRUE
Definition Typedefs.h:25
static TBOOL Create()
static TBOOL Create()
Definition TSystem.cpp:60

◆ ToshiDestroy()

void TUtil::ToshiDestroy ( )
static

Definition at line 167 of file TUtil.cpp.

168{
169 TIMPLEMENT();
170 ms_oGlobalMutex.Destroy();
171
173}
#define TIMPLEMENT()
Definition Defines.h:136
static void Uninitialise()

◆ TrimLog()

void TUtil::TrimLog ( const TCHAR * fileExtension,
TSIZE trimTo )
static

Definition at line 16 of file TUtil_Win.cpp.

17{
18 // and yes they actually did it with std
19
20 WIN32_FIND_DATAA ffd;
21 std::queue<std::string> queue;
22
23 HANDLE hFind = FindFirstFileA( fileName, &ffd );
24
25 if ( INVALID_HANDLE_VALUE == hFind )
26 {
27 FindClose( hFind );
28 return;
29 }
30
31 do
32 {
33 if ( ffd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE )
34 {
35 queue.push( ffd.cFileName );
36 }
37
38 BOOL found = FindNextFileA( hFind, &ffd );
39
40 if ( !found )
41 {
42 FindClose( hFind );
43 do
44 {
45 DeleteFileA( queue.front().c_str() );
46 queue.pop();
47 } while ( queue.size() > trimTo );
48 return;
49 }
50
51 } while ( TTRUE );
52}

Member Data Documentation

◆ kTypeStrings

const TCHAR* TUtil::kTypeStrings[]
staticconstexpr
Initial value:
= {
"Info",
"Warning",
"Error",
"Critical"
}

Definition at line 29 of file TUtil.h.

29 {
30 "Info",
31 "Warning",
32 "Error",
33 "Critical"
34 };

◆ s_aiCRC32LUT

TUINT32 TUtil::s_aiCRC32LUT[(256)] = {}
inlinestatic

Definition at line 183 of file TUtil.h.

183{};

The documentation for this class was generated from the following files: