diff options
author | David Robillard <d@drobilla.net> | 2008-08-02 20:42:23 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-08-02 20:42:23 +0000 |
commit | 503944e72ce146e5bed2556e7b2caa5a41edd7ea (patch) | |
tree | 2259f758036ecb680b208106fd866d58bf4560c5 | |
parent | 925022321b8f7dba8b10993a9cd32c0cc0b45e0d (diff) | |
download | patchage-503944e72ce146e5bed2556e7b2caa5a41edd7ea.tar.gz patchage-503944e72ce146e5bed2556e7b2caa5a41edd7ea.tar.bz2 patchage-503944e72ce146e5bed2556e7b2caa5a41edd7ea.zip |
Format split/location code from Nedko for consistency.
Make coordinates valid over all possible values (including -1).
git-svn-id: http://svn.drobilla.net/lad/patchage@1318 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/StateManager.cpp | 66 | ||||
-rw-r--r-- | src/StateManager.hpp | 22 |
2 files changed, 40 insertions, 48 deletions
diff --git a/src/StateManager.cpp b/src/StateManager.cpp index 78a0e0d..32e3d7d 100644 --- a/src/StateManager.cpp +++ b/src/StateManager.cpp @@ -26,12 +26,10 @@ using namespace std; StateManager::StateManager() + : _window_location(0, 0) + , _window_size(640, 480) + , _zoom(1.0) { - _window_location.x = 0; - _window_location.y = 0; - _window_size.x = 640; - _window_size.y = 480; - _zoom = 1.0; } @@ -40,30 +38,34 @@ StateManager::get_module_location(const string& name, ModuleType type, Coord& lo { map<string, ModuleSettings>::const_iterator i = _module_settings.find(name); if (i == _module_settings.end()) - { return false; - } const ModuleSettings& settings = (*i).second; - switch (type) - { + + switch (type) { case Input: - loc = settings.input_location; - goto check; + if (settings.input_location) { + loc = *settings.input_location; + return true; + } + break; case Output: - loc = settings.output_location; - goto check; + if (settings.output_location) { + loc = *settings.output_location; + return true; + } + break; case InputOutput: - loc = settings.inout_location; - goto check; + if (settings.inout_location) { + loc = *settings.inout_location; + return true; + } + break; default: throw std::runtime_error("Invalid module type"); } return false; - -check: - return loc.x != UNINITIALIZED_COORD; } @@ -72,8 +74,7 @@ StateManager::set_module_location(const string& name, ModuleType type, Coord loc { retry: map<string, ModuleSettings>::iterator i = _module_settings.find(name); - if (i == _module_settings.end()) - { + if (i == _module_settings.end()) { // no mapping exists, insert new element and set its split type, then retry to retrieve reference to it _module_settings[name].split = type != InputOutput; goto retry; @@ -81,8 +82,7 @@ retry: ModuleSettings& settings_ref = (*i).second; - switch (type) - { + switch (type) { case Input: settings_ref.input_location = loc; break; @@ -108,9 +108,7 @@ StateManager::get_module_split(const string& name, bool default_val) const { map<string, ModuleSettings>::const_iterator i = _module_settings.find(name); if (i == _module_settings.end()) - { return default_val; - } return (*i).second.split; } @@ -208,9 +206,7 @@ StateManager::load(const string& filename) is.close(); } -static -inline -void +static inline void write_module_settings_entry( std::ofstream& os, const string& name, @@ -235,14 +231,11 @@ StateManager::save(const string& filename) const ModuleSettings& settings = (*i).second; const string& name = (*i).first; - if (settings.split) - { - write_module_settings_entry(os, name, "input", settings.input_location); - write_module_settings_entry(os, name, "output", settings.output_location); - } - else - { - write_module_settings_entry(os, name, "inputoutput", settings.inout_location); + if (settings.split) { + write_module_settings_entry(os, name, "input", *settings.input_location); + write_module_settings_entry(os, name, "output", *settings.output_location); + } else { + write_module_settings_entry(os, name, "inputoutput", *settings.inout_location); } } @@ -277,4 +270,5 @@ StateManager::get_port_color(PortType type) return 0x4A8A0EC0; else return 0xFF0000FF; -} +} + diff --git a/src/StateManager.hpp b/src/StateManager.hpp index 12cdbb9..3899eef 100644 --- a/src/StateManager.hpp +++ b/src/StateManager.hpp @@ -22,15 +22,13 @@ #include <list> #include <map> #include <iostream> +#include <boost/optional.hpp> #include "PatchagePort.hpp" enum ModuleType { Input, Output, InputOutput }; -#define UNINITIALIZED_COORD -1 -struct Coord -{ - Coord() { x = UNINITIALIZED_COORD; y = UNINITIALIZED_COORD; } - Coord(double x_, double y_) : x(x_), y(y_) {} +struct Coord { + Coord(double x_=0, double y_=0) : x(x_), y(y_) {} double x; double y; }; @@ -61,17 +59,17 @@ public: private: struct ModuleSettings { - ModuleSettings() { split = false; }; + ModuleSettings() : split(false) {} bool split; - Coord input_location; - Coord output_location; - Coord inout_location; + boost::optional<Coord> input_location; + boost::optional<Coord> output_location; + boost::optional<Coord> inout_location; }; std::map<std::string,ModuleSettings> _module_settings; - Coord _window_location; - Coord _window_size; - float _zoom; + Coord _window_location; + Coord _window_size; + float _zoom; }; |