1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmProcessTools.h,v $
6 Date: $Date: 2009-02-24 16:08:38 $
7 Version: $Revision: 1.2 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmProcessTools_h
18 #define cmProcessTools_h
20 #include "cmStandardIncludes.h"
22 /** \class cmProcessTools
23 * \brief Helper classes for process output parsing
29 /** Abstract interface for process output parsers. */
33 /** Process the given output data from a tool. Processing may be
34 done incrementally. Returns true if the parser is interested
35 in any more data and false if it is done. */
36 bool Process(const char* data
, int length
)
37 { return this->ProcessChunk(data
, length
); }
39 virtual ~OutputParser() {}
41 /** Implement in a subclass to process a chunk of data. It should
42 return true only if it is interested in more data. */
43 virtual bool ProcessChunk(const char* data
, int length
) = 0;
46 /** Process output parser that extracts one line at a time. */
47 class LineParser
: public OutputParser
50 /** Construct with line separation character and choose whether to
51 ignore carriage returns. */
52 LineParser(char sep
= '\n', bool ignoreCR
= true);
54 /** Configure logging of lines as they are extracted. */
55 void SetLog(std::ostream
* log
, const char* prefix
);
62 virtual bool ProcessChunk(const char* data
, int length
);
64 /** Implement in a subclass to process one line of input. It
65 should return true only if it is interested in more data. */
66 virtual bool ProcessLine() = 0;
69 /** Trivial line handler for simple logging. */
70 class OutputLogger
: public LineParser
73 OutputLogger(std::ostream
& log
, const char* prefix
= 0)
74 { this->SetLog(&log
, prefix
); }
76 virtual bool ProcessLine() { return true; }
79 /** Run a process and send output to given parsers. */
80 static void RunProcess(struct cmsysProcess_s
* cp
,
81 OutputParser
* out
, OutputParser
* err
= 0);