status.h
Go to the documentation of this file.
00001 // Copyright (c) 2017, The Regents of the University of California
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are met:
00006 // * Redistributions of source code must retain the above copyright
00007 //   notice, this list of conditions and the following disclaimer.
00008 // * Redistributions in binary form must reproduce the above copyright
00009 //   notice, this list of conditions and the following disclaimer in the
00010 //   documentation and/or other materials provided with the distribution.
00011 // * Neither the name of the University of California nor the
00012 //   names of its contributors may be used to endorse or promote products
00013 //   derived from this software without specific prior written permission.
00014 //
00015 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00016 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018 // ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF CALIFORNIA
00019 // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00020 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00021 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00024 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00025 // POSSIBILITY OF SUCH DAMAGE.
00026 
00027 // Status is the common return type of our functions.
00028 
00029 #ifndef UTIL_STATUS_H_
00030 #define UTIL_STATUS_H_
00031 
00032 #include <iosfwd>
00033 #include <string>
00034 
00035 namespace util {
00036 
00037 namespace error {
00038 enum Code {
00039   OK = 0,
00040   CANCELLED = 1,
00041   UNKNOWN = 2,
00042   INVALID_ARGUMENT = 3,
00043   DEADLINE_EXCEEDED = 4,
00044   NOT_FOUND = 5,
00045   ALREADY_EXISTS = 6,
00046   PERMISSION_DENIED = 7,
00047   UNAUTHENTICATED = 16,
00048   RESOURCE_EXHAUSTED = 8,
00049   FAILED_PRECONDITION = 9,
00050   ABORTED = 10,
00051   OUT_OF_RANGE = 11,
00052   UNIMPLEMENTED = 12,
00053   INTERNAL = 13,
00054   UNAVAILABLE = 14,
00055   DATA_LOSS = 15,
00056 };
00057 }  // namespace error
00058 
00059 class Status {
00060  public:
00061   // Creates a "successful" status.
00062   Status();
00063 
00064   // Create a status in the canonical error space with the specified
00065   // code, and error message.  If "code == 0", error_message is
00066   // ignored and a Status object identical to Status::OK is
00067   // constructed.
00068   Status(error::Code error_code, std::string error_message);
00069   Status(const Status&);
00070   Status& operator=(const Status& x);
00071   ~Status() {}
00072 
00073   // Some pre-defined Status objects
00074   static const Status OK;             // Identical to 0-arg constructor
00075   static const Status CANCELLED;
00076   static const Status UNKNOWN;
00077 
00078   // Accessor
00079   bool ok() const {
00080     return error_code_ == error::OK;
00081   }
00082   int error_code() const {
00083     return error_code_;
00084   }
00085   std::string error_message() const {
00086     return error_message_;
00087   }
00088 
00089   bool operator==(const Status& x) const;
00090   bool operator!=(const Status& x) const {
00091     return !operator==(x);
00092   }
00093 
00094   // Return a combination of the error code name and message.
00095   std::string ToString() const;
00096 
00097  private:
00098   error::Code error_code_;
00099   std::string error_message_;
00100 };
00101 
00102 // Prints a human-readable representation of 'x' to 'os'.
00103 std::ostream& operator<<(std::ostream& os, const Status& x);
00104 
00105 #define EXPECT_OK(value) EXPECT_TRUE((value).ok())
00106 #define CHECK_OK(value) CHECK((value).ok())
00107 #define DCHECK_OK(value) DCHECK((value).ok())
00108 
00109 }  // namespace util
00110 
00111 #endif  // UTIL_STATUS_H_
00112 
00113 
00114 // Protocol Buffers - Google's data interchange format
00115 // Copyright 2008 Google Inc.  All rights reserved.
00116 // https://developers.google.com/protocol-buffers/
00117 //
00118 // Redistribution and use in source and binary forms, with or without
00119 // modification, are permitted provided that the following conditions are
00120 // met:
00121 //
00122 //     * Redistributions of source code must retain the above copyright
00123 // notice, this list of conditions and the following disclaimer.
00124 //     * Redistributions in binary form must reproduce the above
00125 // copyright notice, this list of conditions and the following disclaimer
00126 // in the documentation and/or other materials provided with the
00127 // distribution.
00128 //     * Neither the name of Google Inc. nor the names of its
00129 // contributors may be used to endorse or promote products derived from
00130 // this software without specific prior written permission.
00131 //
00132 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00133 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00134 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00135 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00136 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00137 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00138 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00139 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00140 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00141 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00142 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


gcloud_speech
Author(s):
autogenerated on Thu Jun 6 2019 17:58:03