OSDN Git Service

Change Dir Structure to be same as TortoiseSVN'
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RevisionGraph / VisibleGraph.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 "VisibleGraph.h"\r
21 \r
22 // construction / destruction\r
23 \r
24 CVisibleGraph::CVisibleGraph()\r
25     : nodeFactory()\r
26 {\r
27 }\r
28 \r
29 CVisibleGraph::~CVisibleGraph()\r
30 {\r
31     Clear();\r
32 }\r
33 \r
34 // modification\r
35 \r
36 void CVisibleGraph::Clear()\r
37 {\r
38     for (size_t i = roots.size(); i > 0; --i)\r
39         nodeFactory.Destroy (roots[i-1]);\r
40 \r
41     assert (GetNodeCount() == 0);\r
42     roots.clear();\r
43 }\r
44 \r
45 CVisibleGraphNode* CVisibleGraph::Add ( const CFullGraphNode* base\r
46                                       , CVisibleGraphNode* source\r
47                                       , bool preserveNode)\r
48 {\r
49     // (only) the first node must have no parent / prev node\r
50 \r
51     assert ((source == NULL) || !roots.empty());\r
52 \r
53     CVisibleGraphNode* result \r
54         = nodeFactory.Create (base, source, preserveNode);\r
55 \r
56     if (source == NULL)\r
57         roots.push_back (result);\r
58 \r
59     return result;\r
60 }\r
61 \r
62 void CVisibleGraph::ReplaceRoot ( CVisibleGraphNode* oldRoot\r
63                                 , CVisibleGraphNode* newRoot)\r
64 {\r
65     assert (newRoot->GetPrevious() == NULL);\r
66     assert (newRoot->GetCopySource() == NULL);\r
67 \r
68     for (size_t i = 0, count = roots.size(); i < count; ++i)\r
69         if (roots[i] == oldRoot)\r
70         {\r
71             roots[i] = newRoot;\r
72             return;\r
73         }\r
74 \r
75     // we should never get here\r
76 \r
77     assert (0);\r
78 }\r
79 \r
80 void CVisibleGraph::RemoveRoot (CVisibleGraphNode* root)\r
81 {\r
82     for (size_t i = 0, count = roots.size(); i < count; ++i)\r
83         if (roots[i] == root)\r
84         {\r
85             roots[i] = roots[count-1];\r
86             roots.pop_back();\r
87 \r
88             return;\r
89         }\r
90 \r
91     // we should never get here\r
92 \r
93     assert (0);\r
94 }\r
95 \r
96 void CVisibleGraph::AddRoot (CVisibleGraphNode* root)\r
97 {\r
98     assert (root->GetPrevious() == NULL);\r
99     assert (root->GetCopySource() == NULL);\r
100 \r
101     roots.push_back (root);\r
102 }\r
103 \r