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 typedef std::pair<std::string, std::string>
Message;
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();
377 std::ostream* outputStream_ =
nullptr;
380 bool integrateDateTime_ =
false;
386 static constexpr
unsigned int maxMessages_ = 5000u;
388 #if defined(__APPLE__)
402 #ifdef OCEAN_DEACTIVATED_MESSENGER
425 template <
bool tActive>
770 class OCEAN_BASE_EXPORT
Log
790 template <
typename TStream>
797 template <
typename TObject,
typename =
void>
801 static constexpr
bool value =
false;
809 template <
typename TObject>
810 struct ShiftOperatorChecker<TObject, std::void_t<decltype( std::declval<TStream&>() << std::declval<TObject>())>>
813 static constexpr bool value = true;
830 static inline DebugMessageObject debug();
836 static inline MessageObject info();
842 static inline MessageObject warning();
848 static inline MessageObject error();
873 template <typename T, typename TStream = MessageObject>
874 static constexpr bool isSupported();
877 inline Messenger::MessageOutput Messenger::outputType() const
879 const ScopedLock scopedLock(lock_);
883 inline size_t Messenger::informations() const
885 const ScopedLock scopedLock(lock_);
886 return informationMessageQueue_.size();
889 inline size_t Messenger::warnings() const
891 const ScopedLock scopedLock(lock_);
892 return warningMessageQueue_.size();
895 inline size_t Messenger::errors() const
897 const ScopedLock scopedLock(lock_);
898 return errorMessageQueue_.size();
901 inline bool Messenger::integrateDateTime() const
903 const ScopedLock scopedLock(lock_);
904 return integrateDateTime_;
907 inline bool Messenger::empty() const
909 const ScopedLock scopedLock(lock_);
910 return informationMessageQueue_.empty() && warningMessageQueue_.empty() && errorMessageQueue_.empty();
913 template <bool tActive>
914 inline MessageObject<tActive>::MessageObject(const MessageType type) :
920 template <bool tActive>
921 inline MessageObject<tActive>::MessageObject(const MessageType type, std::string&& location) :
922 location_(std::move(location)),
928 template <bool tActive>
929 inline MessageObject<tActive>::MessageObject(const MessageType type, std::string&& location, std::string&& message) :
930 message_(std::move(message)),
931 location_(std::move(location)),
937 template <bool tActive>
938 inline MessageObject<tActive>::~MessageObject()
940 if (!message_.empty())
942 Messenger::get().push(type_, std::move(location_), std::move(message_));
946 template <bool tActive>
947 inline MessageObject<tActive>& MessageObject<tActive>::newLine(const bool condition)
957 template <bool tActive>
958 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(std::string&& message)
960 if (message_.empty())
962 message_ = std::move(message);
972 template <bool tActive>
973 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const std::string& message)
979 template <bool tActive>
980 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const char* message)
982 if (message != nullptr)
984 message_ += std::string(message);
990 template <bool tActive>
991 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const double message)
993 message_ += String::toAString(message);
997 template <bool tActive>
998 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const float message)
1000 message_ += String::toAString(message);
1004 template <bool tActive>
1005 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const int message)
1007 message_ += String::toAString(message);
1011 template <bool tActive>
1012 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const unsigned int message)
1014 message_ += String::toAString(message);
1018 template <bool tActive>
1019 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long message)
1021 message_ += String::toAString(message);
1025 template <bool tActive>
1026 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long long message)
1028 message_ += String::toAString(message);
1032 template <bool tActive>
1033 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const unsigned long long message)
1035 message_ += String::toAString(message);
1039 template <bool tActive>
1040 inline MessageObject<tActive>& MessageObject<tActive>::operator<<(const long unsigned int message)
1042 message_ += String::toAString(message);
1046 template <bool tActive>
1047 inline void MessageObject<tActive>::operator<<(const MessageObject<tActive>& messageObject)
1049 ocean_assert_and_suppress_unused(messageObject.type_ == Messenger::TYPE_UNDEFINED, messageObject);
1051 if (!message_.empty())
1053 Messenger::get().push(type_, std::string(location_), std::move(message_));
1059 inline Log::DebugMessageObject Log::debug()
1061 return DebugMessageObject(Messenger::TYPE_DEBUG);
1064 inline Log::MessageObject Log::info()
1066 return MessageObject(Messenger::TYPE_INFORMATION);
1069 inline Log::MessageObject Log::warning()
1071 return MessageObject(Messenger::TYPE_WARNING);
1074 inline Log::MessageObject Log::error()
1076 return MessageObject(Messenger::TYPE_ERROR);
1079 template <typename T, typename TStream>
1080 constexpr bool Log::isSupported()
1082 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:771
Ocean::MessageObject< Messenger::isActive() &&Messenger::isDebugBuild()> DebugMessageObject
Definition of a debug message object, only active on debug builds and if Messenger::isActive() == tru...
Definition: Messenger.h:782
Ocean::MessageObject< Messenger::isActive()> MessageObject
Definition of a default message object, only active if Messenger::isActive() == true.
Definition: Messenger.h:777
MessageObject & operator<<(const long)
Pushes another information message.
Definition: Messenger.h:709
MessageObject(const MessageObject &messageObject)=default
Copy-constructs a new message object.
MessageObject & operator<<(std::string &&)
Pushes another information message.
Definition: Messenger.h:646
MessageObject & operator<<(const long unsigned int)
Pushes another information message.
Definition: Messenger.h:736
MessageObject(const MessageType)
Creates a new message object.
Definition: Messenger.h:600
MessageObject & operator<<(const std::string &)
Pushes another information message.
Definition: Messenger.h:655
MessageObject & operator<<(const float)
Pushes another information message.
Definition: Messenger.h:682
void operator<<(const MessageObject &)
Pushes another information message.
Definition: Messenger.h:744
MessageObject & newLine(const bool)
Adds a new line to this message object if a specified condition holds.
Definition: Messenger.h:637
MessageObject & operator<<(const double)
Pushes another information message.
Definition: Messenger.h:673
MessageObject & operator<<(const unsigned int)
Pushes another information message.
Definition: Messenger.h:700
MessageObject & operator<<(const unsigned long long)
Pushes another information message.
Definition: Messenger.h:727
MessageObject & operator<<(const int)
Pushes another information message.
Definition: Messenger.h:691
MessageObject & operator<<(const char *)
Pushes another information message.
Definition: Messenger.h:664
~MessageObject()=default
Destructs a message object.
MessageObject(const MessageType, std::string &&)
Creates a new message object.
Definition: Messenger.h:608
MessageObject(const MessageType, std::string &&, std::string &&)
Creates a new message object.
Definition: Messenger.h:760
MessageObject & operator<<(const long long)
Pushes another information message.
Definition: Messenger.h:718
MessageObject & newLine()
Adds a new line to this message object if a specified condition holds.
Definition: Messenger.h:628
MessageObject & operator=(const MessageObject &messageObject)=default
Assign operator.
Messenger object, one object for each message.
Definition: Messenger.h:427
MessageObject & operator=(const MessageObject &messageObject)=default
Assign operator.
std::string message_
Entire message.
Definition: Messenger.h:570
std::string location_
Location of the message.
Definition: Messenger.h:573
MessageObject & newLine(const bool condition=true)
Adds a new line to this message object if a specified condition holds.
Definition: Messenger.h:947
MessageObject & operator<<(std::string &&message)
Pushes another information message.
Definition: Messenger.h:958
MessageObject(const MessageObject &messageObject)=default
Copy-constructs a new message object.
MessageObject(const MessageType type)
Creates a new message object.
Definition: Messenger.h:914
~MessageObject()
Destructs a message object.
Definition: Messenger.h:938
Messenger::MessageType type_
Type of this messenger.
Definition: Messenger.h:576
This class implements a messenger for information, warning or error messages.
Definition: Messenger.h:93
static constexpr bool isActive()
Returns whether the messenger is active on this build.
Definition: Messenger.h:400
std::string lastErrorMessage_
Last error message.
Definition: Messenger.h:371
static constexpr bool isDebugBuild()
Returns whether the messenger is used on a debug build.
Definition: Messenger.h:409
MessageQueue informationMessageQueue_
Information message queue.
Definition: Messenger.h:356
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:383
std::queue< Message > MessageQueue
Definition of a message queue.
Definition: Messenger.h:147
MessageQueue errorMessageQueue_
Error message queue.
Definition: Messenger.h:362
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:368
bool setOutputStream(std::ostream &stream)
Sets the message output to an output stream.
void clear()
Clears all message queues.
std::ofstream fileOutputStream_
File output stream.
Definition: Messenger.h:374
MessageQueue debugMessageQueue_
Debug message queue.
Definition: Messenger.h:349
static void writeToDebugOutput(const std::string &message)
Writes a message to the most suitable debug output of the current platform.
std::pair< std::string, std::string > Message
Definition of a message.
Definition: Messenger.h:142
MessageQueue warningMessageQueue_
Warning message queue.
Definition: Messenger.h:359
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:352
static void writeMessageToDebugWindowApple(const std::string &message)
Write message to Apple-specific log facility.
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:365
bool popInformation(std::string &location, std::string &message, bool *isNew=nullptr)
Pops the first information message from the message queue.
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:799
Helper class allowing to specify a specific message object or stream type.
Definition: Messenger.h:792