- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# GenericLogPrinter.h

Go to the documentation of this file.

    00001
    00015 #pragma once
    00016
    00017 #include "ILogPrinter.h"
    00018 #include "LogInfo.h"
    00019 #include "CompositeLoggable.h"
    00020 #include "IGenericLogManager.h"
    00021
    00022 #include <boost/foreach.hpp>
    00023 #include <boost/any.hpp>
    00024 #include <vector>
    00025
    00026 namespace Nvidia {
    00027 namespace Logging {
    00028
    00029 namespace Test {
    00030     class LoggerTest;
    00031     class LoggerConstructorTest;
    00032 }
    00033
    00041 template <typename T>
    00042 class GenericLogPrinter : public ILogPrinter
    00043 {
    00044     friend class Nvidia::Logging::Test::LoggerTest;
    00045     friend class Nvidia::Logging::Test::LoggerConstructorTest;
    00046 private:
    00048     std::vector<IGenericLogManager<T>*> m_LogManagers;
    00049
    00050 public:
    00061     void AddLogManager(ILogManager* logManager)
    00062     {
    00063         IGenericLogManager<T>* manager = dynamic_cast<IGenericLogManager<T>*> (logManager);
    00064         if ( manager == NULL )
    00065             throw std::bad_cast();
    00066         m_LogManagers.push_back(manager);
    00067     }
    00068
    00076     void PrintMessage(const LogInfo& logInfo, const CompositeLoggable& message)
    00077     {
    00078         T formattedMessage = DoFormatMessage(logInfo, message);
    00079
    00080         BOOST_FOREACH(IGenericLogManager<T>* logManager, m_LogManagers)
    00081         {
    00082             logManager->ManageMessage(formattedMessage);
    00083         }
    00084     }
    00085
    00086 private:
    00093     virtual T DoFormatMessage(const LogInfo& logInfo, const CompositeLoggable& message) = 0;
    00094 };
    00095
    00096 }
    00097 }