OSDN Git Service

Change Dir Structure to be same as TortoiseSVN'
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RevisionGraph / PathClassificator.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2007-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 #pragma once\r
20 \r
21 // required includes\r
22 \r
23 #include "DictionaryBasedTempPath.h"\r
24 #include "NodeClassification.h"\r
25 \r
26 /**\r
27  * Efficiently classifies a path as "trunk", "branches" or "tags".\r
28  * For every class, a list of wild card patterns separated by semicolon \r
29  * can be specified. Example "tags;qa ?;qa ?.*". String comparison\r
30  * is case-insensitive for latin chars ('a' .. 'z').\r
31  * A given path may be assigned to multiple classes.\r
32  */\r
33 \r
34 class CPathClassificator\r
35 {\r
36 private:\r
37 \r
38     class CWildCardPattern\r
39     {\r
40     private:\r
41 \r
42         /// pattern to match against\r
43 \r
44         std::string pattern;\r
45 \r
46         /// algorithm selection\r
47 \r
48         bool hasWildCards;\r
49 \r
50         /// different matching algorithms\r
51 \r
52         bool WildCardMatch (const char* s, const char* pattern) const;\r
53         bool StraightMatch (const char* s, size_t length) const;\r
54 \r
55         /// construction utility\r
56 \r
57         void NormalizePattern();\r
58 \r
59     public:\r
60 \r
61         /// construction\r
62 \r
63         CWildCardPattern (const std::string& pattern);\r
64 \r
65         /// match s against the pattern\r
66 \r
67         bool Match (const char* s, size_t length) const;\r
68     };\r
69 \r
70     /// the patterns to detect trunk, branches and tags\r
71 \r
72     typedef std::vector<CWildCardPattern> TPatterns;\r
73 \r
74     TPatterns trunkPatterns;\r
75     TPatterns branchesPatterns;\r
76     TPatterns tagsPatterns;\r
77 \r
78     /// path classification\r
79 \r
80     std::vector<unsigned char> pathElementClassification;\r
81     std::vector<unsigned char> pathClassification;\r
82 \r
83     /// construction utilities\r
84 \r
85     TPatterns ParsePatterns (const std::string& patterns) const;\r
86 \r
87     bool Matches ( TPatterns::const_iterator firstPattern\r
88                  , TPatterns::const_iterator lastPattern\r
89                  , const char* element\r
90                  , size_t length) const;\r
91     void ClassifyPathElements ( const LogCache::CStringDictionary& elements\r
92                               , const TPatterns& patterns\r
93                               , unsigned char classification);\r
94     void ClassifyPathElements (const LogCache::CStringDictionary& elements);\r
95     void ClassifyPaths (const LogCache::CPathDictionary& paths);\r
96 \r
97 public:\r
98 \r
99     /// construction / destruction\r
100 \r
101     CPathClassificator ( const LogCache::CPathDictionary& paths\r
102                        , const std::string& trunkPatterns = "trunk"\r
103                        , const std::string& branchesPatterns = "branches"\r
104                        , const std::string& tagsPatterns = "tags");\r
105     ~CPathClassificator(void);\r
106 \r
107     /// get the classification for a given path\r
108 \r
109     unsigned char GetClassification (const LogCache::index_t pathID) const;\r
110     unsigned char operator[](const LogCache::CDictionaryBasedPath& path) const;\r
111 \r
112     unsigned char GetClassification (const LogCache::CDictionaryBasedTempPath& path) const;\r
113     unsigned char operator[](const LogCache::CDictionaryBasedTempPath& path) const;\r
114 };\r
115 \r
116 /// get the classification for a given path\r
117 \r
118 inline unsigned char \r
119 CPathClassificator::GetClassification (const LogCache::index_t pathID) const\r
120 {\r
121     return pathClassification[pathID];\r
122 }\r
123 \r
124 inline unsigned char \r
125 CPathClassificator::operator[](const LogCache::CDictionaryBasedPath& path) const\r
126 {\r
127     return GetClassification (path.GetIndex());\r
128 }\r
129 \r
130 inline unsigned char \r
131 CPathClassificator::operator[](const LogCache::CDictionaryBasedTempPath& path) const\r
132 {\r
133     return GetClassification (path);\r
134 }\r