1 /** \file BufferedLogCallback.hxx
2 * Buffer certain log messages permanently for later retrieval and display
5 // Copyright (C) 2013 James Turner zakalawe@mac.com
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.
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.
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.
23 #ifndef SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
24 #define SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
27 #include <memory> // for std::auto_ptr
29 #include <simgear/debug/logstream.hxx>
34 class BufferedLogCallback : public LogCallback
37 BufferedLogCallback(sgDebugClass c, sgDebugPriority p);
38 virtual ~BufferedLogCallback();
40 virtual void operator()(sgDebugClass c, sgDebugPriority p,
41 const char* file, int line, const std::string& aMessage);
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.
50 typedef std::vector<unsigned char*> vector_cstring;
53 * copy the buffered log data into the provided output list
54 * (which will be cleared first). This method is safe to call from
57 void threadsafeCopy(vector_cstring& aOutput);
59 class BufferedLogCallbackPrivate;
60 std::auto_ptr<BufferedLogCallbackPrivate> d;
64 } // of namespace simgear
66 #endif // of SG_DEBUG_BUFFEREDLOGCALLBACK_HXX