Atoms Crowd  7.0.0
Logger.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsUtils/Globals.h>
11 #include <sstream>
12 #include <memory>
13 #include <AtomsUtils/AtomsMath.h>
14 
15 namespace AtomsUtils
16 {
17 
19 
24  class ATOMSUTILS_EXPORT LogType
25  {
26  public:
29  {
30  kINFO,
31  kWARNING,
32  kERROR,
33  kCOMMAND
34  };
35 
38 
40  virtual ~LogType();
41 
43  void flushMessage(MessageType mType, const std::string &msg);
44 
46  virtual void info(const std::string &msg);
47 
49  virtual void warning(const std::string &msg);
50 
52  virtual void error(const std::string &msg);
53 
55  virtual void cmd(const std::string &msg);
56 
57  };
58 
60  class ATOMSUTILS_EXPORT LogProxy
61  {
62  public:
63 
66 
68  LogProxy(const LogProxy &other);
69 
72 
73 #ifdef ATOMS_UNREAL
74  LogProxy& operator<<(const std::string& value);
75  LogProxy& operator<<(const char* value);
76  LogProxy& operator<<(const double value);
77  LogProxy& operator<<(const int value);
78  LogProxy& operator<<(const unsigned int value);
79 #ifndef ATOMS_32
80  LogProxy& operator<<(const size_t value);
81 #endif
82  LogProxy& operator<<(const bool value);
83 
84  LogProxy& operator<<(const float value);
85  LogProxy& operator<<(const short value);
86  LogProxy& operator<<(const unsigned short value);
87  LogProxy& operator<<(const long value);
88 
89  LogProxy& operator<<(const AtomsMath::Vector2& value);
90  LogProxy& operator<<(const AtomsMath::Vector2f& value);
91  LogProxy& operator<<(const AtomsMath::Vector3& value);
92  LogProxy& operator<<(const AtomsMath::Vector3f& value);
93  LogProxy& operator<<(const AtomsMath::Vector4& value);
94  LogProxy& operator<<(const AtomsMath::Vector4f& value);
95  LogProxy& operator<<(const AtomsMath::Matrix& value);
96  LogProxy& operator<<(const AtomsMath::Matrixf& value);
97  LogProxy& operator<<(const AtomsMath::Quaternion& value);
98  LogProxy& operator<<(const AtomsMath::Quaternionf& value);
99  LogProxy& operator<<(const AtomsMath::Euler& value);
100  LogProxy& operator<<(const AtomsMath::Eulerf& value);
101 
102 #else
104  template<typename T>
105  inline LogProxy& operator<<(const T& value)
106  {
107  m_msg << value << " ";
108  return *this;
109  }
110 #endif
111 
112  private:
113 
115  std::stringstream m_msg;
116 
118  LogType::MessageType m_mType;
119 
121  LogType* m_logType;
122  };
123 
125  class ATOMSUTILS_EXPORT Logger
126  {
127  public:
128 
131 
133 
135  void setLogType(LogType* logType);
136 
139 
141  static Logger& instance();
142 
145 
147  static LogProxy info();
148 
150  static LogProxy warning();
151 
153  static LogProxy error();
154 
156  static LogProxy cmd();
157 
158  private:
159 
161  ~Logger();
162 
164  Logger(const Logger&);
165 
167  Logger& operator=(const Logger&);
168 
169  private:
170 
172  std::shared_ptr<LogType> m_logType;
173  LogType* m_externalLogType;
174  };
175 #ifndef ATOMS_UNREAL
176  template<>
177  inline LogProxy& LogProxy::operator<<(const AtomsMath::Matrix& value)
178  {
179  m_msg << "( "<< value[0][0] << ", " << value[0][1] << ", " << value[0][2] << ", " << value[0][3] << ", ";
180  m_msg << value[1][0] << ", " << value[1][1] << ", " << value[1][2] << ", " << value[1][3] << ", ";
181  m_msg << value[2][0] << ", " << value[2][1] << ", " << value[2][2] << ", " << value[2][3] << ", ";
182  m_msg << value[3][0] << ", " << value[3][1] << ", " << value[3][2] << ", " << value[3][3] << " ) ";
183  return *this;
184  }
185 
186  template<>
187  inline LogProxy& LogProxy::operator<<(const AtomsMath::Matrixf& value)
188  {
189  m_msg << "( " << value[0][0] << ", " << value[0][1] << ", " << value[0][2] << ", " << value[0][3] << ", ";
190  m_msg << value[1][0] << ", " << value[1][1] << ", " << value[1][2] << ", " << value[1][3] << ", ";
191  m_msg << value[2][0] << ", " << value[2][1] << ", " << value[2][2] << ", " << value[2][3] << ", ";
192  m_msg << value[3][0] << ", " << value[3][1] << ", " << value[3][2] << ", " << value[3][3] << " ) ";
193  return *this;
194  }
195 #endif
196 }
Logger proxy class.
Definition: Logger.h:61
LogProxy(LogType *l, LogType::MessageType mType)
Constructor.
~LogProxy()
Destructor.
LogProxy(const LogProxy &other)
Copy constructor.
LogProxy & operator<<(const T &value)
output function
Definition: Logger.h:105
Log type class.
Definition: Logger.h:25
LogType()
Constructor.
virtual void info(const std::string &msg)
Info log function.
void flushMessage(MessageType mType, const std::string &msg)
flush message
virtual void warning(const std::string &msg)
Warning log message.
virtual void cmd(const std::string &msg)
Cmd log message.
virtual ~LogType()
Destructor.
MessageType
Message type.
Definition: Logger.h:29
virtual void error(const std::string &msg)
Error log message.
Logger class.
Definition: Logger.h:126
static Logger & instance()
Singleton access.
static LogProxy log(LogType::MessageType mType)
Get logger proxy.
static LogProxy cmd()
Get logger proxy error.
static LogProxy warning()
Get logger proxy warning.
Logger()
Constructor.
static LogProxy error()
Get logger proxy error.
LogType * logType()
Get logger type.
static LogProxy info()
Get logger proxy info.
void setLogType(LogType *logType)
Set logger type.
AtomsCore namespace.
Definition: Base64.h:13