From e35ce0069094c135ed9065f2bda945fdf4b6d83e Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 2 Jan 2013 11:33:59 -0500 Subject: 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. --- pulse.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pulse.cc') diff --git a/pulse.cc b/pulse.cc index cbbe405..e42db12 100644 --- a/pulse.cc +++ b/pulse.cc @@ -305,12 +305,12 @@ bool PulseClient::SetVolume(Device& device, long volume) { bool PulseClient::IncreaseVolume(Device& device, long increment) { return SetVolume(device, - volume_range_.clamp(device.volume_percent_ + increment)); + volume_range_.Clamp(device.volume_percent_ + increment)); } bool PulseClient::DecreaseVolume(Device& device, long increment) { return SetVolume(device, - volume_range_.clamp(device.volume_percent_ - increment)); + volume_range_.Clamp(device.volume_percent_ - increment)); } bool PulseClient::SetBalance(Device& device, long balance) { @@ -339,12 +339,12 @@ bool PulseClient::SetBalance(Device& device, long balance) { bool PulseClient::IncreaseBalance(Device& device, long increment) { return SetBalance(device, - balance_range_.clamp(device.balance_ + increment)); + balance_range_.Clamp(device.balance_ + increment)); } bool PulseClient::DecreaseBalance(Device& device, long increment) { return SetBalance(device, - balance_range_.clamp(device.balance_ - increment)); + balance_range_.Clamp(device.balance_ - increment)); } int PulseClient::GetVolume(const Device& device) const { -- cgit v1.2.3