1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmProcessTools.h,v $
6 Date: $Date: 2009-07-10 15:07:27 $
7 Version: $Revision: 1.3 $
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
); }
38 bool Process(const char* data
)
39 { return this->Process(data
, static_cast<int>(strlen(data
))); }
41 virtual ~OutputParser() {}
43 /** Implement in a subclass to process a chunk of data. It should
44 return true only if it is interested in more data. */
45 virtual bool ProcessChunk(const char* data
, int length
) = 0;
48 /** Process output parser that extracts one line at a time. */
49 class LineParser
: public OutputParser
52 /** Construct with line separation character and choose whether to
53 ignore carriage returns. */
54 LineParser(char sep
= '\n', bool ignoreCR
= true);
56 /** Configure logging of lines as they are extracted. */
57 void SetLog(std::ostream
* log
, const char* prefix
);
64 virtual bool ProcessChunk(const char* data
, int length
);
66 /** Implement in a subclass to process one line of input. It
67 should return true only if it is interested in more data. */
68 virtual bool ProcessLine() = 0;
71 /** Trivial line handler for simple logging. */
72 class OutputLogger
: public LineParser
75 OutputLogger(std::ostream
& log
, const char* prefix
= 0)
76 { this->SetLog(&log
, prefix
); }
78 virtual bool ProcessLine() { return true; }
81 /** Run a process and send output to given parsers. */
82 static void RunProcess(struct cmsysProcess_s
* cp
,
83 OutputParser
* out
, OutputParser
* err
= 0);