00001
00015 #pragma once
00016
00017 #include "ChainLoggable.h"
00018 #include "TBoostFormat.h"
00019
00020 #include <boost/lexical_cast.hpp>
00021
00022 namespace Nvidia {
00023 namespace Logging {
00024
00030 template <typename ChainType>
00031 class FormattedChainLoggable : public ChainLoggable<ChainType>
00032 {
00033 private:
00035 std::tstring m_format;
00036
00037 public:
00047 FormattedChainLoggable(const ChainType& chain, std::tstring& format) :
00048 ChainLoggable(chain),
00049 m_format(format) {}
00050
00056 virtual std::tstring GetStringValue() const
00057 {
00058 try {
00059 boost::tformat formatter(m_format);
00060 AppendChain(m_wrappedChain, formatter);
00061 return formatter.str();
00062 } catch ( std::exception& exception ) {
00063 return boost::lexical_cast<std::tstring>(exception.what());
00064 }
00065 }
00066
00067 private:
00068 template<typename HeadType, typename TailType>
00069 void AppendChain(const Chain<HeadType, TailType>& chain, boost::tformat& formatter) const
00070 {
00071 AppendChain(chain.GetTail(), formatter);
00072 formatter % chain.GetHead();
00073 }
00074
00075
00076 template<>
00077 void AppendChain(const EmptyChain&, boost::tformat&) const
00078 {}
00079 };
00080
00082 template <typename ChainType>
00083 FormattedChainLoggable<ChainType> MakeFormattedChainLoggable(const ChainType& chain, std::tstring format)
00084 {
00085 return FormattedChainLoggable<ChainType>(chain, format);
00086 }
00087
00088 }
00089 }