Provide (experimental) clang-format file
[TortoiseGit.git] / src / TortoiseProc / BstrSafeVector.h
blobde2d96e2742ae6210286d2b386b7c38dd3387681
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2010 - TortoiseSVN
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.
19 #pragma once
21 class CBstrSafeVector {
22 public:
23 CBstrSafeVector() : controlled(nullptr) {}
24 CBstrSafeVector( ULONG count );
25 ~CBstrSafeVector() { release(); }
27 const SAFEARRAY* operator ->() { return controlled; }
28 operator SAFEARRAY*() { return controlled; }
29 operator const SAFEARRAY*() const { return controlled; }
31 SAFEARRAY** operator&();
33 HRESULT PutElement( LONG index, const CString& value );
35 private:
36 SAFEARRAY* controlled;
38 void release();
41 inline CBstrSafeVector::CBstrSafeVector( ULONG count )
43 controlled = SafeArrayCreateVector(VT_BSTR, 0, count);
46 inline SAFEARRAY** CBstrSafeVector::operator&()
48 release();
49 return &controlled;
52 inline HRESULT CBstrSafeVector::PutElement( LONG index, const CString& value )
54 ATL::CComBSTR valueBstr;
55 valueBstr.Attach( value.AllocSysString() );
56 return SafeArrayPutElement(controlled, &index, valueBstr);
59 inline void CBstrSafeVector::release()
61 if (!controlled)
62 return;
63 SafeArrayDestroy(controlled);
64 controlled = 0;