Loading...
Searching...
No Matches
image_int.hpp
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef IMAGE_INT_HPP_
#define IMAGE_INT_HPP_
// *****************************************************************************
// included header files
#include "slice.hpp" // for Slice
#include <cstddef> // for size_t
#include <cstdint> // for int32_t
#include <ostream> // for ostream, basic_ostream::put
#include <string>
#if defined(__MINGW32__)
#define ATTRIBUTE_FORMAT_PRINTF __attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2)))
#elif defined(__GNUC__)
#define ATTRIBUTE_FORMAT_PRINTF __attribute__((format(printf, 1, 2)))
#else
#define ATTRIBUTE_FORMAT_PRINTF
#endif
// *****************************************************************************
// namespace extensions
namespace Exiv2::Internal {
// *****************************************************************************
// class definitions
std::string stringFormat(const char* format, ...) ATTRIBUTE_FORMAT_PRINTF;
template <typename T>
struct binaryToStringHelper;
template <typename T>
std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper<T>& binToStr) {
for (size_t i = 0; i < binToStr.buf_.size(); ++i) {
auto c = static_cast<int>(binToStr.buf_.at(i));
const bool bTrailingNull = c == 0 && i == binToStr.buf_.size() - 1;
if (!bTrailingNull) {
if (c < ' ' || c >= 127) {
c = '.';
}
stream.put(static_cast<char>(c));
}
}
return stream;
}
template <typename T>
struct binaryToStringHelper {
constexpr binaryToStringHelper(Slice<T>&& myBuf) noexcept : buf_(std::move(myBuf)) {
}
// the Slice is stored by value to avoid dangling references, in case we
// invoke:
// binaryToString(makeSlice(buf, 0, n));
// <- buf_ would be now dangling, were it a reference
Slice<T> buf_;
};
template <typename T>
constexpr binaryToStringHelper<T> binaryToString(Slice<T>&& sl) noexcept {
return binaryToStringHelper<T>(std::move(sl));
}
std::string indent(size_t i);
} // namespace Exiv2::Internal
#endif // #ifndef IMAGE_INT_HPP_
Exiv2::Internal
Helper structure for the Matroska tags lookup table.
Definition matroskavideo.hpp:39
Exiv2::Internal::binaryToString
constexpr binaryToStringHelper< T > binaryToString(Slice< T > &&sl) noexcept
format binary data for display in Image::printStructure()
Definition image_int.hpp:98
Exiv2::Internal::indent
std::string indent(size_t i)
indent output for kpsRecursive in printStructure() .
Definition image_int.cpp:38
Exiv2::Internal::stringFormat
std::string stringFormat(const char *format,...)
format a string in the pattern of sprintf .
Definition image_int.cpp:12
Exiv2::Internal::binaryToStringHelper
Helper struct for binary data output via binaryToString.
Definition image_int.hpp:66
Exiv2::Slice
Slice (= view) for STL containers.
Definition slice.hpp:421