You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2018/11/13 00:26:21 UTC
[mesos] 01/03: Added some new generic flag parsers.
This is an automated email from the ASF dual-hosted git repository.
benh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 975136403457f94b5890271f9d8b3f1bcf75a416
Author: Benjamin Hindman <be...@gmail.com>
AuthorDate: Sun Jul 15 09:54:30 2018 -0700
Added some new generic flag parsers.
Review: https://reviews.apache.org/r/67955
---
3rdparty/stout/include/stout/flags/parse.hpp | 47 ++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/3rdparty/stout/include/stout/flags/parse.hpp b/3rdparty/stout/include/stout/flags/parse.hpp
index 4566b79..f69c81a 100644
--- a/3rdparty/stout/include/stout/flags/parse.hpp
+++ b/3rdparty/stout/include/stout/flags/parse.hpp
@@ -218,6 +218,53 @@ inline Try<int_fd> parse(const std::string& value)
}
#endif // __WINDOWS__
+
+// TODO(klueska): Generalize this parser to take any comma separated
+// list and convert it to its appropriate type (i.e., not just for
+// unsigned ints). Issues could arise when the generic type is a
+// string that contains commas though, so generalizing this is not as
+// straightforward as it looks at first glance.
+template <>
+inline Try<std::vector<unsigned int>> parse(const std::string& value)
+{
+ std::vector<unsigned int> result;
+
+ foreach (const std::string& token, strings::tokenize(value, ",")) {
+ Try<unsigned int> number = numify<unsigned int>(token);
+
+ if (number.isError()) {
+ return Error("Failed to numify '" + token + "': " + number.error());
+ }
+
+ result.push_back(number.get());
+ }
+
+ return result;
+}
+
+
+// NOTE: Strings in the set cannot contain commas, since that
+// is the delimiter and we provide no way to escape it.
+//
+// TODO(klueska): Generalize this parser to take any comma separated
+// list and convert it to its appropriate type (i.e., not just for
+// strings).
+template <>
+inline Try<std::set<std::string>> parse(const std::string& value)
+{
+ std::set<std::string> result;
+
+ foreach (const std::string& token, strings::tokenize(value, ",")) {
+ if (result.count(token) > 0) {
+ return Error("Duplicate token '" + token + "'");
+ }
+
+ result.insert(token);
+ }
+
+ return result;
+}
+
} // namespace flags {
#endif // __STOUT_FLAGS_PARSE_HPP__