1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5
6
7#ifndef _StringCopyHolder_h_
8#define _StringCopyHolder_h_
9
10
11//-----------------------------------------------------------------------------
12// Simple holder to keep a copy of a string.
13// Implements IStringHolder so we can pass instances through IDacDbiInterface
14// and have it fill in the contents.
15//-----------------------------------------------------------------------------
16class StringCopyHolder : public IDacDbiInterface::IStringHolder
17{
18public:
19 StringCopyHolder();
20
21 // Free the memory allocated for the string contents
22 ~StringCopyHolder();
23
24 // Make a copy of the provided null-terminated unicode string
25 virtual HRESULT AssignCopy(const WCHAR * pCopy);
26
27 // Reset the string to NULL and free memory
28 void Clear();
29
30 // Returns true if the string has been set to a non-NULL value
31 bool IsSet()
32 {
33 return (m_szData != NULL);
34 }
35
36 // Returns true if an empty string is stored. IsSet must be true to call this.
37 bool IsEmpty()
38 {
39 _ASSERTE(m_szData != NULL);
40 return m_szData[0] == W('\0');
41 }
42
43 // Returns the pointer to the string contents
44 operator WCHAR* () const
45 {
46 return m_szData;
47 }
48
49private:
50 // Disallow copying (to prevent double-free) - no implementation
51 StringCopyHolder( const StringCopyHolder& rhs );
52 StringCopyHolder& operator=( const StringCopyHolder& rhs );
53
54 WCHAR * m_szData;
55
56};
57
58
59#endif // StringCopyHolder
60