diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-06-17 02:39:14 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-06-20 09:36:21 -0700 |
| commit | 8741214bf69d1209a1e6d405ed8561d27f04436a (patch) | |
| tree | 85325eb4b2d2c1c15eb8bd58426dac5462242d4e /toolsrc/include/vcpkg_Parse.h | |
| parent | 8c4d55b8f304c74aeb95878cfe354830ff4abc88 (diff) | |
| download | vcpkg-8741214bf69d1209a1e6d405ed8561d27f04436a.tar.gz vcpkg-8741214bf69d1209a1e6d405ed8561d27f04436a.zip | |
[vcpkg] Use unique_ptr<> for paragraphs. Post-parser phase rework.
Diffstat (limited to 'toolsrc/include/vcpkg_Parse.h')
| -rw-r--r-- | toolsrc/include/vcpkg_Parse.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg_Parse.h b/toolsrc/include/vcpkg_Parse.h new file mode 100644 index 000000000..a2eb152dc --- /dev/null +++ b/toolsrc/include/vcpkg_Parse.h @@ -0,0 +1,36 @@ +#pragma once + +#include <memory> +#include <unordered_map> + +#include "vcpkg_expected.h" +#include "vcpkg_optional.h" + +namespace vcpkg::Parse +{ + struct ParseControlErrorInfo + { + std::string name; + std::vector<std::string> missing_fields; + std::vector<std::string> extra_fields; + std::error_code error; + }; + + template<class P> + using ParseExpected = ExpectedT<std::unique_ptr<P>, std::unique_ptr<ParseControlErrorInfo>>; + + using RawParagraph = std::unordered_map<std::string, std::string>; + + struct ParagraphParser + { + ParagraphParser(RawParagraph&& fields) : fields(std::move(fields)) {} + + void required_field(const std::string& fieldname, std::string& out); + std::string optional_field(const std::string& fieldname); + std::unique_ptr<ParseControlErrorInfo> error_info(const std::string& name) const; + + private: + RawParagraph&& fields; + std::vector<std::string> missing_fields; + }; +} |
