OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / TortoiseProc / RevisionGraph / VisibleGraphBuilder.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 #include "StdAfx.h"\r
20 #include "VisibleGraphBuilder.h"\r
21 #include "FullGraph.h"\r
22 #include "VisibleGraph.h"\r
23 #include "CopyFilterOptions.h"\r
24 \r
25 #ifdef _DEBUG\r
26 #define new DEBUG_NEW\r
27 #undef THIS_FILE\r
28 static char THIS_FILE[] = __FILE__;\r
29 #endif\r
30 \r
31 // construction / destruction (nothing to do here)\r
32 \r
33 CVisibleGraphBuilder::CVisibleGraphBuilder \r
34     ( const CFullGraph& fullGraph\r
35     , CVisibleGraph& visibleGraph\r
36     , const CCopyFilterOptions& copyFilter)\r
37     : fullGraph (fullGraph)\r
38     , visibleGraph (visibleGraph)\r
39     , copyFilter (copyFilter)\r
40 {\r
41 }\r
42 \r
43 CVisibleGraphBuilder::~CVisibleGraphBuilder(void)\r
44 {\r
45 }\r
46 \r
47 // copy\r
48 \r
49 void CVisibleGraphBuilder::Run()\r
50 {\r
51     visibleGraph.Clear();\r
52     Copy (fullGraph.GetRoot(), NULL);\r
53 }\r
54 \r
55 // the actual copy loop\r
56 \r
57 void CVisibleGraphBuilder::CopyBranches ( const CFullGraphNode* source\r
58                                         , CVisibleGraphNode* target)\r
59 {\r
60     for ( const CFullGraphNode::CCopyTarget* copy = source->GetFirstCopyTarget()\r
61         ; copy != NULL\r
62         ; copy = copy->next())\r
63     {\r
64         Copy (copy->value(), target);\r
65     }\r
66 }\r
67 \r
68 void CVisibleGraphBuilder::Copy ( const CFullGraphNode* source\r
69                                 , CVisibleGraphNode* target)\r
70 {\r
71     do\r
72     {\r
73         ICopyFilterOption::EResult filterAction = copyFilter.ShallRemove (source);\r
74         while (   (filterAction != ICopyFilterOption::KEEP_NODE)\r
75                && (filterAction != ICopyFilterOption::PRESERVE_NODE))\r
76         {\r
77             // stop copy here, if the whole sub-tree shall be removed\r
78 \r
79             if (filterAction == ICopyFilterOption::REMOVE_SUBTREE)\r
80                 return;\r
81 \r
82             // skip this node\r
83 \r
84             assert (filterAction == ICopyFilterOption::REMOVE_NODE);\r
85             CopyBranches (source, NULL);\r
86 \r
87             source = source->GetNext();\r
88 \r
89             // end of branch?\r
90 \r
91             if (source == NULL)\r
92                 return;\r
93 \r
94             // test next node\r
95 \r
96             filterAction = copyFilter.ShallRemove (source);\r
97         }\r
98 \r
99         // copy the node itself\r
100 \r
101         bool preserveNode = filterAction != ICopyFilterOption::PRESERVE_NODE;\r
102         target = visibleGraph.Add (source, target, preserveNode);\r
103 \r
104         // copy branches\r
105 \r
106         CopyBranches (source, target);\r
107 \r
108         // next node\r
109 \r
110         source = source->GetNext();\r
111     }\r
112     while (source != NULL);\r
113 }\r