InsertTrackAttachmentDelta.cpp

Go to the documentation of this file.
00001 
00008 /* Copyright © 2009, 2010 James Legg.
00009     This program is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 */
00014 
00015 #include "InsertTrackAttachmentDelta.h"
00016 #include "../Track.h"
00017 #include <Debug.h>
00018 
00019 namespace Document
00020 {
00021 
00022 InsertRemoveTrackAttachmentIdentifier::InsertRemoveTrackAttachmentIdentifier(const boost::shared_ptr<Track::TrackAttachment> & obj)
00023     :   InsertRemoveIdentifier<std::pair<std::size_t, std::size_t>, boost::shared_ptr<Track::TrackAttachment> >
00024             (std::pair<std::size_t, std::size_t>(obj->get_name(), obj->edge_name))
00025 {
00026 }
00027 
00028 InsertRemoveTrackAttachmentIdentifier::InsertRemoveTrackAttachmentIdentifier(std::size_t attachment_name, std::size_t edge_name)
00029     :   InsertRemoveIdentifier<std::pair<std::size_t, std::size_t>, boost::shared_ptr<Track::TrackAttachment> >
00030             (std::pair<std::size_t, std::size_t>(attachment_name, edge_name))
00031 {
00032 }
00033 
00034 void InsertRemoveTrackAttachmentIdentifier::insert(Track::Track & track, boost::shared_ptr<Track::TrackAttachment> object) const
00035 {
00036     // insert.
00037     // First check if we are adding the right object.
00038     assert((object->get_name() == identifier.first));
00039     track.get_path().get_edge(identifier.second).insert_attachment(object);
00040 }
00041 
00042 boost::shared_ptr<Track::TrackAttachment> InsertRemoveTrackAttachmentIdentifier::remove(Track::Track & track) const
00043 {
00044     // remove but return a copy.
00045     typedef std::vector<boost::shared_ptr<Track::TrackAttachment> > VectorType;
00046     Track::PathEdge & edge = track.get_path().get_edge(identifier.second);
00047     const VectorType & vector = edge.get_attachments();
00048     for (VectorType::const_iterator it = vector.begin();
00049          it != vector.end();
00050          it++)
00051     {
00052         if ((**it).get_name() == identifier.first)
00053         {
00054             boost::shared_ptr<Track::TrackAttachment> ptr = (*it);
00055             edge.remove_attachment(identifier.first);
00056             return ptr;
00057         }
00058     }
00059     // could not be found. Editor's state is broken.
00060     assert(false);
00061 }
00062 
00063 } // namespace Document

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:11 2010 by Doxygen version 1.4.7 for Racer version svn335.