OpenShot Library | libopenshot-audio 0.2.0
juce_Result.h
1
2/** @weakgroup juce_core-misc
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/**
32 Represents the 'success' or 'failure' of an operation, and holds an associated
33 error message to describe the error when there's a failure.
34
35 E.g.
36 @code
37 Result myOperation()
38 {
39 if (doSomeKindOfFoobar())
40 return Result::ok();
41 else
42 return Result::fail ("foobar didn't work!");
43 }
44
45 const Result result (myOperation());
46
47 if (result.wasOk())
48 {
49 ...it's all good...
50 }
51 else
52 {
53 warnUserAboutFailure ("The foobar operation failed! Error message was: "
54 + result.getErrorMessage());
55 }
56 @endcode
57
58 @tags{Core}
59*/
61{
62public:
63 //==============================================================================
64 /** Creates and returns a 'successful' result. */
65 static Result ok() noexcept { return Result(); }
66
67 /** Creates a 'failure' result.
68 If you pass a blank error message in here, a default "Unknown Error" message
69 will be used instead.
70 */
71 static Result fail (const String& errorMessage) noexcept;
72
73 //==============================================================================
74 /** Returns true if this result indicates a success. */
75 bool wasOk() const noexcept;
76
77 /** Returns true if this result indicates a failure.
78 You can use getErrorMessage() to retrieve the error message associated
79 with the failure.
80 */
81 bool failed() const noexcept;
82
83 /** Returns true if this result indicates a success.
84 This is equivalent to calling wasOk().
85 */
86 operator bool() const noexcept;
87
88 /** Returns true if this result indicates a failure.
89 This is equivalent to calling failed().
90 */
91 bool operator!() const noexcept;
92
93 /** Returns the error message that was set when this result was created.
94 For a successful result, this will be an empty string;
95 */
96 const String& getErrorMessage() const noexcept;
97
98 //==============================================================================
99 Result (const Result&);
100 Result& operator= (const Result&);
101 Result (Result&&) noexcept;
102 Result& operator= (Result&&) noexcept;
103
104 bool operator== (const Result& other) const noexcept;
105 bool operator!= (const Result& other) const noexcept;
106
107private:
108 String errorMessage;
109
110 // The default constructor is not for public use!
111 // Instead, use Result::ok() or Result::fail()
112 Result() noexcept;
113 explicit Result (const String&) noexcept;
114
115 // These casts are private to prevent people trying to use the Result object in numeric contexts
116 operator int() const;
117 operator void*() const;
118};
119
120} // namespace juce
121
122/** @}*/
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
Definition juce_Result.h:61
static Result ok() noexcept
Creates and returns a 'successful' result.
Definition juce_Result.h:65
The JUCE String class!
Definition juce_String.h:43
#define JUCE_API
This macro is added to all JUCE public class declarations.