]> git.mxchange.org Git - simgear.git/blob - simgear/debug/BufferedLogCallback.hxx
21359fd96511854c442191e1cac3d0abcbc23219
[simgear.git] / simgear / debug / BufferedLogCallback.hxx
1 /** \file BufferedLogCallback.hxx
2  * Buffer certain log messages permanently for later retrieval and display
3  */
4
5 // Copyright (C) 2013  James Turner  zakalawe@mac.com
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21      
22      
23 #ifndef SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
24 #define SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
25
26 #include <vector>
27 #include <memory> // for std::auto_ptr
28
29 #include <simgear/debug/logstream.hxx>
30
31 namespace simgear
32 {
33
34 class BufferedLogCallback : public LogCallback
35 {
36 public:
37     BufferedLogCallback(sgDebugClass c, sgDebugPriority p);
38     virtual ~BufferedLogCallback();
39     
40     virtual void operator()(sgDebugClass c, sgDebugPriority p, 
41         const char* file, int line, const std::string& aMessage);
42     
43     /**
44     * copying a (large) vector of std::string would be very expensive.
45     * once logged, this call retains storage of the underlying string data,
46     * so when copying, it's sufficient to pass around the strings as raw
47     * char arrays. This means we're only copying a vector of pointers,
48     * which is very efficient.
49     */
50     typedef std::vector<unsigned char*> vector_cstring;
51      
52     /**
53      * copy the buffered log data into the provided output list
54      * (which will be cleared first). This method is safe to call from
55      * any thread.
56      */
57     void threadsafeCopy(vector_cstring& aOutput);
58 private:
59     class BufferedLogCallbackPrivate;
60     std::auto_ptr<BufferedLogCallbackPrivate> d;
61 };
62      
63
64 } // of namespace simgear
65
66 #endif // of SG_DEBUG_BUFFEREDLOGCALLBACK_HXX