- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# Chain.h

Go to the documentation of this file.

    00001
    00015 #pragma once
    00016
    00017 #include "Loggable.h"
    00018
    00019 #include <vector>
    00020
    00021 #include <boost/utility/enable_if.hpp>
    00022 #include <boost/type_traits.hpp>
    00023
    00024 namespace Nvidia {
    00025 namespace Logging {
    00026
    00028 struct NullType {};
    00029
    00044 template<typename HeadType, typename TailType>
    00045 class Chain
    00046 {
    00047     template <typename TailType2, typename HeadType2>
    00048     friend class Chain;
    00049
    00050 private:
    00052     HeadType m_head;
    00054     const TailType& m_tail;
    00055
    00056 public:
    00058     Chain(HeadType head, const TailType& tail): m_head(head), m_tail(tail) {}
    00059
    00061     Chain(const Chain<HeadType, TailType>& aChain)
    00062     {
    00063         m_head = aChain.Head;
    00064         m_tail = aChain.Tail;
    00065     }
    00066
    00068     Chain<HeadType, TailType>& operator=(const Chain<HeadType, TailType>& aChain)
    00069     {
    00070         m_head = aChain.Head;
    00071         m_tail = aChain.Tail;
    00072         return *this;
    00073     }
    00074
    00076     HeadType GetHead() const
    00077     {
    00078         return m_head;
    00079     }
    00080
    00082     const TailType& GetTail() const
    00083     {
    00084         return m_tail;
    00085     }
    00086
    00093     template<typename T>
    00094     typename boost::enable_if_c<boost::is_arithmetic<T>::value,
    00095     Chain<T, Chain<HeadType, TailType> > >::type
    00096     operator+(T head)
    00097     {
    00098         return Chain<T, Chain<HeadType, TailType> >(head, *this);
    00099     }
    00100
    00107     template<typename T>
    00108     typename boost::disable_if_c<boost::is_arithmetic<T>::value,
    00109     Chain<const T&, Chain<HeadType, TailType> > >::type
    00110     operator+(const T& head)
    00111     {
    00112         return Chain<const T&, Chain<HeadType, TailType> >(head, *this);
    00113     }
    00114 };
    00115
    00117 typedef Chain<NullType, NullType> EmptyChain;
    00118
    00120 inline EmptyChain MakeEmptyChain()
    00121 {
    00122     return Chain<NullType, NullType>(NullType(), NullType());
    00123 }
    00124
    00125 }
    00126 }