[cig-commits] r4504 - in cs/pythia/trunk/journal: . diagnostics

leif at geodynamics.org leif at geodynamics.org
Fri Sep 8 17:10:13 PDT 2006


Author: leif
Date: 2006-09-08 17:10:13 -0700 (Fri, 08 Sep 2006)
New Revision: 4504

Removed:
   cs/pythia/trunk/journal/Index.h
   cs/pythia/trunk/journal/manip-explicit.h
   cs/pythia/trunk/journal/manip-templated.h
Modified:
   cs/pythia/trunk/journal/Diagnostic.h
   cs/pythia/trunk/journal/SeverityDebug.h
   cs/pythia/trunk/journal/SeverityError.h
   cs/pythia/trunk/journal/SeverityFirewall.h
   cs/pythia/trunk/journal/SeverityInfo.h
   cs/pythia/trunk/journal/SeverityWarning.h
   cs/pythia/trunk/journal/__init__.py
   cs/pythia/trunk/journal/diagnostics/Debug.py
   cs/pythia/trunk/journal/diagnostics/Diagnostic.py
   cs/pythia/trunk/journal/diagnostics/Error.py
   cs/pythia/trunk/journal/diagnostics/Firewall.py
   cs/pythia/trunk/journal/diagnostics/Info.py
   cs/pythia/trunk/journal/diagnostics/Warning.py
   cs/pythia/trunk/journal/manipulators.h
Log:
Created an inline C++ journal interface which uses the Python version
of journal for its implementation.  It functions in a similar manner
to the _journal module's ProxyDevice in the standard version of Pythia,
except that it interfaces with the Python journal at the 'Diagnostic'
level instead of the 'Device' level.

This means the Pythia egg will have a fully functional journal,
without any native code modules or libraries whatsoever (no
_journalmodule.so or libjournal.so).


Modified: cs/pythia/trunk/journal/Diagnostic.h
===================================================================
--- cs/pythia/trunk/journal/Diagnostic.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/Diagnostic.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -15,11 +15,11 @@
 #define journal_Diagnostic_h
 
 
+#include <Python.h>
+
+
 // forward declarations
 namespace journal {
-    class Entry;
-    class Facility;
-    class Journal;
     class Diagnostic;
 }
 
@@ -28,18 +28,25 @@
 
 // types
 public:
-    typedef Entry entry_t;
-    typedef bool state_t;
-    typedef Journal journal_t;
-
     typedef std::string string_t;
     typedef std::stringstream buffer_t;
 
 // interface
 public:
-    void state(bool flag) { _state = flag; }
-    bool state() const { return _state; }
-    static state_t & lookup(string_t name) { static state_t dummy; return dummy; }
+    void state(bool flag) {
+        PyObject *ret = PyObject_CallMethod(_self, (char *)(flag ? "activate" : "deactivate"), 0);
+        if (ret) { Py_DECREF(ret); } else { _error(); }
+    }
+    bool state() const {
+        PyObject *state = PyObject_GetAttrString(_self, "state"); if (!state) { _error(); }
+        bool ret = false;
+        switch (PyObject_IsTrue(state)) {
+        case 1: ret = true; break;
+        case -1: _error(); break;
+        }
+        Py_DECREF(state);
+        return ret;
+    }
     
     void activate() { state(true); }
     void deactivate() { state(false); }
@@ -47,18 +54,31 @@
     string_t facility() const { return _facility; }
 
     // entry manipulation
-    void record() { /**/ }
-    void newline() { if (state()) _newline(); }
+    void record() {
+        newline();
+        PyObject *ret = PyObject_CallMethod(_self, "record", 0);
+        if (ret) { Py_DECREF(ret); } else { _error(); }
+    }
+    void newline() {
+        string_t message = str();
+        PyObject *ret = PyObject_CallMethod(_self, "line", "s#", message.c_str(), message.size());
+        if (ret) { Py_DECREF(ret); } else { _error(); }
+        _buffer.str(string_t());
+    }
     void attribute(string_t key, string_t value) {
-        /*(*_entry)[key] = value;*/
+        PyObject *ret = PyObject_CallMethod(_self, "attribute", "s#s#",
+                                            key.c_str(), key.size(),
+                                            value.c_str(), value.size());
+        if (ret) { Py_DECREF(ret); } else { _error(); }
     }
