status.h
Go to the documentation of this file.
1 // Copyright (c) 2017, The Regents of the University of California
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of the University of California nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF CALIFORNIA
19 // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
26 
27 // Status is the common return type of our functions.
28 
29 #ifndef UTIL_STATUS_H_
30 #define UTIL_STATUS_H_
31 
32 #include <iosfwd>
33 #include <string>
34 
35 namespace util {
36 
37 namespace error {
38 enum Code {
39  OK = 0,
40  CANCELLED = 1,
41  UNKNOWN = 2,
44  NOT_FOUND = 5,
50  ABORTED = 10,
53  INTERNAL = 13,
55  DATA_LOSS = 15,
56 };
57 } // namespace error
58 
59 class Status {
60  public:
61  // Creates a "successful" status.
62  Status();
63 
64  // Create a status in the canonical error space with the specified
65  // code, and error message. If "code == 0", error_message is
66  // ignored and a Status object identical to Status::OK is
67  // constructed.
68  Status(error::Code error_code, std::string error_message);
69  Status(const Status&);
70  Status& operator=(const Status& x);
71  ~Status() {}
72 
73  // Some pre-defined Status objects
74  static const Status OK; // Identical to 0-arg constructor
75  static const Status CANCELLED;
76  static const Status UNKNOWN;
77 
78  // Accessor
79  bool ok() const {
80  return error_code_ == error::OK;
81  }
82  int error_code() const {
83  return error_code_;
84  }
85  std::string error_message() const {
86  return error_message_;
87  }
88 
89  bool operator==(const Status& x) const;
90  bool operator!=(const Status& x) const {
91  return !operator==(x);
92  }
93 
94  // Return a combination of the error code name and message.
95  std::string ToString() const;
96 
97  private:
99  std::string error_message_;
100 };
101 
102 // Prints a human-readable representation of 'x' to 'os'.
103 std::ostream& operator<<(std::ostream& os, const Status& x);
104 
105 #define EXPECT_OK(value) EXPECT_TRUE((value).ok())
106 #define CHECK_OK(value) CHECK((value).ok())
107 #define DCHECK_OK(value) DCHECK((value).ok())
108 
109 } // namespace util
110 
111 #endif // UTIL_STATUS_H_
112 
113 
114 // Protocol Buffers - Google's data interchange format
115 // Copyright 2008 Google Inc. All rights reserved.
116 // https://developers.google.com/protocol-buffers/
117 //
118 // Redistribution and use in source and binary forms, with or without
119 // modification, are permitted provided that the following conditions are
120 // met:
121 //
122 // * Redistributions of source code must retain the above copyright
123 // notice, this list of conditions and the following disclaimer.
124 // * Redistributions in binary form must reproduce the above
125 // copyright notice, this list of conditions and the following disclaimer
126 // in the documentation and/or other materials provided with the
127 // distribution.
128 // * Neither the name of Google Inc. nor the names of its
129 // contributors may be used to endorse or promote products derived from
130 // this software without specific prior written permission.
131 //
132 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
133 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
134 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
135 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
136 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
137 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
138 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
139 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
140 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
141 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
142 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static const Status OK
Definition: status.h:74
bool ok() const
Definition: status.h:79
static const Status UNKNOWN
Definition: status.h:76
std::string error_message() const
Definition: status.h:85
bool operator==(const in6_addr a, const in6_addr b)
error::Code error_code_
Definition: status.h:98
static const Status CANCELLED
Definition: status.h:75
std::ostream & operator<<(std::ostream &os, const Status &x)
Definition: status.cc:122
int error_code() const
Definition: status.h:82
bool operator!=(const Status &x) const
Definition: status.h:90
std::string error_message_
Definition: status.h:99


gcloud_speech_utils
Author(s):
autogenerated on Wed Jun 5 2019 21:24:09