From 6f4daaae0af346bc8a3a1b528a043b45198b687a Mon Sep 17 00:00:00 2001 From: Sakari Bergen Date: Fri, 26 Sep 2008 12:33:16 +0000 Subject: Improved ExportProfileManager error handling, and added some missing (?) initialization git-svn-id: svn://localhost/ardour2/branches/3.0@3807 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/export_profile_manager.h | 23 +++++++++-- libs/ardour/export_profile_manager.cc | 59 +++++++++++++++-------------- 2 files changed, 49 insertions(+), 33 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/ardour/export_profile_manager.h b/libs/ardour/ardour/export_profile_manager.h index d63549e185..d2f1c162e0 100644 --- a/libs/ardour/ardour/export_profile_manager.h +++ b/libs/ardour/ardour/export_profile_manager.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -143,7 +144,7 @@ class ExportProfileManager typedef std::list TimespanStateList; void set_selection_range (nframes_t start = 0, nframes_t end = 0); - TimespanStateList const & get_timespans () { return timespans; } + TimespanStateList const & get_timespans () { return check_list (timespans); } private: @@ -175,7 +176,7 @@ class ExportProfileManager typedef boost::shared_ptr ChannelConfigStatePtr; typedef std::list ChannelConfigStateList; - ChannelConfigStateList const & get_channel_configs () { return channel_configs; } + ChannelConfigStateList const & get_channel_configs () { return check_list (channel_configs); } private: @@ -199,7 +200,7 @@ class ExportProfileManager typedef boost::shared_ptr FormatStatePtr; typedef std::list FormatStateList; - FormatStateList const & get_formats () { return formats; } + FormatStateList const & get_formats () { return check_list (formats); } FormatStatePtr duplicate_format_state (FormatStatePtr state); void remove_format_state (FormatStatePtr state); @@ -238,7 +239,7 @@ class ExportProfileManager typedef boost::shared_ptr FilenameStatePtr; typedef std::list FilenameStateList; - FilenameStateList const & get_filenames () { return filenames; } + FilenameStateList const & get_filenames () { return check_list (filenames); } FilenameStatePtr duplicate_filename_state (FilenameStatePtr state); void remove_filename_state (FilenameStatePtr state); @@ -265,6 +266,20 @@ class ExportProfileManager ChannelConfigStatePtr channel_config_state, FormatStatePtr format_state, FilenameStatePtr filename_state); + + /* Utilities */ + + /* Element state lists should never be empty, this is used to check them */ + template + std::list const & + check_list (std::list const & list) + { + if (list.empty()) { + throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager"); + } + return list; + } + }; diff --git a/libs/ardour/export_profile_manager.cc b/libs/ardour/export_profile_manager.cc index ac17ec7310..e9edf5feef 100644 --- a/libs/ardour/export_profile_manager.cc +++ b/libs/ardour/export_profile_manager.cc @@ -80,6 +80,14 @@ ExportProfileManager::ExportProfileManager (Session & s) : load_presets (); load_formats (); + + /* Initialize all lists with an empty config */ + + XMLNodeList dummy; + init_timespans (dummy); + init_channel_configs (dummy); + init_formats (dummy); + init_filenames (dummy); } ExportProfileManager::~ExportProfileManager () @@ -294,21 +302,23 @@ bool ExportProfileManager::init_timespans (XMLNodeList nodes) { timespans.clear (); - - if (nodes.empty()) { - update_ranges (); + update_ranges (); - TimespanStatePtr timespan (new TimespanState (session_range, selection_range, ranges)); + bool ok = true; + for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { + TimespanStatePtr span = deserialize_timespan (**it); + if (span) { + timespans.push_back (span); + } else { ok = false; } + } + if (timespans.empty()) { + TimespanStatePtr timespan (new TimespanState (session_range, selection_range, ranges)); timespans.push_back (timespan); return false; } - - for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { - timespans.push_back (deserialize_timespan (**it)); - } - return true; + return ok; } ExportProfileManager::TimespanStatePtr @@ -317,8 +327,6 @@ ExportProfileManager::deserialize_timespan (XMLNode & root) TimespanStatePtr state (new TimespanState (session_range, selection_range, ranges)); XMLProperty const * prop; - update_ranges (); - XMLNodeList spans = root.children ("Range"); for (XMLNodeList::iterator node_it = spans.begin(); node_it != spans.end(); ++node_it) { @@ -517,27 +525,20 @@ ExportProfileManager::get_new_format (FormatPtr original) bool ExportProfileManager::init_formats (XMLNodeList nodes) { - bool ok = true; formats.clear(); - if (nodes.empty()) { - FormatStatePtr format (new FormatState (format_list, FormatPtr ())); - formats.push_back (format); - return false; - } - + bool ok = true; for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { - FormatStatePtr format; - if ((format = deserialize_format (**it))) { + FormatStatePtr format = deserialize_format (**it); + if (format) { formats.push_back (format); - } else { - ok = false; - } + } else { ok = false; } } if (formats.empty ()) { FormatStatePtr format (new FormatState (format_list, FormatPtr ())); formats.push_back (format); + return false; } return ok; @@ -622,18 +623,18 @@ ExportProfileManager::init_filenames (XMLNodeList nodes) { filenames.clear (); - if (nodes.empty()) { - FilenameStatePtr filename (new FilenameState (handler->add_filename())); - filenames.push_back (filename); - return false; - } - for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { FilenamePtr filename = handler->add_filename(); filename->set_state (**it); filenames.push_back (FilenameStatePtr (new FilenameState (filename))); } + if (filenames.empty()) { + FilenameStatePtr filename (new FilenameState (handler->add_filename())); + filenames.push_back (filename); + return false; + } + return true; } -- cgit v1.2.3