1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| bool Project::save()
{
using namespace boost::property_tree;
// fill it with properties that needs to be saved
ptree infos;
infos.put( "project.name", name() );
foreach_sequence( [&]( const Sequence& sequence )
{
infos.add( "project.sequences.sequence", sequence.location().generic_string() );
});
foreach_edition( [&]( const EditionSession& edition_session )
{
infos.add( "project.edition.session", edition_session.id() );
});
if( m_selected_session )
infos.add( "project.edition.selected", m_selected_session->id() );
// TODO : add other informations here
// TODO : manage errors differently
try
{
namespace bfs = boost::filesystem;
const auto directory_path = m_location.parent_path();
// make sure the directory is available
if( !bfs::is_directory( directory_path ) )
{
bfs::create_directories( directory_path );
}
bfs::ofstream filestream( m_location );
write_xml( filestream, infos );
}
catch( const boost::exception& e )
{
UTILCPP_LOG_ERROR << boost::diagnostic_information(e);
return false;
}
std::for_each( m_sequences.begin(), m_sequences.end(), [&]( std::unique_ptr<Sequence>& sequence )
{
sequence->save();
});
std::for_each( m_edit_sessions.begin(), m_edit_sessions.end(), [&]( std::unique_ptr<EditionSession>& edition_session )
{
const auto& file_path = directory_path() / path::EDITION_SESSION_FILE( edition_session->id() );
edition_session->save( file_path );
});
return true;
}
void Project::foreach_sequence( std::function< void ( const Sequence& sequence )> func ) const
{
std::for_each( m_sequences.begin(), m_sequences.end(), [&]( const std::unique_ptr<Sequence>& a_sequence ){ func(*a_sequence); } );
}
void Project::foreach_edition( std::function< void ( const EditionSession& edition_session )> func ) const
{
std::for_each( m_edit_sessions.begin(), m_edit_sessions.end(), [&]( const std::unique_ptr<EditionSession>& a_session ){ func(*a_session); } );
} |
Partager