+    void attribute(string_t key, long value) {
+        PyObject *ret = PyObject_CallMethod(_self, "attribute", "s#l", key.c_str(), key.size(), value);
+        if (ret) { Py_DECREF(ret); } else { _error(); }
+    }
 
     // access to the buffered data
     string_t str() const { return _buffer.str(); }
 
-    // access to the journal singleton
-    static journal_t & journal();
-
     // builtin data type injection
     template <typename item_t> 
     Diagnostic & inject(item_t item) {
@@ -66,18 +86,39 @@
         return *this;
     }
 
+private:
+    static PyObject *_journal() {
+        static PyObject *journal;
+        if (!journal) {
+            journal = PyImport_ImportModule("journal");
+            if (!journal) {
+                PyErr_Print();
+                Py_FatalError("could not import journal module");
+            }
+        }
+        return journal;
+    }
+    static PyObject *_getDiagnostic(string_t facility, string_t severity) {
+        PyObject *factory = PyObject_GetAttrString(_journal(), (char *)severity.c_str()); if (!factory) { _error(); }
+        PyObject *diag = PyObject_CallFunction(factory, "s#", facility.c_str(), facility.size()); if (!diag) { _error(); }
+        Py_DECREF(factory);
+        return diag;
+    }
+    static void _error() {
+        PyErr_Print();
+        Py_Exit(1);
+    }
+    
 // meta-methods
 public:
-    ~Diagnostic() { /*delete _entry;*/ }
-    Diagnostic(string_t facility, string_t severity, state_t & state):
+    ~Diagnostic() { Py_DECREF(_self); }
+    Diagnostic(string_t facility, string_t severity):
         _facility(facility), _severity(severity),
-        _state(state), _buffer(), _entry(0 /*new entry_t*/) {}
-
-// implementation
-private:
-    void _newline() {
-        /*_entry->newline(str());*/
-        _buffer.str(string_t());
+        _buffer(),
+        _self(_getDiagnostic(facility, severity)) {
+        if (PyErr_Occurred()) {
+            _error();
+        }
     }
 
 // disable these
@@ -90,9 +131,9 @@
     const string_t _facility;
     const string_t _severity;
 
-    state_t & _state;
     buffer_t _buffer;
-    entry_t * _entry;
+
+    PyObject *_self;
 };
 
 

Deleted: cs/pythia/trunk/journal/Index.h
===================================================================
--- cs/pythia/trunk/journal/Index.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/Index.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -1,52 +0,0 @@
-// -*- C++ -*-
-//
-// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-//
-//                             Michael A.G. Aivazis
-//                      California Institute of Technology
-//                      (C) 1998-2005  All Rights Reserved
-//
-// <LicenseText>
-//
-// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-//
-
-#if !defined(journal_Index_h)
-#define journal_Index_h
-
-
-// forward declarations
-namespace journal {
-    class Index;
-    class Diagnostic;
-}
-
-
-class journal::Index {
-
-// types
-public:
-    typedef std::string string_t;
-    typedef Diagnostic::state_t state_t;
-
-// interface
-public:
-    virtual state_t & lookup(string_t name) = 0;
-
-// meta-methods
-public:
-    virtual ~Index();
-    Index() {}
-
-// disable these
-private:
-    Index(const Index &);
-    const Index & operator=(const Index &);
-};
-
-
-#endif
-// version
-// $Id: Index.h,v 1.1.1.1 2005/03/08 16:13:55 aivazis Exp $
-
-// End of file 

Modified: cs/pythia/trunk/journal/SeverityDebug.h
===================================================================
--- cs/pythia/trunk/journal/SeverityDebug.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/SeverityDebug.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -33,7 +33,7 @@
     ~SeverityDebug() {}
     
     SeverityDebug(string_t name) :
-        Diagnostic(name, "debug", lookup(name)) {}
+        Diagnostic(name, "debug") {}
 
 // disable these
 private:

