InsertVertexDelta.cpp

Go to the documentation of this file.
00001 
00008 /* Copyright © 2009 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 "InsertVertexDelta.h"
00016 #include "../Track.h"
00017 #include "ClearVertexDelta.h"
00018 
00019 #include <Debug.h>
00020 
00021 namespace Document
00022 {
00023 
00024 InsertRemoveVertexIdentifier::InsertRemoveVertexIdentifier(Track::PathVertex object)
00025     :   InsertRemoveIdentifier<std::size_t, Track::PathVertex>(object.get_name())
00026 {
00027 }
00028 
00029 InsertRemoveVertexIdentifier::InsertRemoveVertexIdentifier(std::size_t vertex_index)
00030     :   InsertRemoveIdentifier<std::size_t, Track::PathVertex>(vertex_index)
00031 {
00032 }
00033 
00034 void InsertRemoveVertexIdentifier::insert(Track::Track & track, Track::PathVertex object) const
00035 {
00036     assert(object.get_name() == identifier);
00037     object.set_track(&track);
00038     Track::Path::Graph & graph = track.get_path().graph;
00039     boost::add_vertex(object, graph);
00040 }
00041 
00042 Track::PathVertex InsertRemoveVertexIdentifier::remove(Track::Track & track) const
00043 {
00044     Track::Path & path = track.get_path();
00045     Track::Path::Graph & graph = path.graph;
00046     Track::Path::Graph::vertex_descriptor vertex_descriptor = path.get_node_descriptor(identifier);
00047     // check that there is no edges using this vertex in debug build.
00048     assert(boost::out_degree(vertex_descriptor, graph) == 0);
00049     assert(boost::in_degree(vertex_descriptor, graph) == 0);
00050     // remove the vertex, but keep the data so we can undo it later.
00051     Track::PathVertex vertex = graph[vertex_descriptor];
00052     boost::remove_vertex(vertex_descriptor, graph);
00053     return vertex;
00054 }
00055 
00056 RemoveVertexDelta::RemoveVertexDelta(std::size_t vertex_index)
00057     :   vertex_index(vertex_index)
00058 {
00059 }
00060 
00061 void RemoveVertexDelta::apply(Track::Track & track)
00062 {
00063     // remove attached edges
00064     boost::shared_ptr<DocumentDelta> clear_delta(
00065         new ClearVertexDelta(vertex_index)
00066     );
00067     add_to_stack(clear_delta, track);
00068     
00069     // now remove the vertex itself.
00070     boost::shared_ptr<DocumentDelta> delta(new RemoveVertexOnlyDelta(vertex_index));
00071     add_to_stack(delta, track);
00072 }
00073 
00074 } // namespace Document
00075 

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.