#ifndef __OSTREAM_PRINTF_HPP__
#define __OSTREAM_PRINTF_HPP__
  #include <iostream>
#include <string>
  ///////////////////////////////////////////////////////////////////////////////
// ostream_printf
///////////////////////////////////////////////////////////////////////////////
class ostream_printf {
public:
  ostream_printf(std::ostream& stream_, const char fmt_[])
    : m_stream(stream_)
    , m_format(fmt_)
    , m_pos(0)
  {
    /* print out initial static text data */
    printStaticData();
  }
    ~ostream_printf()
  {
    /* print out remaining static text data */
    printStaticData();
      /* entire formatting string was not used, too few arguments */
    invariant( m_format[m_pos] == '\0' );
  }
    inline ostream_printf& operator<<(bool  value_)                   { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(void* value_)                   { parseFormatString(); m_stream << value_; return *this; }
                                                                  
  inline ostream_printf& operator<<(char  value_)                   { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(short value_)                   { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(int   value_)                   { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(long  value_)                   { parseFormatString(); m_stream << value_; return *this; }
                                                                  
  inline ostream_printf& operator<<(unsigned char   value_)         { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(unsigned short  value_)         { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(unsigned int    value_)         { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(unsigned long   value_)         { parseFormatString(); m_stream << value_; return *this; }
                                                                  
  inline ostream_printf& operator<<(float  value_)                  { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(double value_)                  { parseFormatString(); m_stream << value_; return *this; }
                                                                  
  inline ostream_printf& operator<<(const char*           value_)   { parseFormatString(); m_stream << value_; return *this; }
  inline ostream_printf& operator<<(const unsigned char*  value_)   { parseFormatString(); m_stream << value_; return *this; }
     
protected:
    /* set stream formattings options */
  void parseFormatString();
    /* output static text data inside formatting string */
  void printStaticData();
  private:
    /* disable assignment operator and copy constructor */
  ostream_printf( ostream_printf& temp_ );
  ostream_printf& operator=( ostream_printf& temp_ );
    std::ostream& m_stream;
  const char*   m_format;
  int           m_pos;
};
  ///////////////////////////////////////////////////////////////////////////////
//  oprintf
///////////////////////////////////////////////////////////////////////////////
inline void oprintf(std::ostream& stream_, const char fmt_[])
{
  ostream_printf print(stream_,fmt_);
}
//-----------------------------------------------------------------------------
template <class T0>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0)
{
  ostream_printf print(stream_,fmt_);
  print << t0;
}
//-----------------------------------------------------------------------------
template <class T0,class T1>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2, T3 t3,T4 t4,T5 t5)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6>
inline void oprintf(std::ostream& stream_, const char fmt_[], T0 t0, T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8,class T9>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8 << t9;
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8,class T9,class T10>
inline void oprintf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9,T10 t10)
{
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8 << t9 << t10;
}
  ///////////////////////////////////////////////////////////////////////////////
//  debugf
///////////////////////////////////////////////////////////////////////////////
inline void debugf(std::ostream& stream_, const char fmt_[])
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
#endif
}
//-----------------------------------------------------------------------------
template <class T0>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2, T3 t3,T4 t4,T5 t5)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6>
inline void debugf(std::ostream& stream_, const char fmt_[], T0 t0, T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8,class T9>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8 << t9;
#endif
}
//-----------------------------------------------------------------------------
template <class T0,class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8,class T9,class T10>
inline void debugf(std::ostream& stream_, const char fmt_[],T0 t0,T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9,T10 t10)
{
#ifndef NDEBUG
  ostream_printf print(stream_,fmt_);
  print << t0 << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8 << t9 << t10;
#endif
}
  
#endif   |