12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #ifndef cmProcessTools_h
- #define cmProcessTools_h
- #include "cmConfigure.h"
- #include "cmProcessOutput.h"
- #include <iosfwd>
- #include <string.h>
- #include <string>
- class cmProcessTools
- {
- public:
- typedef cmProcessOutput::Encoding Encoding;
-
- class OutputParser
- {
- public:
-
- bool Process(const char* data, int length)
- {
- return this->ProcessChunk(data, length);
- }
- bool Process(const char* data)
- {
- return this->Process(data, static_cast<int>(strlen(data)));
- }
- virtual ~OutputParser() {}
- protected:
-
- virtual bool ProcessChunk(const char* data, int length) = 0;
- };
-
- class LineParser : public OutputParser
- {
- public:
-
- LineParser(char sep = '\n', bool ignoreCR = true);
-
- void SetLog(std::ostream* log, const char* prefix);
- protected:
- std::ostream* Log;
- const char* Prefix;
- std::string Line;
- char Separator;
- char LineEnd;
- bool IgnoreCR;
- bool ProcessChunk(const char* data, int length) override;
-
- virtual bool ProcessLine() = 0;
- };
-
- class OutputLogger : public LineParser
- {
- public:
- OutputLogger(std::ostream& log, const char* prefix = nullptr)
- {
- this->SetLog(&log, prefix);
- }
- private:
- bool ProcessLine() override { return true; }
- };
-
- static void RunProcess(struct cmsysProcess_s* cp, OutputParser* out,
- OutputParser* err = nullptr,
- Encoding encoding = cmProcessOutput::Auto);
- };
- #endif
|