status.cc
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 #include "util/status.h"
28 
29 #include <cstdio>
30 #include <ostream>
31 #include <string>
32 #include <utility>
33 
34 namespace util {
35 namespace error {
36 inline std::string CodeEnumToString(Code code) {
37  switch (code) {
38  case OK:
39  return "OK";
40  case CANCELLED:
41  return "CANCELLED";
42  case UNKNOWN:
43  return "UNKNOWN";
44  case INVALID_ARGUMENT:
45  return "INVALID_ARGUMENT";
46  case DEADLINE_EXCEEDED:
47  return "DEADLINE_EXCEEDED";
48  case NOT_FOUND:
49  return "NOT_FOUND";
50  case ALREADY_EXISTS:
51  return "ALREADY_EXISTS";
52  case PERMISSION_DENIED:
53  return "PERMISSION_DENIED";
54  case UNAUTHENTICATED:
55  return "UNAUTHENTICATED";
56  case RESOURCE_EXHAUSTED:
57  return "RESOURCE_EXHAUSTED";
59  return "FAILED_PRECONDITION";
60  case ABORTED:
61  return "ABORTED";
62  case OUT_OF_RANGE:
63  return "OUT_OF_RANGE";
64  case UNIMPLEMENTED:
65  return "UNIMPLEMENTED";
66  case INTERNAL:
67  return "INTERNAL";
68  case UNAVAILABLE:
69  return "UNAVAILABLE";
70  case DATA_LOSS:
71  return "DATA_LOSS";
72  }
73 
74  // No default clause, clang will abort if a code is missing from
75  // above switch.
76  return "UNKNOWN";
77 }
78 } // namespace error.
79 
80 const Status Status::OK = Status();
83 
84 Status::Status() : error_code_(error::OK) {
85 }
86 
88  : error_code_(error_code) {
89  if (error_code != error::OK) {
91  }
92 }
93 
94 Status::Status(const Status& other)
96 }
97 
99  error_code_ = other.error_code_;
101  return *this;
102 }
103 
104 bool Status::operator==(const Status& x) const {
105  return error_code_ == x.error_code_ &&
107 }
108 
109 std::string Status::ToString() const {
110  if (error_code_ == error::OK) {
111  return "OK";
112  } else {
113  if (error_message_.empty()) {
115  } else {
116  return error::CodeEnumToString(error_code_) + ":" +
118  }
119  }
120 }
121 
122 std::ostream& operator<<(std::ostream& os, const Status& x) {
123  os << x.ToString();
124  return os;
125 }
126 
127 } // namespace util
128 
129 
130 // Protocol Buffers - Google's data interchange format
131 // Copyright 2008 Google Inc. All rights reserved.
132 // https://developers.google.com/protocol-buffers/
133 //
134 // Redistribution and use in source and binary forms, with or without
135 // modification, are permitted provided that the following conditions are
136 // met:
137 //
138 // * Redistributions of source code must retain the above copyright
139 // notice, this list of conditions and the following disclaimer.
140 // * Redistributions in binary form must reproduce the above
141 // copyright notice, this list of conditions and the following disclaimer
142 // in the documentation and/or other materials provided with the
143 // distribution.
144 // * Neither the name of Google Inc. nor the names of its
145 // contributors may be used to endorse or promote products derived from
146 // this software without specific prior written permission.
147 //
148 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
149 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
150 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
151 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
152 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
153 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
154 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
155 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
156 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
157 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
158 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static const Status OK
Definition: status.h:74
static const Status UNKNOWN
Definition: status.h:76
std::string error_message() const
Definition: status.h:85
error::Code error_code_
Definition: status.h:98
std::string ToString() const
Definition: status.cc:109
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.cc:104
std::string error_message_
Definition: status.h:99
Status & operator=(const Status &x)
Definition: status.cc:98
std::string CodeEnumToString(Code code)
Definition: status.cc:36


gcloud_speech
Author(s):
autogenerated on Mon Jun 10 2019 13:20:53