- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# StreamOperators.h

    00001
    00015 #pragma once
    00016
    00017 #include "TStd.h"
    00018 #include "Utils.h"
    00019 #include "LogLevel.h"
    00020 #include "Loggable.h"
    00021 #include <vector>
    00022
    00023 #include <boost/lexical_cast.hpp>
    00024 #include <boost/algorithm/string/replace.hpp>
    00025
    00026 namespace Nvidia {
    00027 namespace Logging {
    00028
    00029 class Loggable;
    00030
    00031 }
    00032 }
    00033
    00034 //TODO: invalid w/ regards to C++ standard, needs fix
    00035 namespace std {
    00036
    00037 template<typename T>
    00038 std::tostream& operator<<(std::tostream& os, const std::vector<T>&)
    00039 {
    00040     // We don't really want to create an instance of T.
    00041     // Creating a pointer and cutting the " *" part from the type name instead.
    00042     T *t;
    00043     t = NULL;
    00044     std::tstring typeName = boost::lexical_cast<std::tstring>(typeid(t).name());
    00045
    00046     os << _T("vector<") << Nvidia::Logging::Utils::GenerateHumanReadableTypeName(typeName) << _T(">") ;
    00047     return os;
    00048 }
    00049
    00050 inline std::tostream& operator<<(std::tostream& os, const Nvidia::Logging::Loggable& loggable)
    00051 {
    00052     os << loggable.GetStringValue();
    00053     return os;
    00054 }
    00055
    00056 inline std::tostream& operator<<(std::tostream& os, const Nvidia::Logging::LogLevel& logLevel)
    00057 {
    00058     switch ( logLevel )
    00059     {
    00060     case Nvidia::Logging::LogLevel_System:
    00061         os << _T("System");
    00062         break;
    00063     case Nvidia::Logging::LogLevel_Critical:
    00064         os << _T("Critical");
    00065         break;
    00066     case Nvidia::Logging::LogLevel_Error:
    00067         os << _T("Error");
    00068         break;
    00069     case Nvidia::Logging::LogLevel_Warning:
    00070         os << _T("Warning");
    00071         break;
    00072     case Nvidia::Logging::LogLevel_Debug:
    00073         os << _T("Debug");
    00074         break;
    00075     case Nvidia::Logging::LogLevel_Info:
    00076         os << _T("Info");
    00077         break;
    00078     default:
    00079         //this should not happen
    00080         break;
    00081     }
    00082
    00083     return os;
    00084 }
    00085
    00086 }