summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index c2b24944d..cc201a0af 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -615,6 +615,12 @@ Rectangle::intersection (Rectangle const & other) const
);
}
+/** Round a number up to the nearest multiple of another number.
+ * @param a Number to round.
+ * @param t Multiple to round to.
+ * @return Rounded number.
+ */
+
int
round_up (int a, int t)
{
@@ -622,6 +628,13 @@ round_up (int a, int t)
return a - (a % t);
}
+/** Read a sequence of key / value pairs from a text stream;
+ * the keys are the first words on the line, and the values are
+ * the remainder of the line following the key. Lines beginning
+ * with # are ignored.
+ * @param s Stream to read.
+ * @return key/value pairs.
+ */
multimap<string, string>
read_key_value (istream &s)
{
@@ -675,6 +688,13 @@ get_required_int (multimap<string, string> const & kv, string k)
return lexical_cast<int> (v);
}
+float
+get_required_float (multimap<string, string> const & kv, string k)
+{
+ string const v = get_required_string (kv, k);
+ return lexical_cast<float> (v);
+}
+
string
get_optional_string (multimap<string, string> const & kv, string k)
{