Exiv2
image_int.hpp
1// ***************************************************************** -*- C++ -*-
2/*
3 * Copyright (C) 2004-2021 Exiv2 authors
4 * This program is part of the Exiv2 distribution.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19 */
20#ifndef IMAGE_INT_HPP_
21#define IMAGE_INT_HPP_
22
23// *****************************************************************************
24// included header files
25#include "types.hpp"
26
27// + standard includes
28#include <string>
29
30#if (defined(__GNUG__) || defined(__GNUC__)) || defined(__clang__)
31#define ATTRIBUTE_FORMAT_PRINTF __attribute__((format(printf, 1, 0)))
32#else
33#define ATTRIBUTE_FORMAT_PRINTF
34#endif
35
36// *****************************************************************************
37// namespace extensions
38namespace Exiv2 {
39 namespace Internal {
40
41// *****************************************************************************
42// class definitions
43
47 std::string stringFormat(const char* format, ...) ATTRIBUTE_FORMAT_PRINTF;
48
56 template <typename T>
57 struct binaryToStringHelper;
58
65 template <typename T>
66 std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper<T>& binToStr)
67 {
68 for (size_t i = 0; i < binToStr.buf_.size(); ++i) {
69 int c = static_cast<int>(binToStr.buf_.at(i));
70 const bool bTrailingNull = c == 0 && i == binToStr.buf_.size() - 1;
71 if (!bTrailingNull) {
72 if (c < ' ' || c >= 127) {
73 c = '.';
74 }
75 stream.put(static_cast<char>(c));
76 }
77 }
78 return stream;
79 }
80
81 template <typename T>
83 {
84 explicit binaryToStringHelper(const Slice<T> buf) throw() : buf_(buf)
85 {
86 }
87
88 friend std::ostream& operator<<<T>(std::ostream& stream, const binaryToStringHelper<T>& binToStr);
89
90 // the Slice is stored by value to avoid dangling references, in case we
91 // invoke:
92 // binaryToString(makeSlice(buf, 0, n));
93 // <- buf_ would be now dangling, were it a reference
94 const Slice<T> buf_;
95 };
96
117 template <typename T>
119 {
120 return binaryToStringHelper<T>(sl);
121 }
122
126 std::string binaryToHex(const byte *data, size_t size);
127
131 std::string indent(int32_t depth);
132
133}} // namespace Internal, Exiv2
134
135#endif // #ifndef IMAGE_INT_HPP_
std::string binaryToHex(const byte *data, size_t size)
format binary for display of raw data .
Definition: image_int.cpp:60
std::string indent(int32_t d)
indent output for kpsRecursive in printStructure() .
Definition: image_int.cpp:106
std::string stringFormat(const char *format,...)
format a string in the pattern of sprintf .
Definition: image_int.cpp:32
binaryToStringHelper< T > binaryToString(const Slice< T > sl)
format binary data for display in Image::printStructure()
Definition: image_int.hpp:118
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
Helper struct for binary data output via binaryToString.
Definition: image_int.hpp:83