Modified: cs/pythia/trunk/journal/SeverityError.h
===================================================================
--- cs/pythia/trunk/journal/SeverityError.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/SeverityError.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -33,7 +33,7 @@
     ~SeverityError() {}
     
     SeverityError(string_t name) :
-        Diagnostic(name, "error", lookup(name)) {}
+        Diagnostic(name, "error") {}
 
 // disable these
 private:

Modified: cs/pythia/trunk/journal/SeverityFirewall.h
===================================================================
--- cs/pythia/trunk/journal/SeverityFirewall.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/SeverityFirewall.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -33,7 +33,7 @@
     ~SeverityFirewall() {}
     
     SeverityFirewall(string_t name) :
-        Diagnostic(name, "firewall", lookup(name)) {}
+        Diagnostic(name, "firewall") {}
 
 // disable these
 private:

Modified: cs/pythia/trunk/journal/SeverityInfo.h
===================================================================
--- cs/pythia/trunk/journal/SeverityInfo.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/SeverityInfo.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -33,7 +33,7 @@
     ~SeverityInfo() {}
     
     SeverityInfo(string_t name) :
-        Diagnostic(name, "info", lookup(name)) {}
+        Diagnostic(name, "info") {}
 
 // disable these
 private:

Modified: cs/pythia/trunk/journal/SeverityWarning.h
===================================================================
--- cs/pythia/trunk/journal/SeverityWarning.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/SeverityWarning.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -33,7 +33,7 @@
     ~SeverityWarning() {}
     
     SeverityWarning(string_t name) :
-        Diagnostic(name, "warning", lookup(name)) {}
+        Diagnostic(name, "warning") {}
 
 // disable these
 private:

Modified: cs/pythia/trunk/journal/__init__.py
===================================================================
--- cs/pythia/trunk/journal/__init__.py	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/__init__.py	2006-09-09 00:10:13 UTC (rev 4504)
@@ -156,18 +156,6 @@
 # statics
 _theJournal = None
 
-# initialize
-try:
-    #print " ** __init__.py: importing _journal"
-    import _journal
-except ImportError:
-    hasProxy = False
-else:
-    #print " ** __init__.py: initializing C++ bindings"
-
-    _journal.initialize(journal())
-    hasProxy = True
-
 # register the known indices
 register()
         

Modified: cs/pythia/trunk/journal/diagnostics/Debug.py
===================================================================
--- cs/pythia/trunk/journal/diagnostics/Debug.py	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/diagnostics/Debug.py	2006-09-09 00:10:13 UTC (rev 4504)
@@ -21,8 +21,6 @@
 
     def init(self):
         Index.init(self, "debug", False)
-        if journal.hasProxy:
-            self._stateFactory = self._proxyState
         return
 
 

Modified: cs/pythia/trunk/journal/diagnostics/Diagnostic.py
===================================================================
--- cs/pythia/trunk/journal/diagnostics/Diagnostic.py	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/diagnostics/Diagnostic.py	2006-09-09 00:10:13 UTC (rev 4504)
@@ -104,7 +104,33 @@
         def __str__(self):
             return self.msg
 
+    
+    # C++ interface
 
+    def attribute(self, key, value):
+        meta = self._entry.meta
+        meta[key] = value
+
+
+    def record(self):
+        if not self.state:
+            return
+
+        meta = self._entry.meta
+        meta["facility"] = self.facility
+        meta["severity"] = self.severity
+        if not meta.has_key("function"):
+            meta["function"] = "<unknown>"
+
+        journal.journal().record(self._entry)
+
+        if self.fatal:
+            raise self.Fatal()
+     
+        self._entry = Entry()
+        return self
+
+
 # version
 __id__ = "$Id: Diagnostic.py,v 1.1.1.1 2005/03/08 16:13:53 aivazis Exp $"
 

Modified: cs/pythia/trunk/journal/diagnostics/Error.py
===================================================================
--- cs/pythia/trunk/journal/diagnostics/Error.py	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/diagnostics/Error.py	2006-09-09 00:10:13 UTC (rev 4504)
@@ -21,8 +21,6 @@
 
     def init(self):
         Index.init(self, "error", True)
-        if journal.hasProxy:
-            self._stateFactory = self._proxyState
         return
 
 

