OSDN Git Service

Change Dir Structure to be same as TortoiseSVN'
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RevisionGraph / FullGraphNode.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 "FullGraphNode.h"\r
22 \r
23 // CVisibleGraphNode::CFactory methods\r
24 \r
25 CFullGraphNode::CFactory::CFactory()\r
26     : nodePool (sizeof (CFullGraphNode), 1024)\r
27     , copyTargetFactory()\r
28 {\r
29 }\r
30 \r
31 CFullGraphNode* CFullGraphNode::CFactory::Create \r
32     ( const CDictionaryBasedTempPath& path\r
33     , revision_t revision\r
34     , CNodeClassification classification\r
35     , CFullGraphNode* source)\r
36 {\r
37     CFullGraphNode * result = static_cast<CFullGraphNode *>(nodePool.malloc());\r
38     new (result) CFullGraphNode (path, revision, classification, source, copyTargetFactory);\r
39     return result;\r
40 }\r
41 \r
42 void CFullGraphNode::CFactory::Replace ( CFullGraphNode* toReplace\r
43                                        , CFullGraphNode::CCopyTarget*& toMove\r
44                                        , CNodeClassification newClassification)\r
45 {\r
46     // remove the old node\r
47 \r
48     CFullGraphNode* previousNode = toReplace->GetPrevious();\r
49     Destroy (toReplace);\r
50 \r
51     // extract the new node\r
52 \r
53     CFullGraphNode* toInsert = copyTargetFactory.remove (toMove);\r
54 \r
55     // (re-)insert the new node\r
56 \r
57     toInsert->classification = newClassification;\r
58     toInsert->InsertAt (previousNode, copyTargetFactory);\r
59 }\r
60 \r
61 void CFullGraphNode::CFactory::Destroy (CFullGraphNode* node)\r
62 {\r
63     node->DestroySubNodes (*this, copyTargetFactory);\r
64 \r
65     node->~CFullGraphNode();\r
66     nodePool.free (node);\r
67 }\r
68 \r
69 // CVisibleGraphNode construction / destruction \r
70 \r
71 CFullGraphNode::CFullGraphNode \r
72     ( const CDictionaryBasedTempPath& path\r
73     , revision_t revision\r
74     , CNodeClassification classification\r
75     , CFullGraphNode* source\r
76     , CCopyTarget::factory& copyTargetFactory)\r
77     : path (path)\r
78     , realPathID (path.GetBasePath().GetIndex())\r
79         , firstCopyTarget(NULL)\r
80     , prev (NULL)\r
81     , next (NULL)\r
82     , copySource (NULL)\r
83     , revision (revision)\r
84     , classification (classification)\r
85 {\r
86     InsertAt (source, copyTargetFactory);\r
87 }\r
88 \r
89 CFullGraphNode::~CFullGraphNode() \r
90 {\r
91     assert (next == NULL);\r
92     assert (firstCopyTarget == NULL);\r
93 };\r
94 \r
95 void CFullGraphNode::InsertAt ( CFullGraphNode* source\r
96                               , CCopyTarget::factory& copyTargetFactory)\r
97 {\r
98     if (source != NULL)\r
99         if (classification.Is (CNodeClassification::IS_COPY_TARGET))\r
100         {\r
101             copySource = source;\r
102             prev = NULL;\r
103             copyTargetFactory.insert (this, source->firstCopyTarget);\r
104         }\r
105         else\r
106         {\r
107             copySource = NULL;\r
108             source->next = this;\r
109             prev = source;\r
110         }\r
111 }\r
112 \r
113 void CFullGraphNode::DestroySubNodes \r
114     ( CFactory& factory\r
115     , CCopyTarget::factory& copyTargetFactory)\r
116 {\r
117     while (next != NULL)\r
118     {\r
119         CFullGraphNode* toDestroy = next; \r
120         next = toDestroy->next;\r
121         toDestroy->next = NULL;\r
122 \r
123         factory.Destroy (toDestroy);\r
124     }\r
125 \r
126     while (firstCopyTarget)\r
127     {\r
128         factory.Destroy (copyTargetFactory.remove (firstCopyTarget));\r
129     }\r
130 }\r