drop unreferenced code
[TortoiseGit.git] / src / Git / gittype.h
blobd9248b9081353b8c7530e92f75c7200eb6061f70
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "GitHash.h"
23 enum
25 TGIT_GIT_SUCCESS=0,
26 TGIT_GIT_ERROR_OPEN_PIP,
27 TGIT_GIT_ERROR_CREATE_PROCESS,
28 TGIT_GIT_ERROR_GET_EXIT_CODE
31 extern BOOL g_IsWingitDllload;
33 class CGitByteArray:public std::vector<BYTE>
35 public:
36 CGitByteArray(){ m_critSec.Init(); }
37 CComCriticalSection m_critSec;
39 int find(BYTE data,int start=0)
41 for(unsigned int i=start;i<size();i++)
42 if( at(i) == data )
43 return i;
44 return -1;
46 int RevertFind(BYTE data, int start=-1)
48 if(start == -1)
49 start=size()-1;
51 if(start<0)
52 return -1;
54 for(int i=start; i>=0;i--)
55 if( at(i) == data )
56 return i;
57 return -1;
59 int findNextString(int start=0)
61 int pos=start;
64 pos=find(0,pos);
65 if(pos >= 0)
66 pos++;
67 else
68 break;
70 if( pos >= size())
71 return -1;
73 }while(at(pos)==0);
75 return pos;
77 int findData(const BYTE* dataToFind, size_t dataSize, int start=0)
79 //Pre checks
80 if(empty())
81 return -1;
82 if(dataSize==0)
83 return 0;
84 if(dataSize>size()-start)
85 return -1;//Data to find is greater then data to search in. No match
87 //Initialize
88 const BYTE* pos=&*(begin()+start);
89 const BYTE* dataEnd=&*(begin()+(size()-dataSize) );++dataEnd;//Set end one step after last place to search
90 if(pos>=dataEnd)
91 return -1;//Started over end. Return not found
92 if(dataSize==0)
93 return start;//No search data. Return current position
94 BYTE firstByte=dataToFind[0];
95 while(pos<dataEnd)
97 //memchr for first character
98 const BYTE* found=(const BYTE*)memchr(pos,firstByte,dataEnd-pos);
99 if(found==NULL)
100 return -1;//Not found
101 //check rest of characters
102 if(memcmp(found,dataToFind,dataSize)==0)
103 return found-&*begin();//Match. Return position.
104 //No match. Set position on next byte and continue search
105 pos=found+1;
107 return -1;
109 int append( std::vector<BYTE> &v,int start=0,int end=-1)
111 if(end<0)
112 end=v.size();
113 for(int i=start;i<end;i++)
114 this->push_back(v[i]);
115 return 0;
117 int append(const BYTE* data, size_t dataSize)
119 size_t oldsize=size();
120 resize(oldsize+dataSize);
121 memcpy(&*(begin()+oldsize),data,dataSize);
122 return 0;
125 typedef std::vector<CString> STRING_VECTOR;
126 typedef std::map<CGitHash, STRING_VECTOR> MAP_HASH_NAME;
127 typedef CGitByteArray BYTE_VECTOR;