Modified: cs/pythia/trunk/journal/diagnostics/Firewall.py
===================================================================
--- cs/pythia/trunk/journal/diagnostics/Firewall.py	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/diagnostics/Firewall.py	2006-09-09 00:10:13 UTC (rev 4504)
@@ -21,8 +21,6 @@
 
     def init(self):
         Index.init(self, "firewall", defaultState=True, fatal=True)
-        if journal.hasProxy:
-            self._stateFactory = self._proxyState
         return
 
 

Modified: cs/pythia/trunk/journal/diagnostics/Info.py
===================================================================
--- cs/pythia/trunk/journal/diagnostics/Info.py	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/diagnostics/Info.py	2006-09-09 00:10:13 UTC (rev 4504)
@@ -20,8 +20,6 @@
 
     def init(self):
         Index.init(self, "info", False)
-        if journal.hasProxy:
-            self._stateFactory = self._proxyState
         return
 
 

Modified: cs/pythia/trunk/journal/diagnostics/Warning.py
===================================================================
--- cs/pythia/trunk/journal/diagnostics/Warning.py	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/diagnostics/Warning.py	2006-09-09 00:10:13 UTC (rev 4504)
@@ -21,8 +21,6 @@
 
     def init(self):
         Index.init(self, "warning", True)
-        if journal.hasProxy:
-            self._stateFactory = self._proxyState
         return
 
 

Deleted: cs/pythia/trunk/journal/manip-explicit.h
===================================================================
--- cs/pythia/trunk/journal/manip-explicit.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/manip-explicit.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -1,105 +0,0 @@
-// -*- C++ -*-
-//
-//--------------------------------------------------------------------------------
-//
-//                              Michael A.G. Aivazis
-//                       California Institute of Technology
-//                       (C) 1998-2005  All Rights Reserved
-//
-// <LicenseText>
-//
-//--------------------------------------------------------------------------------
-//
-
-#if !defined(journal_manip_explicit_h)
-#define journal_manip_explicit_h
-
-namespace journal {
-
-    // declarations of the builtin manipulators
-    class set_t;
-    class loc2_t;
-    class loc3_t;
-}
-
-
-class journal::set_t {
-// types
-public:
-    typedef Diagnostic & (*factory_t)(Diagnostic &, const char *, const char *);
-
-// meta-methods
-public:
-    set_t(factory_t f, const char * key, const char * value) :
-        _f(f), _key(key), _value(value) {}
-
-// data
-public:
-    factory_t _f;
-    const char * _key;
-    const char * _value;
-};
-
-
-class journal::loc2_t {
-
-// types
-public:
-    typedef Diagnostic & (*factory_t)(Diagnostic &, const char *, long);
-
-// meta-methods
-public:
-    loc2_t(factory_t f, const char * file, long line) :
-        _f(f), _file(file), _line(line) {}
-
-// data
-public:
-    factory_t _f;
-    const char * _file;
-    long _line;
-};
-
-
-class journal::loc3_t {
-// types
-public:
-    typedef Diagnostic & (*factory_t)(Diagnostic &, const char *, long, const char *);
-
-// meta-methods
-public:
-    loc3_t(factory_t f, const char * file, long line, const char * function) :
-        _f(f), _file(file), _line(line), _function(function) {}
-
-// data
-public:
-    factory_t _f;
-    const char * _file;
-    long _line;
-    const char * _function;
-};
-
-
-// the injection operators: leave these in the global namespace
-
-inline journal::Diagnostic & operator<< (journal::Diagnostic & s, journal::set_t m)
-{
-    return (*m._f)(s, m._key, m._value);
-}
-
-inline journal::Diagnostic & operator<< (journal::Diagnostic & s, journal::loc2_t m)
-{
-    return (*m._f)(s, m._file, m._line);
-}
-
-inline journal::Diagnostic & operator<< (journal::Diagnostic & s, journal::loc3_t m)
-{
-    return (*m._f)(s, m._file, m._line, m._function);
-}
-
-
-#endif
-
-// version
-// $Id: manip-explicit.h,v 1.1.1.1 2005/03/08 16:13:55 aivazis Exp $
-
-// End of file

