aboutsummaryrefslogtreecommitdiffstats
path: root/pulse.h
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-01-02 11:33:59 -0500
committerDave Reisner <dreisner@archlinux.org>2013-01-02 14:23:57 -0500
commite35ce0069094c135ed9065f2bda945fdf4b6d83e (patch)
tree843d860598cbefbe1d3c35ddb4a6d4e320fefed2 /pulse.h
parentaa6847b94511728250333125c3dd9bec7b65759a (diff)
downloadmirror-ponymix-e35ce0069094c135ed9065f2bda945fdf4b6d83e.tar.gz
mirror-ponymix-e35ce0069094c135ed9065f2bda945fdf4b6d83e.tar.bz2
mirror-ponymix-e35ce0069094c135ed9065f2bda945fdf4b6d83e.zip
ponymix: validate arg count before invoking function
A few changes make this fun and easy: - Merge the function array into the string to action lookup and return a Command instead of simply an enum. A Command is the function and the min/max arg count. - Implement an InRange method for the Range class. - Add a Dispatch function to convert the string to Command and validate the arguments. This leaves us in a position where the argc parameter to each method is never used, but maybe some day a command will be added that takes a range of args rather than a fixed number.
Diffstat (limited to 'pulse.h')
-rw-r--r--pulse.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/pulse.h b/pulse.h
index 9a61108..9bb0733 100644
--- a/pulse.h
+++ b/pulse.h
@@ -102,10 +102,18 @@ template<typename T>
struct Range {
Range(T min, T max) : min(min), max(max) {}
- T clamp(T value) {
+ // Clamps a value to the stored range
+ T Clamp(T value) {
return value < min ? min : (value > max ? max : value);
}
+ // Determine if the passed value is within the range. Returns 0
+ // on success, else -1 if lower than the minimum, and 1 if higher
+ // than the maximum.
+ int InRange(T value) const {
+ return value < min ? -1 : (value > max ? 1 : 0);
+ }
+
T min;
T max;
};