/*------------------------------------------------------------------------------
 src/lib/dj/djDbg.h
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

#ifndef DJ_DBG_H
#define DJ_DBG_H
#include <djStr.h>
#include <djMap.h>
#include <djTime.h>

namespace dj {

// Debugging messages.
//
class Dbg {
public:

  Dbg();
  Dbg(const char *);
  Dbg(const Str &);
  ~Dbg();
  
  // Indent.
  //
  void begin();
  void end();
  void operator ++ ();
  void operator -- ();
  
  // Print.
  //
  enum LINE { BEGIN, END };
  Dbg & operator << (LINE);
  Dbg & operator << (const char *);
  Dbg & operator << (const Str &);
  static int _print;

private:

  void add(const Str &);
  
  LINE _begin, _end;
  Timer _timer;
  Str _tmp;
};

#ifdef DJ_DBG
#define DJ_DBG_FNC(in) dj::Dbg _dbg(in)
#define DJ_DBG_BEGIN() _dbg.begin()
#define DJ_DBG_END() _dbg.end()
#define DJ_DBG_PRN(in) _dbg << dj::Dbg::BEGIN << in << dj::Dbg::END
#else
#define DJ_DBG_FNC(in)
#define DJ_DBG_BEGIN()
#define DJ_DBG_END()
#define DJ_DBG_PRN(in)
#endif

class DbgLog {
public:
  DbgLog() { Dbg::_print++; }
  ~DbgLog() { Dbg::_print--; }
};
#ifdef DJ_DBG
#define DJ_DBG_LOG() dj::DbgLog _dbgLog
#else
#define DJ_DBG_LOG()
#endif

template <class T>
Dbg & operator << (Dbg &, const T &);
Dbg & operator << (Dbg &, bool);
Dbg & operator << (Dbg &, const StrList &);
template <class Key, class Value>
Dbg & operator << (Dbg &, const Map<Key, Value> &);

const Str dbgBits(uint32_t);
const Str dbgBits(float);

}

#include <djDbg_.h>
#endif
