Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / Git / gittype.h
blobd3684f5bfad53dca698a471437bfae3fdba0c2e8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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"
22 #include <unordered_map>
24 enum
26 TGIT_GIT_SUCCESS=0,
27 TGIT_GIT_ERROR_OPEN_PIP,
28 TGIT_GIT_ERROR_CREATE_PROCESS,
29 TGIT_GIT_ERROR_GET_EXIT_CODE
32 class CGitByteArray:public std::vector<BYTE>
34 public:
35 size_t find(BYTE data, size_t start = 0) const
37 for (size_t i = start, end = size(); i < end; ++i)
38 if ((*this)[i] == data)
39 return i;
40 return npos;
42 size_t RevertFind(BYTE data, size_t start = npos) const
44 if (start == npos)
46 if (empty())
47 return npos;
48 start = size() - 1;
51 for (size_t i = start + 1; i-- > 0;)
52 if ((*this)[i] == data)
53 return i;
54 return npos;
56 size_t findNextString(size_t start = 0) const
58 size_t pos = start;
59 size_t end = size();
62 pos=find(0,pos);
63 if(pos != npos)
64 ++pos;
65 else
66 break;
68 if (pos >= end)
69 return npos;
71 }while(at(pos)==0);
73 return pos;
75 size_t append(std::vector<BYTE> &v, size_t start = 0, size_t end = npos)
77 if (end == npos)
78 end = v.size();
79 for (size_t i = start; i < end; ++i)
80 this->push_back(v[i]);
81 return 0;
83 void append(const BYTE* data, size_t dataSize)
85 if (dataSize == 0)
86 return;
87 size_t oldsize=size();
88 resize(oldsize+dataSize);
89 memcpy(&*(begin()+oldsize),data,dataSize);
91 static const size_t npos = (size_t)-1; // bad/missing length/position
92 static_assert(MAXSIZE_T == npos, "NPOS must equal MAXSIZE_T");
93 #pragma warning(push)
94 #pragma warning(disable: 4310)
95 static_assert(-1 == (int)npos, "NPOS must equal -1");
96 #pragma warning(pop)
99 class CGitGuardedByteArray : public CGitByteArray
101 private:
102 CGitGuardedByteArray(const CGitGuardedByteArray&) = delete;
103 CGitGuardedByteArray& operator=(const CGitGuardedByteArray&) = delete;
104 public:
105 CGitGuardedByteArray() { m_critSec.Init(); }
106 ~CGitGuardedByteArray() { m_critSec.Term(); }
107 CComCriticalSection m_critSec;
110 struct TGitRef
112 CString name;
113 CGitHash hash;
114 operator const CString&() const { return name; }
117 typedef std::vector<CString> STRING_VECTOR;
118 typedef std::unordered_map<CGitHash, STRING_VECTOR> MAP_HASH_NAME;
119 typedef std::map<CString, CString> MAP_STRING_STRING;
120 typedef std::vector<TGitRef> REF_VECTOR;
121 typedef CGitByteArray BYTE_VECTOR;