8#ifndef META_OCEAN_BASE_MESSENGER_H
9#define META_OCEAN_BASE_MESSENGER_H
122 OUTPUT_DISCARDED = 0u,
124 OUTPUT_STANDARD = 1u << 0u,
126 OUTPUT_QUEUED = 1u << 1u,
128 OUTPUT_DEBUG_WINDOW = 1u << 2u,
130 OUTPUT_FILE = 1u << 3u,
132 OUTPUT_STREAM = 1u << 4u,
134 OUTPUT_MAINTENANCE = 1u << 5u
142 using Message = std::pair<std::string, std::string>;
166 bool popDebug(std::string& location, std::string& message,
bool* isNew =
nullptr);
175 bool popInformation(std::string& location, std::string& message,
bool* isNew =
nullptr);
184 bool popWarning(std::string& location, std::string& message,
bool* isNew =
nullptr);
193 bool popError(std::string& location, std::string& message,
bool* isNew =
nullptr);
283 inline size_t informations()
const;
289 inline size_t warnings()
const;
295 inline size_t errors()
const;
303 inline bool integrateDateTime()
const;
309 inline bool empty()
const;
322 static constexpr bool isActive();
328 static constexpr bool isDebugBuild();
350#ifdef OCEAN_PLATFORM_BUILD_ANDROID
362#ifdef OCEAN_PLATFORM_BUILD_APPLE
409 std::ostream* outputStream_ =
nullptr;
412 bool integrateDateTime_ =
false;
418 static constexpr unsigned int maxMessages_ = 5000u;
423#ifdef OCEAN_DEACTIVATED_MESSENGER
446template <
bool tActive>
791class OCEAN_BASE_EXPORT
Log
811 template <
typename TStream>
818 template <
typename TObject,
typename =
void>
822 static constexpr bool value =
false;
830 template <
typename TObject>
831 struct ShiftOperatorChecker<TObject, std::void_t<decltype( std::declval<TStream&>() << std::declval<TObject>())>>
834 static constexpr bool value = true;
851 static inline DebugMessageObject debug();
857 static inline MessageObject info();
863 static inline MessageObject warning();
869 static inline MessageObject error();
894 template <typename T, typename TStream = MessageObject>
895 static constexpr bool isSupported();
898inline Messenger::MessageOutput Messenger::outputType() const
900 const ScopedLock scopedLock(lock_);
904inline size_t Messenger::informations() const
906 const ScopedLock scopedLock(lock_);
907 return informationMessageQueue_.size();
910inline size_t Messenger::warnings() const
912 const ScopedLock scopedLock(lock_);
913 return warningMessageQueue_.size();
916inline size_t Messenger::errors() const
918 const ScopedLock scopedLock(lock_);
919 return errorMessageQueue_.size();
922inline bool Messenger::integrateDateTime() const
924 const ScopedLock scopedLock(lock_);
925 return integrateDateTime_;
928inline bool Messenger::empty() const
930 const ScopedLock scopedLock(lock_);
931 return informationMessageQueue_.empty() && warningMessageQueue_.empty() && errorMessageQueue_.empty();
934template <bool tActive>
935inline MessageObject<tActive>::MessageObject(const MessageType type) :
941template <bool tActive>
942inline MessageObject<tActive>::MessageObject(const MessageType type, std::string&& location) :
943 location_(std::move(location)),
949template <bool tActive>
950inline MessageObject<tActive>::MessageObject(const MessageType type, std::string&& location, std::string&& message) :
951 message_(std::move(message)),
952 location_(std::move(location)),
958template <bool tActive>
959inline MessageObject<tActive>::~MessageObject()
961 if (!message_.empty())
963 Messenger::get().push(type_, std::move(location_), std::move(message_));
967template <bool tActive>
968inline MessageObject<tActive>& MessageObject<tActive>::newLine(const bool condition)
978template <bool tActive>
979inline MessageObject<tActive>& MessageObject<tActive>::operator<<(std::string&& message)
981 if (message_.empty())
983 message_ = std::move(message);
993template <bool tActive>
994inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const std::string& message)
1000template <bool tActive>
1001inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const char* message)
1003 if (message != nullptr)
1005 message_ += std::string(message);
1011template <bool tActive>
1012inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const double message)
1014 message_ += String::toAString(message);
1018template <bool tActive>
1019inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const float message)
1021 message_ += String::toAString(message);
1025template <bool tActive>
1026inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const int message)
1028 message_ += String::toAString(message);
1032template <bool tActive>
1033inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const unsigned int message)
1035 message_ += String::toAString(message);
1039template <bool tActive>
1040inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long message)
1042 message_ += String::toAString(message);
1046template <bool tActive>
1047inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long long message)
1049 message_ += String::toAString(message);
1053template <bool tActive>
1054inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const unsigned long long message)
1056 message_ += String::toAString(message);
1060template <bool tActive>
1061inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long unsigned int message)
1063 message_ += String::toAString(message);
1067template <bool tActive>
1068inline void MessageObject<tActive>::operator<<(const MessageObject<tActive>& messageObject)
1070 ocean_assert_and_suppress_unused(messageObject.type_ == Messenger::TYPE_UNDEFINED, messageObject);
1072 if (!message_.empty())
1074 Messenger::get().push(type_, std::string(location_), std::move(message_));
1080inline Log::DebugMessageObject Log::debug()
1082 return DebugMessageObject(Messenger::TYPE_DEBUG);
1085inline Log::MessageObject Log::info()
1087 return MessageObject(Messenger::TYPE_INFORMATION);
1090inline Log::MessageObject Log::warning()
1092 return MessageObject(Messenger::TYPE_WARNING);
1095inline Log::MessageObject Log::error()
1097 return MessageObject(Messenger::TYPE_ERROR);
1100template <typename T, typename TStream>
1101constexpr bool Log::isSupported()
1103 return StreamHelper<TStream>::template ShiftOperatorChecker<T>::value;
This class implements a recursive lock object.
Definition Lock.h:31
This class provides access to three different Message objects, e.g., for regular information,...
Definition Messenger.h:792
MessageObject & operator<<(std::string &&)
Pushes another information message.
Definition Messenger.h:667
MessageObject(const MessageObject &messageObject)=default
Copy-constructs a new message object.
MessageObject & newLine(const bool)
Adds a new line to this message object if a specified condition holds.
Definition Messenger.h:658
MessageObject(const MessageType)
Creates a new message object.
Definition Messenger.h:621
MessageObject & operator<<(const long long)
Pushes another information message.
Definition Messenger.h:739
MessageObject & operator<<(const long unsigned int)
Pushes another information message.
Definition Messenger.h:757
void operator<<(const MessageObject &)
Pushes another information message.
Definition Messenger.h:765
MessageObject & operator=(const MessageObject &messageObject)=default
Assign operator.
MessageObject & operator<<(const long)
Pushes another information message.
Definition Messenger.h:730
MessageObject & operator<<(const float)
Pushes another information message.
Definition Messenger.h:703
MessageObject & operator<<(const std::string &)
Pushes another information message.
Definition Messenger.h:676
MessageObject & newLine()
Adds a new line to this message object if a specified condition holds.
Definition Messenger.h:649
MessageObject & operator<<(const int)
Pushes another information message.
Definition Messenger.h:712
~MessageObject()=default
Destructs a message object.
MessageObject & operator<<(const char *)
Pushes another information message.
Definition Messenger.h:685
MessageObject(const MessageType, std::string &&)
Creates a new message object.
Definition Messenger.h:629
MessageObject & operator<<(const double)
Pushes another information message.
Definition Messenger.h:694
MessageObject(const MessageType, std::string &&, std::string &&)
Creates a new message object.
Definition Messenger.h:781
MessageObject & operator<<(const unsigned long long)
Pushes another information message.
Definition Messenger.h:748
MessageObject & operator<<(const unsigned int)
Pushes another information message.
Definition Messenger.h:721
Messenger object, one object for each message.
Definition Messenger.h:448
std::string message_
Entire message.
Definition Messenger.h:591
std::string location_
Location of the message.
Definition Messenger.h:594
MessageObject & newLine(const bool condition=true)
Adds a new line to this message object if a specified condition holds.
Definition Messenger.h:968
MessageObject & operator<<(std::string &&message)
Pushes another information message.
Definition Messenger.h:979
MessageObject(const MessageObject &messageObject)=default
Copy-constructs a new message object.
MessageObject & operator=(const MessageObject &messageObject)=default
Assign operator.
~MessageObject()
Destructs a message object.
Definition Messenger.h:959
Messenger::MessageType type_
Type of this messenger.
Definition Messenger.h:597
This class implements a messenger for information, warning or error messages.
Definition Messenger.h:93
static void writeMessageToLogApple(const MessageType messageType, const std::string &message)
Writes a message to Apple's log system.
static constexpr bool isActive()
Returns whether the messenger is active on this build.
Definition Messenger.h:421
void queueMessage(const MessageType messageType, std::string &&locationAndTime, std::string &&message)
Queues a message.
std::string lastErrorMessage_
Last error message.
Definition Messenger.h:403
static constexpr bool isDebugBuild()
Returns whether the messenger is used on a debug build.
Definition Messenger.h:430
MessageQueue informationMessageQueue_
Information message queue.
Definition Messenger.h:388
bool popMessage(MessageType &type, std::string &location, std::string &message, bool *isNew=nullptr)
Pops any first message available of a given type or of any type.
Lock lock_
Messenger lock.
Definition Messenger.h:415
MessageQueue errorMessageQueue_
Error message queue.
Definition Messenger.h:394
void setIntegrateDateTime(const bool state)
Enables or disables the integration of local date/time information into the location information of m...
void clearInformations()
Clears the information message queue.
void clearWarnings()
Clears the warning message queue.
bool popDebug(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first debug message from the message queue.
MessageOutput
Definition of different message output types.
Definition Messenger.h:120
std::string lastWarningMessage_
Last warning message.
Definition Messenger.h:400
bool setOutputStream(std::ostream &stream)
Sets the message output to an output stream.
void clear()
Clears all message queues.
std::queue< Message > MessageQueue
Definition of a message queue.
Definition Messenger.h:147
std::ofstream fileOutputStream_
File output stream.
Definition Messenger.h:406
MessageQueue debugMessageQueue_
Debug message queue.
Definition Messenger.h:381
std::pair< std::string, std::string > Message
Definition of a message.
Definition Messenger.h:142
static void writeToDebugOutput(const std::string &message)
Writes a message to the most suitable debug output of the current platform.
MessageQueue warningMessageQueue_
Warning message queue.
Definition Messenger.h:391
MessageType
Definition of different message types.
Definition Messenger.h:103
@ TYPE_INFORMATION
Information message.
Definition Messenger.h:109
@ TYPE_WARNING
Warning message.
Definition Messenger.h:111
@ TYPE_DEBUG
Debug message, which are not used on release builds (optimized out of the code).
Definition Messenger.h:107
@ TYPE_UNDEFINED
Invalid message type.
Definition Messenger.h:105
std::string popMessage(const MessageType type=TYPE_UNDEFINED, bool *isNew=nullptr)
Pops the oldest message available of a specified type.
~Messenger()
Destructs a messenger object.
std::string lastDebugMessage_
Last debug message.
Definition Messenger.h:384
void flush(std::ostream &stream)
Flushes the current message stack to a given output stream, the output type is unchanged.
void push(const MessageType type, std::string &&location, std::string &&message)
Pushes a new message into the message queue.
bool setOutputType(const MessageOutput type)
Sets the output type of the messenger.
bool popWarning(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first warning message from the message queue.
bool setFileOutput(const std::string &filename)
Sets the message output to a file.
void clearErrors()
Clears the error message queue.
Messenger()
Creates a new messenger object queuing all messages as default.
std::string lastInformationMessage_
Last information message.
Definition Messenger.h:397
bool popInformation(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first information message from the message queue.
static void writeMessageToLogAndroid(const MessageType messageType, const std::string &locationAndTime, const std::string &message)
Writes a message to the Android log system (logcat).
bool popError(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first error message from the message queue.
This template class is the base class for all singleton objects.
Definition Singleton.h:71
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
Helper class to check whether a message object or a stream provides a shift operator for an object wi...
Definition Messenger.h:820
Helper class allowing to specify a specific message object or stream type.
Definition Messenger.h:813