You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/03/29 20:45:41 UTC
mesos git commit: Added a flag parser for vector to
src/common/parse.hpp.
Repository: mesos
Updated Branches:
refs/heads/master b3516fd39 -> 6cb74dad4
Added a flag parser for vector<unsigned int> to src/common/parse.hpp.
Review: https://reviews.apache.org/r/44777/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6cb74dad
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6cb74dad
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6cb74dad
Branch: refs/heads/master
Commit: 6cb74dad412ca9565a291df18ab7e0bf59c9697e
Parents: b3516fd
Author: Kevin Klues <kl...@gmail.com>
Authored: Tue Mar 29 11:29:48 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Mar 29 11:42:01 2016 -0700
----------------------------------------------------------------------
src/common/parse.hpp | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6cb74dad/src/common/parse.hpp
----------------------------------------------------------------------
diff --git a/src/common/parse.hpp b/src/common/parse.hpp
index 9535fad..9036dae 100644
--- a/src/common/parse.hpp
+++ b/src/common/parse.hpp
@@ -109,6 +109,30 @@ inline Try<hashmap<std::string, std::string>> parse(const std::string& value)
return map;
}
+
+// 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;
+}
+
} // namespace flags {
#endif // __COMMON_PARSE_HPP__