1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #ifndef cmProcessTools_h
13 #define cmProcessTools_h
15 #include "cmStandardIncludes.h"
17 /** \class cmProcessTools
18 * \brief Helper classes for process output parsing
24 /** Abstract interface for process output parsers. */
28 /** Process the given output data from a tool. Processing may be
29 done incrementally. Returns true if the parser is interested
30 in any more data and false if it is done. */
31 bool Process(const char* data, int length)
32 { return this->ProcessChunk(data, length); }
33 bool Process(const char* data)
34 { return this->Process(data, static_cast<int>(strlen(data))); }
36 virtual ~OutputParser() {}
38 /** Implement in a subclass to process a chunk of data. It should
39 return true only if it is interested in more data. */
40 virtual bool ProcessChunk(const char* data, int length) = 0;
43 /** Process output parser that extracts one line at a time. */
44 class LineParser: public OutputParser
47 /** Construct with line separation character and choose whether to
48 ignore carriage returns. */
49 LineParser(char sep = '\n', bool ignoreCR = true);
51 /** Configure logging of lines as they are extracted. */
52 void SetLog(std::ostream* log, const char* prefix);
60 virtual bool ProcessChunk(const char* data, int length);
62 /** Implement in a subclass to process one line of input. It
63 should return true only if it is interested in more data. */
64 virtual bool ProcessLine() = 0;
67 /** Trivial line handler for simple logging. */
68 class OutputLogger: public LineParser
71 OutputLogger(std::ostream& log, const char* prefix = 0)
72 { this->SetLog(&log, prefix); }
74 virtual bool ProcessLine() { return true; }
77 /** Run a process and send output to given parsers. */
78 static void RunProcess(struct cmsysProcess_s* cp,
79 OutputParser* out, OutputParser* err = 0);