OSDN Git Service

Change Progress.h to SysProgress.h because there are two progress.h file.
[tortoisegit/TortoiseGitJp.git] / src / Git / gittype.h
1 #pragma once\r
2 \r
3 enum\r
4 {\r
5         GIT_SUCCESS=0,\r
6         GIT_ERROR_OPEN_PIP,\r
7         GIT_ERROR_CREATE_PROCESS,\r
8         GIT_ERROR_GET_EXIT_CODE\r
9 };\r
10 \r
11 extern BOOL g_IsWingitDllload;\r
12 \r
13 class CGitByteArray:public std::vector<BYTE>\r
14 {\r
15 public:\r
16         int find(BYTE data,int start=0)\r
17         {\r
18                 for(int i=start;i<size();i++)\r
19                         if( at(i) == data )\r
20                                 return i;\r
21                 return -1;\r
22         }\r
23         int findNextString(int start=0)\r
24         {\r
25                 int pos=start;\r
26                 do\r
27                 {\r
28                         pos=find(0,pos);\r
29                         if(pos >= 0)\r
30                                 pos++;\r
31                         else\r
32                                 break;\r
33 \r
34                         if( pos >= size())\r
35                                 return -1;\r
36 \r
37                 }while(at(pos)==0);\r
38 \r
39                 return pos;\r
40         }\r
41         int findData(const BYTE* dataToFind, size_t dataSize, int start=0)\r
42         {\r
43                 //Pre checks\r
44                 if(empty())\r
45                         return -1;\r
46                 if(dataSize==0)\r
47                         return 0;\r
48                 if(dataSize>size()-start)\r
49                         return -1;//Data to find is greater then data to search in. No match\r
50 \r
51                 //Initialize\r
52                 const BYTE* pos=&*(begin()+start);\r
53                 const BYTE* dataEnd=&*(begin()+(size()-dataSize) );++dataEnd;//Set end one step after last place to search\r
54                 if(pos>=dataEnd)\r
55                         return -1;//Started over end. Return not found\r
56                 if(dataSize==0)\r
57                         return start;//No search data. Return current position\r
58                 BYTE firstByte=dataToFind[0];\r
59                 while(pos<dataEnd)\r
60                 {\r
61                         //memchr for first character\r
62                         const BYTE* found=(const BYTE*)memchr(pos,firstByte,dataEnd-pos);\r
63                         if(found==NULL)\r
64                                 return -1;//Not found\r
65                         //check rest of characters\r
66                         if(memcmp(found,dataToFind,dataSize)==0)\r
67                                 return found-&*begin();//Match. Return position.\r
68                         //No match. Set position on next byte and continue search\r
69                         pos=found+1;\r
70                 }\r
71                 return -1;\r
72         }\r
73         int append( std::vector<BYTE> &v,int start=0,int end=-1)\r
74         {\r
75                 if(end<0)\r
76                         end=v.size();\r
77                 for(int i=start;i<end;i++)\r
78                         this->push_back(v[i]);\r
79                 return 0;\r
80         }\r
81         int append(const BYTE* data, size_t dataSize)\r
82         {\r
83                 size_t oldsize=size();\r
84                 resize(oldsize+dataSize);\r
85                 memcpy(&*(begin()+oldsize),data,dataSize);\r
86                 return 0;\r
87         }\r
88 };\r
89 typedef std::vector<CString> STRING_VECTOR;\r
90 typedef std::map<CString, STRING_VECTOR> MAP_HASH_NAME;\r
91 typedef CGitByteArray BYTE_VECTOR;\r
92 \r