digiKam
error.h
Go to the documentation of this file.
1 /*
2  * HEIF codec.
3  * Copyright (c) 2017 struktur AG, Dirk Farin <farin@struktur.de>
4  *
5  * This file is part of libheif.
6  *
7  * libheif is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * libheif is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with libheif. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef LIBHEIF_ERROR_H
22 #define LIBHEIF_ERROR_H
23 
24 #if defined(HAVE_CONFIG_H)
25 #include "config.h"
26 #endif
27 
28 #include <cinttypes>
29 #include <cstddef>
30 
31 #include <vector>
32 #include <string>
33 #include <memory>
34 #include <limits>
35 #include <istream>
36 #include <ostream>
37 #include <sstream>
38 
39 
40 #include "heif.h"
41 
42 
43 
44 static constexpr char kSuccess[] = "Success";
45 
46 
47 namespace heif {
48 
50  {
51  public:
53 
54  void set_success() {
55  m_error_message = c_success;
56  }
57 
58  void set_error(std::string err) {
59  m_buffer = err;
60  m_error_message = m_buffer.c_str();
61  }
62 
63  const char* get_error() const {
64  return m_error_message;
65  }
66 
67  private:
68  constexpr static const char* c_success = "Success";
69  std::string m_buffer;
70  const char* m_error_message = c_success;
71  };
72 
73 
74  class Error
75  {
76  public:
79  std::string message;
80 
81  Error();
82 
85  std::string msg="");
86 
87  static Error Ok;
88 
89  static const char kSuccess[];
90 
91  bool operator==(const Error& other) const { return error_code == other.error_code; }
92  bool operator!=(const Error& other) const { return !(*this == other); }
93 
94  operator bool() const { return error_code != heif_error_Ok; }
95 
96  static const char* get_error_string(heif_error_code err);
97  static const char* get_error_string(heif_suberror_code err);
98 
99  heif_error error_struct(ErrorBuffer* error_buffer) const;
100  };
101 
102 
103  inline std::ostream& operator<<(std::ostream& ostr, const Error& err) {
104  ostr << err.error_code << "/" << err.sub_error_code;
105  return ostr;
106  }
107 }
108 
109 #endif
Definition: error.h:50
void set_error(std::string err)
Definition: error.h:58
ErrorBuffer()
Definition: error.h:52
const char * get_error() const
Definition: error.h:63
void set_success()
Definition: error.h:54
Definition: error.h:75
enum heif_error_code error_code
Definition: error.h:77
static const char kSuccess[]
Definition: error.h:89
static const char * get_error_string(heif_suberror_code err)
static Error Ok
Definition: error.h:87
bool operator!=(const Error &other) const
Definition: error.h:92
static const char * get_error_string(heif_error_code err)
std::string message
Definition: error.h:79
bool operator==(const Error &other) const
Definition: error.h:91
Error(heif_error_code c, heif_suberror_code sc=heif_suberror_Unspecified, std::string msg="")
enum heif_suberror_code sub_error_code
Definition: error.h:78
heif_error error_struct(ErrorBuffer *error_buffer) const
heif_suberror_code
Definition: heif.h:124
@ heif_suberror_Unspecified
Definition: heif.h:126
heif_error_code
Definition: heif.h:91
@ heif_error_Ok
Definition: heif.h:93
Definition: bitstream.h:41
std::ostream & operator<<(std::ostream &ostr, const Error &err)
Definition: error.h:103
Definition: heif.h:264