gwnavruntime/basesystem/logstream.h Source File

logstream.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
11 
12 namespace Kaim
13 {
14 
15 // LogStream useful to print to log with << semantics, usage:
16 // LogStream stream;
17 // stream << "x = " << x << '\n';
18 // stream << "x = " << x << Kaim::Endl;
19 // stream << "x = " << x << " meters\n";
20 class LogStream
21 {
22  KY_DEFINE_NEW_DELETE_OPERATORS(Kaim::Stat_Default_Mem)
23  KY_CLASS_WITHOUT_COPY(LogStream)
24 public:
25  LogStream() {}
26 
27 #ifndef KY_NO_LOG_OUTPUT
28  void EndLineChar(char value)
29  {
30  if (value == '\n')
31  Flush();
32  }
33 
34  void EndLineString(const char* value)
35  {
36  size_t length = SFstrlen(value);
37  if (value[length-1] == '\n')
38  Flush();
39  }
40 
41  void Flush()
42  {
43  BaseLog* log = Kaim::BaseLog::GetGlobalBaseLog();
44  if (log)
45  log->LogMessage("%s", m_ss.CStr());
46  m_ss.Clear();
47  }
48 
49  StringStream m_ss;
50 #endif
51 };
52 
53 
54 #ifndef KY_NO_LOG_OUTPUT
55  inline LogStream& operator<<(LogStream& s, KyInt32 value) { s.m_ss << value; return s; }
56  inline LogStream& operator<<(LogStream& s, KyUInt32 value) { s.m_ss << value; return s; }
57  inline LogStream& operator<<(LogStream& s, KyInt64 value) { s.m_ss << value; return s; }
58  inline LogStream& operator<<(LogStream& s, KyUInt64 value) { s.m_ss << value; return s; }
59  inline LogStream& operator<<(LogStream& s, float value) { s.m_ss << value; return s; }
60  inline LogStream& operator<<(LogStream& s, double value) { s.m_ss << value; return s; }
61  inline LogStream& operator<<(LogStream& s, bool value) { s.m_ss << value; return s; }
62  inline LogStream& operator<<(LogStream& s, char value) { s.m_ss << value; s.EndLineChar(value); return s; }
63  inline LogStream& operator<<(LogStream& s, const char* value) { s.m_ss << value; s.EndLineString(value); return s; }
64 #else
65  inline LogStream& operator<<(LogStream& s, KyInt32 value) { KY_UNUSED(value); return s; }
66  inline LogStream& operator<<(LogStream& s, KyUInt32 value) { KY_UNUSED(value); return s; }
67  inline LogStream& operator<<(LogStream& s, KyInt64 value) { KY_UNUSED(value); return s; }
68  inline LogStream& operator<<(LogStream& s, KyUInt64 value) { KY_UNUSED(value); return s; }
69  inline LogStream& operator<<(LogStream& s, float value) { KY_UNUSED(value); return s; }
70  inline LogStream& operator<<(LogStream& s, double value) { KY_UNUSED(value); return s; }
71  inline LogStream& operator<<(LogStream& s, bool value) { KY_UNUSED(value); return s; }
72  inline LogStream& operator<<(LogStream& s, char value) { KY_UNUSED(value); return s; }
73  inline LogStream& operator<<(LogStream& s, const char* value) { KY_UNUSED(value); return s; }
74 #endif
75 
76 }
77 
78 #define KY_LOG_BIG_TITLE_BEGIN(prefix, title) \
79  prefix << "==============================================================\n" \
80  << prefix << "======== " << title << Kaim::Endl << Kaim::Endl
81 
82 #define KY_LOG_BIG_TITLE_END(prefix, title) \
83  prefix << "======== " << title << Kaim::Endl \
84  << prefix << "==============================================================" << Kaim::Endl << Kaim::Endl
85 
86 #define KY_LOG_SMALL_TITLE_BEGIN(prefix, title) \
87  prefix << "------------------------------------------------------ " << Kaim::Endl \
88  << prefix << "---- " << title << Kaim::Endl
89 
90 #define KY_LOG_SMALL_TITLE_END(prefix, title) \
91  prefix << "---- " << title << Kaim::Endl \
92  << prefix << "------------------------------------------------------ " << Kaim::Endl << Kaim::Endl
93 
std::uint64_t KyUInt64
uint64_t
Definition: types.h:30
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
std::int64_t KyInt64
int64_t
Definition: types.h:25
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24