Atoms Crowd  4.1.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
103  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(std::shared_ptr<LogType>& logType);
136 
138  std::shared_ptr<LogType> logType();
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  };
174 #ifndef ATOMS_UNREAL
175  template<>
176  inline LogProxy& LogProxy::operator<<(const AtomsMath::Matrix& value)
177  {
178  m_msg << "( "<< value[0][0] << ", " << value[0][1] << ", " << value[0][2] << ", " << value[0][3] << ", ";
179  m_msg << value[1][0] << ", " << value[1][1] << ", " << value[1][2] << ", " << value[1][3] << ", ";
180  m_msg << value[2][0] << ", " << value[2][1] << ", " << value[2][2] << ", " << value[2][3] << ", ";
181  m_msg << value[3][0] << ", " << value[3][1] << ", " << value[3][2] << ", " << value[3][3] << " ) ";
182  return *this;
183  }
184 
185  template<>
186  inline LogProxy& LogProxy::operator<<(const AtomsMath::Matrixf& value)
187  {
188  m_msg << "( " << value[0][0] << ", " << value[0][1] << ", " << value[0][2] << ", " << value[0][3] << ", ";
189  m_msg << value[1][0] << ", " << value[1][1] << ", " << value[1][2] << ", " << value[1][3] << ", ";
190  m_msg << value[2][0] << ", " << value[2][1] << ", " << value[2][2] << ", " << value[2][3] << ", ";
191  m_msg << value[3][0] << ", " << value[3][1] << ", " << value[3][2] << ", " << value[3][3] << " ) ";
192  return *this;
193  }
194 #endif
195 }
AtomsUtils::Logger::cmd
static LogProxy cmd()
Get logger proxy error.
AtomsUtils::LogType
Log type class.
Definition: Logger.h:25
AtomsUtils::Logger::instance
static Logger & instance()
Singleton access.
AtomsUtils::LogProxy::LogProxy
LogProxy(const LogProxy &other)
Copy constructor.
AtomsUtils::LogType::LogType
LogType()
Constructor.
AtomsUtils::LogType::flushMessage
void flushMessage(MessageType mType, const std::string &msg)
flush message
AtomsUtils
AtomsCore namespace.
Definition: Base64.h:13
AtomsUtils::LogProxy
Logger proxy class.
Definition: Logger.h:61
AtomsUtils::LogType::MessageType
MessageType
Message type.
Definition: Logger.h:29
AtomsUtils::Logger::Logger
Logger()
Constructor.
AtomsUtils::LogType::warning
virtual void warning(const std::string &msg)
Warning log message.
AtomsUtils::Logger::log
static LogProxy log(LogType::MessageType mType)
Get logger proxy.
AtomsUtils::LogType::info
virtual void info(const std::string &msg)
Info log function.
AtomsUtils::Logger::logType
std::shared_ptr< LogType > logType()
Get logger type.
AtomsUtils::LogType::cmd
virtual void cmd(const std::string &msg)
Cmd log message.
AtomsUtils::Logger
Logger class.
Definition: Logger.h:126
AtomsUtils::Logger::setLogType
void setLogType(std::shared_ptr< LogType > &logType)
Set logger type.
AtomsUtils::Logger::warning
static LogProxy warning()
Get logger proxy warning.
AtomsUtils::LogProxy::LogProxy
LogProxy(LogType *l, LogType::MessageType mType)
Constructor.
AtomsUtils::Logger::info
static LogProxy info()
Get logger proxy info.
AtomsUtils::LogProxy::operator<<
LogProxy & operator<<(const T &value)
output function
Definition: Logger.h:105
AtomsUtils::LogType::~LogType
virtual ~LogType()
Destructor.
AtomsUtils::LogType::error
virtual void error(const std::string &msg)
Error log message.
AtomsUtils::Logger::error
static LogProxy error()
Get logger proxy error.
AtomsUtils::LogProxy::~LogProxy
~LogProxy()
Destructor.