[Supertux-Commit] [tinygettext commit] r132 - branches/tinygettext-portable/src

codesite-noreply at google.com codesite-noreply at google.com
Sun Feb 1 05:28:09 PST 2009


Author: grumbel
Date: Sun Feb  1 04:29:30 2009
New Revision: 132

Modified:
    branches/tinygettext-portable/src/log.cpp
    branches/tinygettext-portable/src/log.hpp

Log:
Added log_error, some more flexibility in log callback handling

Modified: branches/tinygettext-portable/src/log.cpp
==============================================================================
--- branches/tinygettext-portable/src/log.cpp	(original)
+++ branches/tinygettext-portable/src/log.cpp	Sun Feb  1 04:29:30 2009
@@ -21,14 +21,51 @@
  #include "log.hpp"

  namespace tinygettext {
-
-void default_log_callback(const std::string& str)
+
+Log::log_callback_t Log::log_info_callback    = &Log::default_log_callback;
+Log::log_callback_t Log::log_warning_callback = &Log::default_log_callback;
+Log::log_callback_t Log::log_error_callback   = &Log::default_log_callback;
+
+void
+Log::default_log_callback(const std::string& str)
  {
    std::cerr << str;
  }

-void (*log_callback)(const std::string&) = &default_log_callback;
+void
+Log::set_log_info_callback(log_callback_t callback)
+{
+  log_info_callback = callback;
+}
+
+void
+Log::set_log_warning_callback(log_callback_t callback)
+{
+  log_warning_callback = callback;
+}
+
+void
+Log::set_log_error_callback(log_callback_t callback)
+{
+  log_error_callback = callback;
+}
+
+Log::Log(log_callback_t callback_)
+  : callback(callback_)
+{
+}
+
+Log::~Log()
+{
+  callback(out.str());
+}

+std::ostream&
+Log::get()
+{
+  return out;
+}
+
  } // namespace tinygettext

  /* EOF */

Modified: branches/tinygettext-portable/src/log.hpp
==============================================================================
--- branches/tinygettext-portable/src/log.hpp	(original)
+++ branches/tinygettext-portable/src/log.hpp	Sun Feb  1 04:29:30 2009
@@ -24,24 +24,36 @@

  namespace tinygettext {

-extern void (*log_callback)(const std::string&);
-
  class Log
  {
+public:
+  typedef void (*log_callback_t)(const std::string&);
+
+  static log_callback_t log_info_callback;
+  static log_callback_t log_warning_callback;
+  static log_callback_t log_error_callback;
+
+
+  static void default_log_callback(const std::string& str);
+
+  static void set_log_info_callback(log_callback_t callback);
+  static void set_log_warning_callback(log_callback_t callback);
+  static void set_log_error_callback(log_callback_t callback);
+
  private:
+  log_callback_t callback;
    std::ostringstream out;

  public:
-  Log() {}
-  ~Log() {
-    log_callback(out.str());
-  }
+  Log(log_callback_t callback);
+  ~Log();

-  std::ostream& get() { return out; }
+  std::ostream& get();
  };

-#define log_warning if (!log_callback); else Log().get()
-#define log_info    if (!log_callback); else Log().get()
+#define log_error   if (!Log::log_error_callback);   else  
Log(Log::log_error_callback).get()
+#define log_warning if (!Log::log_warning_callback); else  
Log(Log::log_warning_callback).get()
+#define log_info    if (!Log::log_info_callback);    else  
Log(Log::log_warning_callback).get()

  } // namespace tinygettext



More information about the Supertux-Commit mailing list