Deleted: cs/pythia/trunk/journal/manip-templated.h
===================================================================
--- cs/pythia/trunk/journal/manip-templated.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/manip-templated.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -1,153 +0,0 @@
-// -*- C++ -*-
-//
-//--------------------------------------------------------------------------------
-//
-//                              Michael A.G. Aivazis
-//                       California Institute of Technology
-//                       (C) 1998-2005  All Rights Reserved
-//
-// <LicenseText>
-//
-//--------------------------------------------------------------------------------
-//
-
-#if !defined(journal_manip_templated_h)
-#define journal_manip_templated_h
-
-namespace journal {
-
-    // manipulators with one argument
-    template <typename arg1_t> class manip_1;
-
-    // manipulators with two arguments
-    template <typename arg1_t, typename arg2_t> class manip_2;
-
-    // manipulators with three arguments
-    template <typename arg1_t, typename arg2_t, typename arg3_t> class manip_3;
-
-    // typedefs of the builtin manipulators
-    typedef manip_2<const char *, long> loc2_t;
-    typedef manip_2<const char *, const char *> set_t;
-    typedef manip_3<const char *, long, const char *> loc3_t;
-}
-
-// the injection operators: leave these in the global namespace
-
-template <typename arg1_t>
-inline journal::Diagnostic & operator << (
-    journal::Diagnostic &, journal::manip_1<arg1_t>);
-
-template <typename arg1_t, typename arg2_t>
-inline journal::Diagnostic & operator << (
-    journal::Diagnostic &, journal::manip_2<arg1_t, arg2_t>);
-
-template <typename arg1_t, typename arg2_t, typename arg3_t>
-inline journal::Diagnostic & operator << (
-    journal::Diagnostic &, journal::manip_3<arg1_t, arg2_t, arg3_t>);
-
-
-template <typename arg1_t>
-class journal::manip_1 {
-
-    friend journal::Diagnostic &
-    ::operator<< <> (journal::Diagnostic &, journal::manip_1<arg1_t>);
-
-// types
-public:
-    typedef Diagnostic & (*factory_t)(Diagnostic &, arg1_t);
-
-// meta-methods
-public:
-
-    manip_1(factory_t f, arg1_t arg1) :
-        _f(f), _arg1(arg1) {}
-
-// data
-private:
-
-    factory_t _f;
-    arg1_t _arg1;
-};
-
-
-template <typename arg1_t>
-inline journal::Diagnostic & operator<< (
-    journal::Diagnostic & s, journal::manip_1<arg1_t> m)
-{
-    return (*m._f)(s, m._arg1);
-}
-
-
-template <typename arg1_t, typename arg2_t>
-class journal::manip_2 {
-
-    friend journal::Diagnostic & 
-    ::operator<< <> (journal::Diagnostic &, journal::manip_2<arg1_t, arg2_t>);
-
-// types
-public:
-    typedef Diagnostic & (*factory_t)(Diagnostic &, arg1_t, arg2_t);
-
-// meta-methods
-public:
-
-    manip_2(factory_t f, arg1_t arg1, arg2_t arg2) :
-        _f(f), _arg1(arg1), _arg2(arg2) {}
-
-// data
-private:
-
-    factory_t _f;
-    arg1_t _arg1;
-    arg2_t _arg2;
-};
-
-
-template <typename arg1_t, typename arg2_t>
-inline journal::Diagnostic & 
-operator<< (
-    journal::Diagnostic & s, journal::manip_2<arg1_t, arg2_t> m) 
-{
-    return (*m._f)(s, m._arg1, m._arg2);
-}
-
-
-template <typename arg1_t, typename arg2_t, typename arg3_t>
-class journal::manip_3 {
-
-    friend journal::Diagnostic & 
-    ::operator<< <> (journal::Diagnostic &, journal::manip_3<arg1_t, arg2_t, arg3_t>);
-
-// types
-public:
-    typedef Diagnostic & (*factory_t)(Diagnostic &, arg1_t, arg2_t, arg3_t);
-
-// meta-methods
-public:
-
-    manip_3(factory_t f, arg1_t arg1, arg2_t arg2, arg3_t arg3) :
-        _f(f), _arg1(arg1), _arg2(arg2), _arg3(arg3) {}
-
-// data
-private:
-
-    factory_t _f;
-    arg1_t _arg1;
-    arg2_t _arg2;
-    arg3_t _arg3;
-};
-
-
-template <typename arg1_t, typename arg2_t, typename arg3_t>
-inline journal::Diagnostic & operator<< 
-(journal::Diagnostic & s, journal::manip_3<arg1_t, arg2_t, arg3_t> m) {
-    return (*m._f)(s, m._arg1, m._arg2, m._arg3);
-}
-
-
-#endif
-
-// version
-// $Id: manip-templated.h,v 1.1.1.1 2005/03/08 16:13:55 aivazis Exp $
-
-// End of file

