Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/installer/mini_installer/mini_string.h

Issue 821673004: replace COMPILE_ASSERT with static_assert in chrome/installer/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/installer/setup/setup_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_INSTALLER_MINI_INSTALLER_MINI_STRING_H_ 5 #ifndef CHROME_INSTALLER_MINI_INSTALLER_MINI_STRING_H_
6 #define CHROME_INSTALLER_MINI_INSTALLER_MINI_STRING_H_ 6 #define CHROME_INSTALLER_MINI_INSTALLER_MINI_STRING_H_
7 7
8 #ifndef COMPILE_ASSERT
9 // COMPILE_ASSERT macro borrowed from basictypes.h
10 template <bool>
11 struct CompileAssert {};
12 #define COMPILE_ASSERT(expr, msg) \
13 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
14 #endif
15 8
16 namespace mini_installer { 9 namespace mini_installer {
17 10
18 // NOTE: Do not assume that these string functions support UTF encoding. 11 // NOTE: Do not assume that these string functions support UTF encoding.
19 // This is fine for the purposes of the mini_installer, but you have 12 // This is fine for the purposes of the mini_installer, but you have
20 // been warned! 13 // been warned!
21 14
22 // Formats a sequence of |bytes| as hex. The |str| buffer must have room for 15 // Formats a sequence of |bytes| as hex. The |str| buffer must have room for
23 // at least 2*|size| + 1. 16 // at least 2*|size| + 1.
24 bool HexEncode(const void* bytes, size_t size, wchar_t* str, size_t str_size); 17 bool HexEncode(const void* bytes, size_t size, wchar_t* str, size_t str_size);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // terminator. 58 // terminator.
66 wchar_t* GetNameFromPathExt(wchar_t* path, size_t size); 59 wchar_t* GetNameFromPathExt(wchar_t* path, size_t size);
67 60
68 // A string class that manages a fixed size buffer on the stack. 61 // A string class that manages a fixed size buffer on the stack.
69 // The methods in the class are based on the above string methods and the 62 // The methods in the class are based on the above string methods and the
70 // class additionally is careful about proper buffer termination. 63 // class additionally is careful about proper buffer termination.
71 template <size_t kCapacity> 64 template <size_t kCapacity>
72 class StackString { 65 class StackString {
73 public: 66 public:
74 StackString() { 67 StackString() {
75 COMPILE_ASSERT(kCapacity != 0, invalid_buffer_size); 68 static_assert(kCapacity != 0, "invalid buffer size");
76 buffer_[kCapacity] = L'\0'; // We always reserve 1 more than asked for. 69 buffer_[kCapacity] = L'\0'; // We always reserve 1 more than asked for.
77 clear(); 70 clear();
78 } 71 }
79 72
80 // We do not expose a constructor that accepts a string pointer on purpose. 73 // We do not expose a constructor that accepts a string pointer on purpose.
81 // We expect the caller to call assign() and handle failures. 74 // We expect the caller to call assign() and handle failures.
82 75
83 // Returns the number of reserved characters in this buffer, _including_ 76 // Returns the number of reserved characters in this buffer, _including_
84 // the reserved char for the terminator. 77 // the reserved char for the terminator.
85 size_t capacity() const { 78 size_t capacity() const {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 wchar_t buffer_[kCapacity + 1]; 130 wchar_t buffer_[kCapacity + 1];
138 131
139 private: 132 private:
140 StackString(const StackString&); 133 StackString(const StackString&);
141 StackString& operator=(const StackString&); 134 StackString& operator=(const StackString&);
142 }; 135 };
143 136
144 } // namespace mini_installer 137 } // namespace mini_installer
145 138
146 #endif // CHROME_INSTALLER_MINI_INSTALLER_MINI_STRING_H_ 139 #endif // CHROME_INSTALLER_MINI_INSTALLER_MINI_STRING_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/setup/setup_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698