Blame lib/trace.hpp

rpm-build d2b433
/*
rpm-build d2b433
 * libopenraw - trace.h
rpm-build d2b433
 *
rpm-build d2b433
 * Copyright (C) 2006-2015 Hubert Figuiere
rpm-build d2b433
 *
rpm-build d2b433
 * This library is free software: you can redistribute it and/or
rpm-build d2b433
 * modify it under the terms of the GNU Lesser General Public License
rpm-build d2b433
 * as published by the Free Software Foundation, either version 3 of
rpm-build d2b433
 * the License, or (at your option) any later version.
rpm-build d2b433
 *
rpm-build d2b433
 * This library is distributed in the hope that it will be useful,
rpm-build d2b433
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build d2b433
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build d2b433
 * Lesser General Public License for more details.
rpm-build d2b433
 *
rpm-build d2b433
 * You should have received a copy of the GNU Lesser General Public
rpm-build d2b433
 * License along with this library.  If not, see
rpm-build d2b433
 * <http://www.gnu.org/licenses/>.
rpm-build d2b433
 */
rpm-build d2b433
rpm-build d2b433
rpm-build d2b433
#ifndef OR_INTERNALS_TRACE_H_
rpm-build d2b433
#define OR_INTERNALS_TRACE_H_
rpm-build d2b433
rpm-build d2b433
#include <string>
rpm-build d2b433
#include <vector>
rpm-build d2b433
#include <algorithm>
rpm-build d2b433
rpm-build d2b433
#include <libopenraw/debug.h>
rpm-build d2b433
rpm-build d2b433
namespace Debug {
rpm-build d2b433
rpm-build d2b433
/** Log debug messages. printf format.
rpm-build d2b433
 * @param fmt the formt string, printf style
rpm-build d2b433
 * @param func the func name
rpm-build d2b433
 */
rpm-build d2b433
void log(debug_level level, const char* fmt, ...)
rpm-build d2b433
    __attribute__ ((format (printf, 2, 3)));
rpm-build d2b433
rpm-build d2b433
rpm-build d2b433
#define LOGWARN(...) \
rpm-build d2b433
  Debug::log(WARNING, ## __VA_ARGS__)
rpm-build d2b433
rpm-build d2b433
#define LOGERR(...) \
rpm-build d2b433
  Debug::log(ERROR, ## __VA_ARGS__)
rpm-build d2b433
rpm-build d2b433
#define LOGDBG1(...) \
rpm-build d2b433
  Debug::log(DEBUG1, ## __VA_ARGS__)
rpm-build d2b433
rpm-build d2b433
#define LOGDBG2(...) \
rpm-build d2b433
  Debug::log(DEBUG2, ## __VA_ARGS__)
rpm-build d2b433
rpm-build d2b433
/** a basic Trace class for debug */
rpm-build d2b433
class Trace
rpm-build d2b433
{
rpm-build d2b433
public:
rpm-build d2b433
  Trace(debug_level level)
rpm-build d2b433
    : m_level(level)
rpm-build d2b433
    {
rpm-build d2b433
    }
rpm-build d2b433
  Trace & operator<<(int i);
rpm-build d2b433
  Trace & operator<<(const char * s);
rpm-build d2b433
  Trace & operator<<(void *);
rpm-build d2b433
  Trace & operator<<(const std::string & s);
rpm-build d2b433
rpm-build d2b433
  template <class T>
rpm-build d2b433
  Trace & operator<<(const std::vector<T> & v);
rpm-build d2b433
rpm-build d2b433
  static void setDebugLevel(debug_level lvl);
rpm-build d2b433
private:
rpm-build d2b433
  friend void log(debug_level level, const char* fmt, ...);
rpm-build d2b433
  static void print(int i);
rpm-build d2b433
  static int debugLevel; // global debug level
rpm-build d2b433
  int m_level;
rpm-build d2b433
};
rpm-build d2b433
rpm-build d2b433
rpm-build d2b433
template <class T>
rpm-build d2b433
Trace & Trace::operator<<(const std::vector<T> & v)
rpm-build d2b433
{
rpm-build d2b433
  if (m_level <= debugLevel) {
rpm-build d2b433
    std::for_each(v.cbegin(), v.cend(),
rpm-build d2b433
                  [](T a) {
rpm-build d2b433
                    print(a);
rpm-build d2b433
                  });
rpm-build d2b433
  }
rpm-build d2b433
  return *this;
rpm-build d2b433
}
rpm-build d2b433
rpm-build d2b433
}
rpm-build d2b433
rpm-build d2b433
#endif
rpm-build d2b433
/*
rpm-build d2b433
  Local Variables:
rpm-build d2b433
  mode:c++
rpm-build d2b433
  c-file-style:"stroustrup"
rpm-build d2b433
  c-file-offsets:((innamespace . 0))
rpm-build d2b433
  tab-width:2
rpm-build d2b433
  c-basic-offset:2
rpm-build d2b433
  indent-tabs-mode:nil
rpm-build d2b433
  fill-column:80
rpm-build d2b433
  End:
rpm-build d2b433
*/