| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Debug/BsLog.h"
- #include "Error/BsException.h"
- namespace bs
- {
- LogEntry::LogEntry(const String& msg, UINT32 channel)
- :mMsg(msg), mChannel(channel)
- { }
- Log::Log()
- :mHash(0)
- {
- }
- Log::~Log()
- {
- clear();
- }
- void Log::logMsg(const String& message, UINT32 channel)
- {
- RecursiveLock lock(mMutex);
- mUnreadEntries.push(LogEntry(message, channel));
- }
- void Log::clear()
- {
- RecursiveLock lock(mMutex);
- mEntries.clear();
- while (!mUnreadEntries.empty())
- mUnreadEntries.pop();
- mHash++;
- }
- void Log::clear(UINT32 channel)
- {
- RecursiveLock lock(mMutex);
- Vector<LogEntry> newEntries;
- for(auto& entry : mEntries)
- {
- if (entry.getChannel() == channel)
- continue;
- newEntries.push_back(entry);
- }
- mEntries = newEntries;
- Queue<LogEntry> newUnreadEntries;
- while (!mUnreadEntries.empty())
- {
- LogEntry entry = mUnreadEntries.front();
- mUnreadEntries.pop();
- if (entry.getChannel() == channel)
- continue;
- newUnreadEntries.push(entry);
- }
- mUnreadEntries = newUnreadEntries;
- mHash++;
- }
- bool Log::getUnreadEntry(LogEntry& entry)
- {
- RecursiveLock lock(mMutex);
- if (mUnreadEntries.empty())
- return false;
- entry = mUnreadEntries.front();
- mUnreadEntries.pop();
- mEntries.push_back(entry);
- mHash++;
- return true;
- }
- bool Log::getLastEntry(LogEntry& entry)
- {
- if (mEntries.size() == 0)
- return false;
- entry = mEntries.back();
- return true;
- }
- Vector<LogEntry> Log::getEntries() const
- {
- RecursiveLock lock(mMutex);
- return mEntries;
- }
- Vector<LogEntry> Log::getAllEntries() const
- {
- Vector<LogEntry> entries;
- {
- RecursiveLock lock(mMutex);
- for (auto& entry : mEntries)
- entries.push_back(entry);
- Queue<LogEntry> unreadEntries = mUnreadEntries;
- while (!unreadEntries.empty())
- {
- entries.push_back(unreadEntries.front());
- unreadEntries.pop();
- }
- }
- return entries;
- }
- }
|