URY playd
C++ minimalist audio player
errors.hpp
Go to the documentation of this file.
1 // This file is part of playd.
2 // playd is licensed under the MIT licence: see LICENSE.txt.
3 
10 #ifndef PLAYD_ERRORS_HPP
11 #define PLAYD_ERRORS_HPP
12 
13 #include <iostream>
14 #include <sstream>
15 
19 class Error
20 {
21 public:
26  Error(const std::string &msg);
27 
32  const std::string &Message() const;
33 
34 private:
35  std::string message;
36 };
37 
38 //
39 // Error sub-categories
40 //
41 
45 class ConfigError : public Error
46 {
47 public:
52  ConfigError(const std::string &msg) : Error(msg)
53  {
54  }
55 };
56 
60 class InternalError : public Error
61 {
62 public:
67  InternalError(const std::string &msg) : Error(msg)
68  {
69  }
70 };
71 
75 class FileError : public Error
76 {
77 public:
82  FileError(const std::string &msg) : Error(msg)
83  {
84  }
85 };
86 
90 class SeekError : public Error
91 {
92 public:
97  SeekError(const std::string &msg) : Error(msg)
98  {
99  }
100 };
101 
105 class NetError : public Error
106 {
107 public:
112  NetError(const std::string &msg) : Error(msg)
113  {
114  }
115 };
116 
120 class NoAudioError : public Error
121 {
122 public:
127  NoAudioError(const std::string &msg) : Error(msg)
128  {
129  }
130 };
131 
133 class Debug
134 {
135 public:
137  inline Debug()
138  {
139  oss << "DEBUG:";
140  }
141 
143  inline ~Debug()
144  {
145  std::cerr << oss.str();
146  }
147 
154  template <typename T>
155  inline Debug &operator<<(const T &x)
156  {
157  oss << " ";
158  oss << x;
159  return *this;
160  }
161 
167  inline Debug &operator<<(std::ostream &(*pf)(std::ostream &))
168  {
169  oss << pf;
170  return *this;
171  }
172 
173 private:
174  std::ostringstream oss;
175 };
177 
178 #endif // PLAYD_ERRORS_HPP
A playd exception.
Definition: errors.hpp:19
InternalError(const std::string &msg)
Constructs an InternalError.
Definition: errors.hpp:67
NetError(const std::string &msg)
Constructs a NetError.
Definition: errors.hpp:112
NoAudioError(const std::string &msg)
Constructs an NoAudioError.
Definition: errors.hpp:127
std::ostringstream oss
Stream buffer (avoids theoretical threading issues).
Definition: errors.hpp:174
FileError(const std::string &msg)
Constructs a FileError.
Definition: errors.hpp:82
An Error signifying that playd can&#39;t read a file.
Definition: errors.hpp:75
Debug()
Constructor.
Definition: errors.hpp:137
const std::string & Message() const
The human-readable message for this error.
Definition: errors.cpp:16
Error(const std::string &msg)
Constructs an Error.
Definition: errors.cpp:12
Debug & operator<<(std::ostream &(*pf)(std::ostream &))
Specialisation for std::endl, which is actually a function pointer.
Definition: errors.hpp:167
~Debug()
Destructor.
Definition: errors.hpp:143
ConfigError(const std::string &msg)
Constructs an ConfigError.
Definition: errors.hpp:52
An Error signifying that playd has been improperly configured.
Definition: errors.hpp:45
An Error signifying that playd can&#39;t seek in a file.
Definition: errors.hpp:90
Debug & operator<<(const T &x)
Stream operator for shoving objects onto a screen somewhere.
Definition: errors.hpp:155
A network error.
Definition: errors.hpp:105
Class for telling the human what playd is doing.
Definition: errors.hpp:133
An Error signifying that playd has hit an internal snag.
Definition: errors.hpp:60
SeekError(const std::string &msg)
Constructs a SeekError.
Definition: errors.hpp:97
std::string message
The human-readable message for this Error.
Definition: errors.hpp:35
An Error signifying that no audio is loaded.
Definition: errors.hpp:120