Improved ExportProfileManager error handling, and added some missing (?) initialization

git-svn-id: svn://localhost/ardour2/branches/3.0@3807 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Sakari Bergen 2008-09-26 12:33:16 +00:00
parent 66ab3d39e0
commit 6f4daaae0a
2 changed files with 49 additions and 33 deletions

View file

@ -25,6 +25,7 @@
#include <vector>
#include <map>
#include <set>
#include <stdexcept>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
@ -143,7 +144,7 @@ class ExportProfileManager
typedef std::list<TimespanStatePtr> 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<ChannelConfigState> ChannelConfigStatePtr;
typedef std::list<ChannelConfigStatePtr> 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<FormatState> FormatStatePtr;
typedef std::list<FormatStatePtr> 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<FilenameState> FilenameStatePtr;
typedef std::list<FilenameStatePtr> 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<typename T>
std::list<T> const &
check_list (std::list<T> const & list)
{
if (list.empty()) {
throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager");
}
return list;
}
};

View file

@ -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 ();
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;
}