output_debug_utils.hxx

Go to the documentation of this file.
00001 #ifndef OUTPUT_DEBUG_UTILS_HXX_
00002 #define OUTPUT_DEBUG_UTILS_HXX_
00003 
00004 #ifdef TRWS_DEBUG_OUTPUT
00005 
00006 #include <iostream>
00007 #include <fstream>
00008 #include <vector>
00009 #include <valarray>
00010 #include <string>
00011 #include <list>
00012 
00013 namespace OUT{
00014 
00015 template<class M>
00016 class nullstreamT: public std::ostream
00017 {
00018 public:
00019    static nullstreamT* Instance()
00020    {
00021       if (!_pInstance) _pInstance = new nullstreamT();
00022       return _pInstance;
00023    };
00024 
00025    template <class T>
00026    nullstreamT& operator << (T& t){return *this;}
00027 private:
00028    nullstreamT(): std::ios(0), std::ostream(0){};  // Private so that it can  not be called
00029    nullstreamT(nullstreamT const&){};             // copy constructor is private
00030    nullstreamT& operator=(nullstreamT const&){return *this;};  // assignment operator is private
00031    static nullstreamT* _pInstance;
00032 };
00033 
00034 template<class M>
00035 nullstreamT<M>* nullstreamT<M>::_pInstance=0;
00036 
00037 typedef nullstreamT<int> nullstream;
00038 
00039    template<typename ArrayType>
00040    std::ostream& operator << (std::ostream& logger,const std::vector<ArrayType>& arr)
00041    {
00042       for (size_t i=0;i<arr.size();++i)
00043          logger << arr[i]<<"; ";
00044       logger <<std::endl;
00045       return logger;
00046    };
00047 
00048    template<typename ArrayType>
00049    std::ostream& operator << (std::ostream& logger,const std::list<ArrayType>& lst)
00050    {
00051       typename std::list<ArrayType>::const_iterator beg=lst.begin(), end=lst.end();
00052       for (;beg!=end;++beg)
00053          logger << *beg<<"; ";
00054       logger <<std::endl;
00055       return logger;
00056    };
00057 
00058    template<typename ArrayType>
00059    std::ostream& operator << (std::ostream& logger,const std::vector<std::vector<ArrayType> >& arr)
00060    {
00061       for (size_t i=0;i<arr.size();++i)
00062          logger << arr[i];
00063       return logger;
00064    };
00065 
00066    template<typename T>
00067    std::ostream& operator << (std::ostream& logger,const std::valarray<T> & arr)
00068    {
00069       for (size_t i=0;i<arr.size();++i)
00070          logger << arr[i]<<", ";
00071       return logger;
00072    };
00073 
00074    template<typename Type1,typename Type2>
00075    std::ostream& operator << (std::ostream& logger, const std::pair<Type1,Type2>& p)
00076    {
00077       logger <<"("<<p.first<<","<<p.second<<")";
00078       return logger;
00079    };
00080 
00081    template<class Iterator>
00082    void saveContainer(std::ostream& fout, Iterator begin, Iterator end)
00083    {
00084       for ( ; begin!=end; ++begin)
00085          fout <<std::scientific<<*begin<<"; ";
00086       fout << std::endl;
00087    }
00088 
00089    template<class Iterator>
00090    void saveContainer(const std::string& filename, Iterator begin, Iterator end)
00091    {
00092       std::ofstream fout(filename.c_str());
00093       saveContainer(fout, begin, end);
00094       fout.close();
00095    };
00096 };
00097 #endif //TRWS_DEBUG_OUTPUT
00098 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:05 2013 for OpenGM by  doxygen 1.6.3