MCPcopy Create free account
hub / github.com/apache/mesos / foreach

Function foreach

src/common/resource_quantities.cpp:44–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 ResourceQuantities result;
43
44 foreach (const string& token, strings::tokenize(text, ";")) {
45 vector<string> pair = strings::tokenize(token, ":");
46 if (pair.size() != 2) {
47 return Error("Failed to parse '" + token + "': missing or extra ':'");
48 }
49
50 Try<Value> value = internal::values::parse(pair[1]);
51 if (value.isError()) {
52 return Error(
53 "Failed to parse '" + pair[1] + "' to quantity: " + value.error());
54 }
55
56 if (value->type() != Value::SCALAR) {
57 return Error(
58 "Failed to parse '" + pair[1] + "' to quantity:"
59 " only scalar values are allowed");
60 }
61
62 if (value->scalar().value() < 0) {
63 return Error(
64 "Failed to parse '" + pair[1] + "' to quantity:"
65 " negative values are not allowed");
66 } else if (value->scalar().value() > 0) {
67 result.add(strings::trim(pair[0]), value->scalar());
68 }
69 // Zero value is silently dropped.
70 }
71
72 return result;
73}

Callers

nothing calls this directly

Calls 15

tokenizeFunction · 0.85
trimFunction · 0.85
NoneClass · 0.85
typeMethod · 0.80
parseFunction · 0.70
errorMethod · 0.65
ErrorFunction · 0.50
addFunction · 0.50
setFunction · 0.50
sizeMethod · 0.45
isErrorMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected