Loading...
Searching...
No Matches
image_int.hpp
// ***************************************************************** -*- C++ -*-
/*
* Copyright (C) 2004-2021 Exiv2 authors
* This program is part of the Exiv2 distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
*/
#ifndef IMAGE_INT_HPP_
#define IMAGE_INT_HPP_
// *****************************************************************************
// included header files
#include "types.hpp"
// + standard includes
#include <string>
#if (defined(__GNUG__) || defined(__GNUC__)) || defined(__clang__)
#define ATTRIBUTE_FORMAT_PRINTF __attribute__((format(printf, 1, 0)))
#else
#define ATTRIBUTE_FORMAT_PRINTF
#endif
// *****************************************************************************
// namespace extensions
namespace Exiv2 {
namespace 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) {
int 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
{
explicit binaryToStringHelper(const Slice<T> buf) throw() : buf_(buf)
{
}
friend std::ostream& operator<<<T>(std::ostream& stream, const binaryToStringHelper<T>& binToStr);
// 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
const Slice<T> buf_;
};
template <typename T>
inline binaryToStringHelper<T> binaryToString(const Slice<T> sl) throw()
{
return binaryToStringHelper<T>(sl);
}
std::string binaryToHex(const byte *data, size_t size);
std::string indent(int32_t depth);
}} // namespace Internal, Exiv2
#endif // #ifndef IMAGE_INT_HPP_
Exiv2::Internal::binaryToHex
std::string binaryToHex(const byte *data, size_t size)
format binary for display of raw data .
Definition image_int.cpp:60
Exiv2::Internal::indent
std::string indent(int32_t d)
indent output for kpsRecursive in printStructure() .
Definition image_int.cpp:106
Exiv2::Internal::stringFormat
std::string stringFormat(const char *format,...)
format a string in the pattern of sprintf .
Definition image_int.cpp:32
Exiv2::Internal::binaryToString
binaryToStringHelper< T > binaryToString(const Slice< T > sl)
format binary data for display in Image::printStructure()
Definition image_int.hpp:118
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition asfvideo.hpp:36
Exiv2::Internal::binaryToStringHelper
Helper struct for binary data output via binaryToString.
Definition image_int.hpp:83
Exiv2::Slice
Slice (= view) for STL containers.
Definition slice.hpp:522