OLD | NEW |
(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_SIMPLE_STRING_DICTIONARY_WRITER_H_ |
| 16 #define CRASHPAD_MINIDUMP_MINIDUMP_SIMPLE_STRING_DICTIONARY_WRITER_H_ |
| 17 |
| 18 #include <sys/types.h> |
| 19 |
| 20 #include <string> |
| 21 #include <map> |
| 22 #include <vector> |
| 23 |
| 24 #include "base/basictypes.h" |
| 25 #include "minidump/minidump_extensions.h" |
| 26 #include "minidump/minidump_string_writer.h" |
| 27 #include "minidump/minidump_writable.h" |
| 28 #include "util/file/file_writer.h" |
| 29 |
| 30 namespace crashpad { |
| 31 |
| 32 //! \brief The writer for a MinidumpSimpleStringDictionaryEntry object in a |
| 33 //! minidump file. |
| 34 //! |
| 35 //! Because MinidumpSimpleStringDictionaryEntry objects only appear as elements |
| 36 //! of MinidumpSimpleStringDictionary objects, this class does not write any |
| 37 //! data on its own. It makes its MinidumpSimpleStringDictionaryEntry data |
| 38 //! available to its MinidumpSimpleStringDictionaryWriter parent, which writes |
| 39 //! it as part of a MinidumpSimpleStringDictionary. |
| 40 class MinidumpSimpleStringDictionaryEntryWriter final |
| 41 : public internal::MinidumpWritable { |
| 42 public: |
| 43 MinidumpSimpleStringDictionaryEntryWriter(); |
| 44 ~MinidumpSimpleStringDictionaryEntryWriter(); |
| 45 |
| 46 //! \brief Returns a MinidumpSimpleStringDictionaryEntry referencing this |
| 47 //! object’s data. |
| 48 //! |
| 49 //! This method is expected to be called by a |
| 50 //! MinidumpSimpleStringDictionaryWriter in order to obtain a |
| 51 //! MinidumpSimpleStringDictionaryEntry to include in its list. |
| 52 //! |
| 53 //! \note Valid in #kStateWritable. |
| 54 const MinidumpSimpleStringDictionaryEntry* |
| 55 MinidumpSimpleStringDictionaryEntry() const; |
| 56 |
| 57 //! \brief Sets the strings to be written as the entry object’s key and value. |
| 58 //! |
| 59 //! \note Valid in #kStateMutable. |
| 60 void SetKeyValue(const std::string& key, const std::string& value); |
| 61 |
| 62 //! \brief Retrieves the key to be written. |
| 63 //! |
| 64 //! \note Valid in any state. |
| 65 const std::string& Key() const { return key_.UTF8(); } |
| 66 |
| 67 protected: |
| 68 // MinidumpWritable: |
| 69 |
| 70 bool Freeze() override; |
| 71 size_t SizeOfObject() override; |
| 72 std::vector<MinidumpWritable*> Children() override; |
| 73 bool WriteObject(FileWriterInterface* file_writer) override; |
| 74 |
| 75 private: |
| 76 struct MinidumpSimpleStringDictionaryEntry entry_; |
| 77 internal::MinidumpUTF8StringWriter key_; |
| 78 internal::MinidumpUTF8StringWriter value_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(MinidumpSimpleStringDictionaryEntryWriter); |
| 81 }; |
| 82 |
| 83 //! \brief The writer for a MinidumpSimpleStringDictionary object in a minidump |
| 84 //! file, containing a list of MinidumpSimpleStringDictionaryEntry objects. |
| 85 //! |
| 86 //! Because this class writes a representatin of a dictionary, the order of |
| 87 //! entries is insignificant. Entries may be written in any order. |
| 88 class MinidumpSimpleStringDictionaryWriter final |
| 89 : public internal::MinidumpWritable { |
| 90 public: |
| 91 MinidumpSimpleStringDictionaryWriter(); |
| 92 ~MinidumpSimpleStringDictionaryWriter(); |
| 93 |
| 94 //! \brief Adds a MinidumpSimpleStringDictionaryEntryWriter to the |
| 95 //! MinidumpSimpleStringDictionary. |
| 96 //! |
| 97 //! \a entry will become a child of this object in the overall tree of |
| 98 //! internal::MinidumpWritable objects. |
| 99 //! |
| 100 //! If the key contained in \a entry duplicates the key of an entry already |
| 101 //! present in the MinidumpSimpleStringDictionary, the new \a entry will |
| 102 //! replace the previous one. |
| 103 //! |
| 104 //! \note Valid in #kStateMutable. |
| 105 void AddEntry(MinidumpSimpleStringDictionaryEntryWriter* entry); |
| 106 |
| 107 protected: |
| 108 // MinidumpWritable: |
| 109 |
| 110 bool Freeze() override; |
| 111 size_t SizeOfObject() override; |
| 112 std::vector<MinidumpWritable*> Children() override; |
| 113 bool WriteObject(FileWriterInterface* file_writer) override; |
| 114 |
| 115 private: |
| 116 MinidumpSimpleStringDictionary simple_string_dictionary_base_; |
| 117 std::map<std::string, MinidumpSimpleStringDictionaryEntryWriter*> |
| 118 entries_; // weak |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(MinidumpSimpleStringDictionaryWriter); |
| 121 }; |
| 122 |
| 123 } // namespace crashpad |
| 124 |
| 125 #endif // CRASHPAD_MINIDUMP_MINIDUMP_SIMPLE_STRING_DICTIONARY_WRITER_H_ |
OLD | NEW |