summaryrefslogtreecommitdiff
path: root/portaudio/bindings/cpp/source/portaudiocpp/Exception.cxx
blob: 98945c817243ff43aaef65c32219cfbf3251fd7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "portaudiocpp/Exception.hxx"

namespace portaudio
{
	// -----------------------------------------------------------------------------------
	// PaException:
	// -----------------------------------------------------------------------------------

	//////
	///  Wraps a PortAudio error into a PortAudioCpp PaException.
	//////
	PaException::PaException(PaError error) : error_(error)
	{
	}

	// -----------------------------------------------------------------------------------

	//////
	/// Alias for paErrorText(), to have std::exception compliance.
	//////
	const char *PaException::what() const throw()
	{
		return paErrorText();
	}

	// -----------------------------------------------------------------------------------

	//////
	/// Returns the PortAudio error code (PaError).
	//////
	PaError PaException::paError() const
	{
		return error_;
	}

	//////
	/// Returns the error as a (zero-terminated) text string.
	//////
	const char *PaException::paErrorText() const
	{
		return Pa_GetErrorText(error_);
	}

	//////
	/// Returns true is the error is a HostApi error.
	//////
	bool PaException::isHostApiError() const
	{
		return (error_ == paUnanticipatedHostError);
	}

	//////
	/// Returns the last HostApi error (which is the current one if 
	/// isHostApiError() returns true) as an error code.
	//////
	long PaException::lastHostApiError() const
	{
		return Pa_GetLastHostErrorInfo()->errorCode;
	}

	//////
	/// Returns the last HostApi error (which is the current one if 
	/// isHostApiError() returns true) as a (zero-terminated) text 
	/// string, if it's available.
	//////
	const char *PaException::lastHostApiErrorText() const
	{
		return Pa_GetLastHostErrorInfo()->errorText;
	}

	// -----------------------------------------------------------------------------------

	bool PaException::operator==(const PaException &rhs) const
	{
		return (error_ == rhs.error_);
	}

	bool PaException::operator!=(const PaException &rhs) const
	{
		return !(*this == rhs);
	}

	// -----------------------------------------------------------------------------------
	// PaCppException:
	// -----------------------------------------------------------------------------------
	
	PaCppException::PaCppException(ExceptionSpecifier specifier) : specifier_(specifier)
	{
	}

	const char *PaCppException::what() const throw()
	{
		switch (specifier_)
		{
			case UNABLE_TO_ADAPT_DEVICE:
			{
				return "Unable to adapt the given device to the specified host api specific device extension";
			}
		}

		return "Unknown exception";
	}

	PaCppException::ExceptionSpecifier PaCppException::specifier() const
	{
		return specifier_;
	}

	bool PaCppException::operator==(const PaCppException &rhs) const
	{
		return (specifier_ == rhs.specifier_);
	}

	bool PaCppException::operator!=(const PaCppException &rhs) const
	{
		return !(*this == rhs);
	}

	// -----------------------------------------------------------------------------------

} // namespace portaudio