00001
00015 #pragma once
00016
00017 #include "CompositeLoggable.h"
00018 #include "Loggable.h"
00019 #include "LogContentsPrinter.h"
00020 #include "Chain.h"
00021 #include "StreamOperators.h"
00022 #include "LoggableTraits.h"
00023
00024 #include "TStd.h"
00025 #include <vector>
00026
00027 namespace Nvidia {
00028 namespace Logging {
00029
00035 template <typename ChainType>
00036 class ChainLoggable : public CompositeLoggable
00037 {
00038 protected:
00040 const ChainType& m_wrappedChain;
00041
00042 public:
00048 ChainLoggable(const ChainType& chain) : m_wrappedChain(chain) {}
00049
00051 ChainLoggable(const ChainLoggable& chainLoggable)
00052 {
00053 m_wrappedChain = chainLoggable.m_wrappedChain;
00054 }
00055
00057 ChainLoggable& operator=(const ChainLoggable& chainLoggable)
00058 {
00059 m_wrappedChain = chainLoggable.m_wrappedChain;
00060 return *this;
00061 }
00062
00063 public:
00069 virtual void LogContentsOn(LogContentsPrinter& logContentsPrinter) const
00070 {
00071 LogChainOn(m_wrappedChain, logContentsPrinter);
00072 }
00073
00079 virtual std::tstring GetStringValue() const
00080 {
00081 std::tostringstream stream;
00082
00083
00084 AppendChainTo(m_wrappedChain.GetTail(), stream);
00085 AppendChainElementTo(m_wrappedChain.GetHead(), stream);
00086 return stream.str();
00087 }
00088
00089 private:
00095 template<typename HeadType, typename TailType>
00096 void LogChainOn(const Chain<HeadType, TailType>& chain, LogContentsPrinter& logContentsPrinter) const
00097 {
00098 LogChainOn(chain.GetTail(), logContentsPrinter);
00099 logContentsPrinter.LogContent(_T(""), chain.GetHead());
00100 }
00101
00105 template<>
00106 void LogChainOn<NullType, NullType>(const EmptyChain&, LogContentsPrinter&) const {}
00107
00113 template<typename HeadType, typename TailType>
00114 void AppendChainTo(const Chain<HeadType, TailType>& chain, std::tostringstream& stream) const
00115 {
00116 AppendChainTo(chain.GetTail(), stream);
00117 AppendChainElementTo(chain.GetHead(), stream);
00118 stream << _T(" ");
00119 }
00120
00122 template<typename HeadType>
00123 static void AppendChainElementTo(HeadType head, std::tostringstream& stream)
00124 {
00125 typename LoggableTraits<HeadType>::LoggableType loggable(head);
00126 stream << loggable;
00127 }
00128
00134 template<typename T>
00135 static void AppendChainElementTo(std::vector<T>& head, std::tostringstream& stream)
00136 {
00137 stream << head;
00138 }
00139
00143 template<>
00144 void AppendChainTo(const EmptyChain&, std::tostringstream&) const
00145 {}
00146 };
00147
00149 template <typename ChainType>
00150 ChainLoggable<ChainType> MakeChainLoggable(const ChainType& chain)
00151 {
00152 return ChainLoggable<ChainType>(chain);
00153 }
00154
00155 }
00156 }