| Exiv2

Loading...
Searching...
No Matches
image_int.hpp
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#ifndef IMAGE_INT_HPP_
4#define IMAGE_INT_HPP_
5
6// *****************************************************************************
7// included header files
8#include "slice.hpp" // for Slice
9
10#include <cstddef> // for size_t
11#include <cstdint> // for int32_t
12#include <ostream> // for ostream, basic_ostream::put
13#include <string>
14
15#if defined(__MINGW32__)
16#define ATTRIBUTE_FORMAT_PRINTF __attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2)))
17#elif defined(__GNUC__)
18#define ATTRIBUTE_FORMAT_PRINTF __attribute__((format(printf, 1, 2)))
19#else
20#define ATTRIBUTE_FORMAT_PRINTF
21#endif
22
23// *****************************************************************************
24// namespace extensions
25 namespace Exiv2::Internal {
26// *****************************************************************************
27// class definitions
28
32std::string stringFormat(const char* format, ...) ATTRIBUTE_FORMAT_PRINTF;
33
41template <typename T>
42struct binaryToStringHelper;
43
50template <typename T>
51std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper<T>& binToStr) {
52 for (size_t i = 0; i < binToStr.buf_.size(); ++i) {
53 auto c = static_cast<int>(binToStr.buf_.at(i));
54 const bool bTrailingNull = c == 0 && i == binToStr.buf_.size() - 1;
55 if (!bTrailingNull) {
56 if (c < ' ' || c >= 127) {
57 c = '.';
58 }
59 stream.put(static_cast<char>(c));
60 }
61 }
62 return stream;
63}
64
65 template <typename T>
66 struct binaryToStringHelper {
67 constexpr binaryToStringHelper(Slice<T>&& myBuf) noexcept : buf_(std::move(myBuf)) {
68 }
69
70 // the Slice is stored by value to avoid dangling references, in case we
71 // invoke:
72 // binaryToString(makeSlice(buf, 0, n));
73 // <- buf_ would be now dangling, were it a reference
74 Slice<T> buf_;
75};
76
97 template <typename T>
98 constexpr binaryToStringHelper<T> binaryToString(Slice<T>&& sl) noexcept {
99 return binaryToStringHelper<T>(std::move(sl));
100}
101
103std::string indent(size_t i);
104
105} // namespace Exiv2::Internal
106
107#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