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

Side by Side Diff: minidump/minidump_string_writer.h

Issue 431363002: Introduce MinidumpStringWriter and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase Created 6 years, 4 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 | « minidump/minidump.gyp ('k') | minidump/minidump_string_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_STRING_WRITER_H_
16 #define CRASHPAD_MINIDUMP_MINIDUMP_STRING_WRITER_H_
17
18 #include <dbghelp.h>
19 #include <stdint.h>
20 #include <sys/types.h>
21
22 #include <string>
23
24 #include "base/basictypes.h"
25 #include "base/strings/string16.h"
26 #include "minidump/minidump_extensions.h"
27 #include "minidump/minidump_writable.h"
28 #include "util/file/file_writer.h"
29
30 namespace crashpad {
31 namespace internal {
32
33 //! \cond
34
35 struct MinidumpStringWriterUTF16Traits {
36 typedef string16 StringType;
37 typedef MINIDUMP_STRING MinidumpStringType;
38 };
39
40 struct MinidumpStringWriterUTF8Traits {
41 typedef std::string StringType;
42 typedef MinidumpUTF8String MinidumpStringType;
43 };
44
45 //! \endcond
46
47 //! \brief Writes a variable-length string to a minidump file in accordance with
48 //! the string type’s characteristics.
49 //!
50 //! MinidumpStringWriter objects should not be instantiated directly. To write
51 //! strings to minidump file, use the MinidumpUTF16StringWriter and
52 //! MinidumpUTF8StringWriter subclasses instead.
53 template <typename Traits>
54 class MinidumpStringWriter : public MinidumpWritable {
55 public:
56 MinidumpStringWriter();
57 ~MinidumpStringWriter();
58
59 protected:
60 typedef typename Traits::MinidumpStringType MinidumpStringType;
61 typedef typename Traits::StringType StringType;
62
63 virtual bool Freeze() override;
64 virtual size_t SizeOfObject() override;
65 virtual bool WriteObject(FileWriterInterface* file_writer) override;
66
67 //! \brief Sets the string to be written.
68 //!
69 //! \note Valid in #kStateMutable.
70 void set_string(const StringType& string) { string_.assign(string); }
71
72 private:
73 MinidumpStringType string_base_;
74 StringType string_;
75
76 DISALLOW_COPY_AND_ASSIGN(MinidumpStringWriter);
77 };
78
79 //! \brief Writes a variable-length UTF-16-encoded MINIDUMP_STRING to a minidump
80 //! file.
81 //!
82 //! MinidumpUTF16StringWriter objects should not be instantiated directly
83 //! outside of the MinidumpWritable family of classes.
84 class MinidumpUTF16StringWriter final
85 : public MinidumpStringWriter<MinidumpStringWriterUTF16Traits> {
86 public:
87 MinidumpUTF16StringWriter() : MinidumpStringWriter() {}
88 ~MinidumpUTF16StringWriter() {}
89
90 //! \brief Converts a UTF-8 string to UTF-16 and sets it as the string to be
91 //! written.
92 //!
93 //! \note Valid in #kStateMutable.
94 void SetUTF8(const std::string& string_utf8);
95
96 private:
97 DISALLOW_COPY_AND_ASSIGN(MinidumpUTF16StringWriter);
98 };
99
100 //! \brief Writes a variable-length UTF-8-encoded MinidumpUTF8String to a
101 //! minidump file.
102 //!
103 //! MinidumpUTF8StringWriter objects should not be instantiated directly outside
104 //! of the MinidumpWritable family of classes.
105 class MinidumpUTF8StringWriter final
106 : public MinidumpStringWriter<MinidumpStringWriterUTF8Traits> {
107 public:
108 MinidumpUTF8StringWriter() : MinidumpStringWriter() {}
109 ~MinidumpUTF8StringWriter() {}
110
111 //! \brief Sets the string to be written.
112 //!
113 //! \note Valid in #kStateMutable.
114 void SetUTF8(const std::string& string_utf8) { set_string(string_utf8); }
115
116 private:
117 DISALLOW_COPY_AND_ASSIGN(MinidumpUTF8StringWriter);
118 };
119
120 } // namespace internal
121 } // namespace crashpad
122
123 #endif // CRASHPAD_MINIDUMP_MINIDUMP_STRING_WRITER_H_
OLDNEW
« no previous file with comments | « minidump/minidump.gyp ('k') | minidump/minidump_string_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698