diff options
Diffstat (limited to 'include/llvm/ObjectYAML/YAML.h')
-rw-r--r-- | include/llvm/ObjectYAML/YAML.h | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/include/llvm/ObjectYAML/YAML.h b/include/llvm/ObjectYAML/YAML.h index 7f6836809b6d9..29151a269df09 100644 --- a/include/llvm/ObjectYAML/YAML.h +++ b/include/llvm/ObjectYAML/YAML.h @@ -10,10 +10,17 @@ #ifndef LLVM_OBJECTYAML_YAML_H #define LLVM_OBJECTYAML_YAML_H +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/YAMLTraits.h" +#include <cstdint> namespace llvm { + +class raw_ostream; + namespace yaml { + /// \brief Specialized YAMLIO scalar type for representing a binary blob. /// /// A typical use case would be to represent the content of a section in a @@ -56,18 +63,20 @@ namespace yaml { /// \endcode class BinaryRef { friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS); + /// \brief Either raw binary data, or a string of hex bytes (must always /// be an even number of characters). ArrayRef<uint8_t> Data; + /// \brief Discriminator between the two states of the `Data` member. - bool DataIsHexString; + bool DataIsHexString = true; public: + BinaryRef() = default; BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), DataIsHexString(false) {} BinaryRef(StringRef Data) - : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()), - DataIsHexString(true) {} - BinaryRef() : DataIsHexString(true) {} + : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()) {} + /// \brief The number of bytes that are represented by this BinaryRef. /// This is the number of bytes that writeAsBinary() will write. ArrayRef<uint8_t>::size_type binary_size() const { @@ -75,9 +84,11 @@ public: return Data.size() / 2; return Data.size(); } + /// \brief Write the contents (regardless of whether it is binary or a /// hex string) as binary to the given raw_ostream. void writeAsBinary(raw_ostream &OS) const; + /// \brief Write the contents (regardless of whether it is binary or a /// hex string) as hex to the given raw_ostream. /// @@ -94,10 +105,13 @@ inline bool operator==(const BinaryRef &LHS, const BinaryRef &RHS) { } template <> struct ScalarTraits<BinaryRef> { - static void output(const BinaryRef &, void *, llvm::raw_ostream &); + static void output(const BinaryRef &, void *, raw_ostream &); static StringRef input(StringRef, void *, BinaryRef &); static bool mustQuote(StringRef S) { return needsQuotes(S); } }; -} -} -#endif + +} // end namespace yaml + +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_YAML_H |