OSDN Git Service

Add TortoiseProc
[tortoisegit/TortoiseGitJp.git] / TortoiseProc / RevisionGraph / ModificationOptions.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 \r
20 #include "StdAfx.h"\r
21 #include "ModificationOptions.h"\r
22 #include "VisibleGraph.h"\r
23 #include "VisibleGraphNode.h"\r
24 \r
25 // apply a filter using differnt traversal orders\r
26 \r
27 void CModificationOptions::TraverseFromRootCopiesFirst \r
28     ( IModificationOption* option\r
29     , CVisibleGraph* graph\r
30     , CVisibleGraphNode* node)\r
31 {\r
32     for (CVisibleGraphNode* next = node->GetNext(); node != NULL; node = next)\r
33     {\r
34         next = node->GetNext();\r
35 \r
36         // copies first\r
37 \r
38         for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()\r
39             , *nextCopy = NULL\r
40             ; copy != NULL\r
41             ; copy = nextCopy)\r
42             {\r
43             nextCopy = copy->next();\r
44             TraverseFromRootCopiesFirst (option, graph, copy->value());\r
45         }\r
46 \r
47         // node afterwards\r
48 \r
49         option->Apply (graph, node);\r
50     }\r
51 }\r
52 \r
53 void CModificationOptions::TraverseToRootCopiesFirst \r
54     ( IModificationOption* option\r
55     , CVisibleGraph* graph\r
56     , CVisibleGraphNode* node)\r
57 {\r
58     // crawl to branch end\r
59 \r
60     while (node->GetNext() != NULL)\r
61         node = node->GetNext();\r
62 \r
63     for (CVisibleGraphNode* prev = node->GetPrevious(); node != NULL; node = prev)\r
64     {\r
65         prev = node->GetPrevious();\r
66 \r
67         // copies second\r
68 \r
69         for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()\r
70             , *nextCopy = NULL\r
71             ; copy != NULL\r
72             ; copy = nextCopy)\r
73             {\r
74             nextCopy = copy->next();\r
75             TraverseToRootCopiesFirst (option, graph, copy->value());\r
76         }\r
77 \r
78         // node last\r
79 \r
80         option->Apply (graph, node);\r
81     }\r
82 }\r
83 \r
84 void CModificationOptions::TraverseFromRootCopiesLast \r
85     ( IModificationOption* option\r
86     , CVisibleGraph* graph\r
87     , CVisibleGraphNode* node)\r
88 {\r
89     for (CVisibleGraphNode* next = node->GetNext(); node != NULL; node = next)\r
90     {\r
91         next = node->GetNext();\r
92 \r
93         // node first\r
94 \r
95         option->Apply (graph, node);\r
96 \r
97         // copies last\r
98 \r
99         for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()\r
100             , *nextCopy = NULL\r
101             ; copy != NULL\r
102             ; copy = nextCopy)\r
103             {\r
104             nextCopy = copy->next();\r
105             TraverseFromRootCopiesLast (option, graph, copy->value());\r
106         }\r
107     }\r
108 }\r
109 \r
110 void CModificationOptions::TraverseToRootCopiesLast \r
111     ( IModificationOption* option\r
112     , CVisibleGraph* graph\r
113     , CVisibleGraphNode* node)\r
114 {\r
115     // crawl to branch end\r
116 \r
117     while (node->GetNext() != NULL)\r
118         node = node->GetNext();\r
119 \r
120     for (CVisibleGraphNode* prev = node->GetPrevious(); node != NULL; node = prev)\r
121     {\r
122         prev = node->GetPrevious();\r
123 \r
124         // node afterwards\r
125 \r
126         option->Apply (graph, node);\r
127 \r
128         // copies last\r
129 \r
130         for ( const CVisibleGraphNode::CCopyTarget* copy = node->GetFirstCopyTarget()\r
131             , *nextCopy = NULL\r
132             ; copy != NULL\r
133             ; copy = nextCopy)\r
134             {\r
135             nextCopy = copy->next();\r
136             TraverseToRootCopiesLast (option, graph, copy->value());\r
137         }\r
138     }\r
139 }\r
140 \r
141 // construction\r
142 \r
143 CModificationOptions::CModificationOptions \r
144     ( const std::vector<IModificationOption*>& options)\r
145     : options (options)\r
146 {\r
147 }\r
148 \r
149 // apply all filters \r
150 \r
151 void CModificationOptions::Apply (CVisibleGraph* graph)\r
152 {\r
153     typedef std::vector<IModificationOption*>::const_iterator IT;\r
154 \r
155     // apply filters until the graph is stable\r
156 \r
157     size_t nodeCount = 0;\r
158     while (nodeCount != graph->GetNodeCount())\r
159     {\r
160         nodeCount = graph->GetNodeCount();\r
161         for ( IT iter = options.begin(), end = options.end()\r
162             ; (iter != end)\r
163             ; ++iter)\r
164         {\r
165             for (size_t i = graph->GetRootCount(); i > 0; --i)\r
166             {\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
171                     else\r
172                         TraverseToRootCopiesFirst (*iter, graph, root);\r
173                 else\r
174                     if ((*iter)->WantsRootFirst())\r
175                         TraverseFromRootCopiesLast (*iter, graph, root);\r
176                     else\r
177                         TraverseToRootCopiesLast (*iter, graph, root);\r
178             }\r
179         }\r
180     }\r
181 }\r
182 \r