Exiv2
image_int.hpp
Go to the documentation of this file.
1 // ***************************************************************** -*- C++ -*-
2 /*
3  * Copyright (C) 2004-2018 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  */
27 #ifndef IMAGE_INT_HPP_
28 #define IMAGE_INT_HPP_
29 
30 // *****************************************************************************
31 // included header files
32 #include "types.hpp"
33 
34 // + standard includes
35 #include <string>
36 
37 #if (defined(__GNUG__) || defined(__GNUC__)) || defined(__clang__)
38 #define ATTRIBUTE_FORMAT_PRINTF __attribute__((format(printf, 1, 0)))
39 #else
40 #define ATTRIBUTE_FORMAT_PRINTF
41 #endif
42 
43 // *****************************************************************************
44 // namespace extensions
45 namespace Exiv2 {
46  namespace Internal {
47 
48 // *****************************************************************************
49 // class definitions
50 
54  std::string stringFormat(const char* format, ...) ATTRIBUTE_FORMAT_PRINTF;
55 
63  template <typename T>
65 
72  template <typename T>
73  std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper<T>& binToStr)
74  {
75  for (size_t i = 0; i < binToStr.buf_.size(); ++i) {
76  int c = static_cast<int>(binToStr.buf_.at(i));
77  const bool bTrailingNull = c == 0 && i == binToStr.buf_.size() - 1;
78  if (!bTrailingNull) {
79  if (c < ' ' || c >= 127) {
80  c = '.';
81  }
82  stream.put(static_cast<char>(c));
83  }
84  }
85  return stream;
86  }
87 
88  template <typename T>
90  {
91  explicit binaryToStringHelper(const Slice<T> buf) throw() : buf_(buf)
92  {
93  }
94 
95  friend std::ostream& operator<<<T>(std::ostream& stream, const binaryToStringHelper<T>& binToStr);
96 
97  // the Slice is stored by value to avoid dangling references, in case we
98  // invoke:
99  // binaryToString(makeSlice(buf, 0, n));
100  // <- buf_ would be now dangling, were it a reference
101  const Slice<T> buf_;
102  };
103 
124  template <typename T>
126  {
127  return binaryToStringHelper<T>(sl);
128  }
129 
133  std::string binaryToHex(const byte *data, size_t size);
134 
138  std::string indent(int32_t depth);
139 
140 }} // namespace Internal, Exiv2
141 
142 #endif // #ifndef IMAGE_INT_HPP_
std::string stringFormat(const char *format,...)
format a string in the pattern of sprintf .
Definition: image_int.cpp:32
STL namespace.
uint8_t byte
1 byte unsigned integer type.
Definition: types.hpp:105
Type definitions for Exiv2 and related functionality.
binaryToStringHelper< T > binaryToString(const Slice< T > sl)
format binary data for display in Image::printStructure()
Definition: image_int.hpp:125
IPTC string type.
Definition: types.hpp:147
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:64
std::string indent(int32_t d)
indent output for kpsRecursive in printStructure() .
Definition: image_int.cpp:106
std::string binaryToHex(const byte *data, size_t size)
format binary for display of raw data .
Definition: image_int.cpp:60