Modified: cs/pythia/trunk/journal/manipulators.h
===================================================================
--- cs/pythia/trunk/journal/manipulators.h	2006-09-08 21:40:31 UTC (rev 4503)
+++ cs/pythia/trunk/journal/manipulators.h	2006-09-09 00:10:13 UTC (rev 4504)
@@ -14,13 +14,90 @@
 #if !defined(journal_manipulators_h)
 #define journal_manipulators_h
 
-// get infrastructure manipulator definitions/declaration
-#if defined(JOURNAL_NON_TEMPLATED_MANIPULATORS)
-#include "manip-explicit.h"
-#else
-#include "manip-templated.h"
-#endif
 
+namespace journal {
+
+    // declarations of the builtin manipulators
+    class set_t;
+    class loc2_t;
+    class loc3_t;
+}
+
+
+class journal::set_t {
+// types
+public:
+    typedef Diagnostic & (*factory_t)(Diagnostic &, const char *, const char *);
+
+// meta-methods
+public:
+    set_t(factory_t f, const char * key, const char * value) :
+        _f(f), _key(key), _value(value) {}
+
+// data
+public:
+    factory_t _f;
+    const char * _key;
+    const char * _value;
+};
+
+
+class journal::loc2_t {
+
+// types
+public:
+    typedef Diagnostic & (*factory_t)(Diagnostic &, const char *, long);
+
+// meta-methods
+public:
+    loc2_t(factory_t f, const char * file, long line) :
+        _f(f), _file(file), _line(line) {}
+
+// data
+public:
+    factory_t _f;
+    const char * _file;
+    long _line;
+};
+
+
+class journal::loc3_t {
+// types
+public:
+    typedef Diagnostic & (*factory_t)(Diagnostic &, const char *, long, const char *);
+
+// meta-methods
+public:
+    loc3_t(factory_t f, const char * file, long line, const char * function) :
+        _f(f), _file(file), _line(line), _function(function) {}
+
+// data
+public:
+    factory_t _f;
+    const char * _file;
+    long _line;
+    const char * _function;
+};
+
+
+// the injection operators: leave these in the global namespace
+
+inline journal::Diagnostic & operator<< (journal::Diagnostic & s, journal::set_t m)
+{
+    return (*m._f)(s, m._key, m._value);
+}
+
+inline journal::Diagnostic & operator<< (journal::Diagnostic & s, journal::loc2_t m)
+{
+    return (*m._f)(s, m._file, m._line);
+}
+
+inline journal::Diagnostic & operator<< (journal::Diagnostic & s, journal::loc3_t m)
+{
+    return (*m._f)(s, m._file, m._line, m._function);
+}
+
+
 // forward declarations
 namespace journal {
     class Diagnostic;
@@ -50,12 +127,7 @@
     // location information
     inline Diagnostic & __diagmanip_loc(Diagnostic & s, const char * filename, long line) {
         s.attribute("filename", filename);
-
-        std::stringstream tmp;
-        tmp << line;
-
-        s.attribute("line", tmp.str());
-
+        s.attribute("line", line);
         return s;
     }
 
@@ -68,12 +140,7 @@
     {
         s.attribute("filename", filename);
         s.attribute("function", function);
-
-        std::stringstream tmp;
-        tmp << line;
-
-        s.attribute("line", tmp.str());
-
+        s.attribute("line", line);
         return s;
     }
 



More information about the cig-commits mailing list