1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 #include "ModificationOptions.h"
\r
22 #include "VisibleGraph.h"
\r
23 #include "VisibleGraphNode.h"
\r
25 // apply a filter using differnt traversal orders
\r
27 void CModificationOptions::TraverseFromRootCopiesFirst
\r
28 ( IModificationOption* option
\r
29 , CVisibleGraph* graph
\r
30 , CVisibleGraphNode* node)
\r
32 for (CVisibleGraphNode* next = node->GetNext(); node != NULL; node = next)
\r
34 next = node->GetNext();
\r
38 for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()
\r
43 nextCopy = copy->next();
\r
44 TraverseFromRootCopiesFirst (option, graph, copy->value());
\r
49 option->Apply (graph, node);
\r
53 void CModificationOptions::TraverseToRootCopiesFirst
\r
54 ( IModificationOption* option
\r
55 , CVisibleGraph* graph
\r
56 , CVisibleGraphNode* node)
\r
58 // crawl to branch end
\r
60 while (node->GetNext() != NULL)
\r
61 node = node->GetNext();
\r
63 for (CVisibleGraphNode* prev = node->GetPrevious(); node != NULL; node = prev)
\r
65 prev = node->GetPrevious();
\r
69 for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()
\r
74 nextCopy = copy->next();
\r
75 TraverseToRootCopiesFirst (option, graph, copy->value());
\r
80 option->Apply (graph, node);
\r
84 void CModificationOptions::TraverseFromRootCopiesLast
\r
85 ( IModificationOption* option
\r
86 , CVisibleGraph* graph
\r
87 , CVisibleGraphNode* node)
\r
89 for (CVisibleGraphNode* next = node->GetNext(); node != NULL; node = next)
\r
91 next = node->GetNext();
\r
95 option->Apply (graph, node);
\r
99 for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()
\r
104 nextCopy = copy->next();
\r
105 TraverseFromRootCopiesLast (option, graph, copy->value());
\r
110 void CModificationOptions::TraverseToRootCopiesLast
\r
111 ( IModificationOption* option
\r
112 , CVisibleGraph* graph
\r
113 , CVisibleGraphNode* node)
\r
115 // crawl to branch end
\r
117 while (node->GetNext() != NULL)
\r
118 node = node->GetNext();
\r
120 for (CVisibleGraphNode* prev = node->GetPrevious(); node != NULL; node = prev)
\r
122 prev = node->GetPrevious();
\r
126 option->Apply (graph, node);
\r
130 for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()
\r
135 nextCopy = copy->next();
\r
136 TraverseToRootCopiesLast (option, graph, copy->value());
\r
143 CModificationOptions::CModificationOptions
\r
144 ( const std::vector<IModificationOption*>& options)
\r
145 : options (options)
\r
149 // apply all filters
\r
151 void CModificationOptions::Apply (CVisibleGraph* graph)
\r
153 typedef std::vector<IModificationOption*>::const_iterator IT;
\r
155 // apply filters until the graph is stable
\r
157 size_t nodeCount = 0;
\r
158 while (nodeCount != graph->GetNodeCount())
\r
160 nodeCount = graph->GetNodeCount();
\r
161 for ( IT iter = options.begin(), end = options.end()
\r
165 for (size_t i = graph->GetRootCount(); i > 0; --i)
\r
167 CVisibleGraphNode* root = graph->GetRoot (i-1);
\r
168 if ((*iter)->WantsCopiesFirst())
\r
169 if ((*iter)->WantsRootFirst())
\r
170 TraverseFromRootCopiesFirst (*iter, graph, root);
\r
172 TraverseToRootCopiesFirst (*iter, graph, root);
\r
174 if ((*iter)->WantsRootFirst())
\r
175 TraverseFromRootCopiesLast (*iter, graph, root);
\r
177 TraverseToRootCopiesLast (*iter, graph, root);
\r