diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/soundlib/Message.h | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/soundlib/Message.h')
-rw-r--r-- | Src/external_dependencies/openmpt-trunk/soundlib/Message.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Src/external_dependencies/openmpt-trunk/soundlib/Message.h b/Src/external_dependencies/openmpt-trunk/soundlib/Message.h new file mode 100644 index 00000000..76c98db0 --- /dev/null +++ b/Src/external_dependencies/openmpt-trunk/soundlib/Message.h @@ -0,0 +1,71 @@ +/* + * Message.h + * --------- + * Purpose: Various functions for processing song messages (allocating, reading from file...) + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + +#include "openmpt/all/BuildSettings.hpp" + +#include <string> + +#include "../common/FileReaderFwd.h" + +OPENMPT_NAMESPACE_BEGIN + +class SongMessage : public std::string +{ +public: + + // Line ending types (for reading song messages from module files) + enum LineEnding + { + leCR, // Carriage Return (0x0D, \r) + leLF, // Line Feed (0x0A \n) + leCRLF, // Carriage Return, Line Feed (0x0D0A, \r\n) + leMixed, // It is not defined whether Carriage Return or Line Feed is the actual line ending. Both are accepted. + leAutodetect, // Detect suitable line ending + }; + + enum + { + InternalLineEnding = '\r', // The character that represents line endings internally + }; + + // Read song message from a mapped file. + // [in] data: pointer to the data in memory that is going to be read + // [in] length: number of characters that should be read, not including a possible trailing null terminator (it is automatically appended). + // [in] lineEnding: line ending formatting of the text in memory. + // [out] returns true on success. + bool Read(const std::byte *data, const size_t length, LineEnding lineEnding); + bool Read(FileReader &file, const size_t length, LineEnding lineEnding); + + // Read comments with fixed line length from a mapped file. + // [in] data: pointer to the data in memory that is going to be read + // [in] length: number of characters that should be read, not including a possible trailing null terminator (it is automatically appended). + // [in] lineLength: The fixed length of a line. + // [in] lineEndingLength: The padding space between two fixed lines. (there could for example be a null char after every line) + // [out] returns true on success. + bool ReadFixedLineLength(const std::byte *data, const size_t length, const size_t lineLength, const size_t lineEndingLength); + bool ReadFixedLineLength(FileReader &file, const size_t length, const size_t lineLength, const size_t lineEndingLength); + + // Retrieve song message. + // [in] lineEnding: line ending formatting of the text in memory. + // [out] returns formatted song message. + std::string GetFormatted(const LineEnding lineEnding) const; + + // Set song message. + // [in] lineEnding: line ending formatting of the text in memory. Must be leCR or leLF or leCRLF, + // [out] returns true if the message has been changed. + bool SetFormatted(std::string message, LineEnding lineEnding); + + // Sets the song message. Expects the provided string to already use the internal line ending character. + void SetRaw(std::string message) noexcept { assign(std::move(message)); } +}; + +OPENMPT_NAMESPACE_END |