Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:16

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef UPB_BASE_STATUS_HPP_
0009 #define UPB_BASE_STATUS_HPP_
0010 
0011 #ifdef __cplusplus
0012 
0013 #include "upb/base/status.h"
0014 
0015 namespace upb {
0016 
0017 class Status final {
0018  public:
0019   Status() { upb_Status_Clear(&status_); }
0020 
0021   upb_Status* ptr() { return &status_; }
0022 
0023   // Returns true if there is no error.
0024   bool ok() const { return upb_Status_IsOk(&status_); }
0025 
0026   // Guaranteed to be NULL-terminated.
0027   const char* error_message() const {
0028     return upb_Status_ErrorMessage(&status_);
0029   }
0030 
0031   // The error message will be truncated if it is longer than
0032   // _kUpb_Status_MaxMessage-4.
0033   void SetErrorMessage(const char* msg) {
0034     upb_Status_SetErrorMessage(&status_, msg);
0035   }
0036   void SetFormattedErrorMessage(const char* fmt, ...) {
0037     va_list args;
0038     va_start(args, fmt);
0039     upb_Status_VSetErrorFormat(&status_, fmt, args);
0040     va_end(args);
0041   }
0042 
0043   // Resets the status to a successful state with no message.
0044   void Clear() { upb_Status_Clear(&status_); }
0045 
0046  private:
0047   upb_Status status_;
0048 };
0049 
0050 }  // namespace upb
0051 
0052 #endif  // __cplusplus
0053 
0054 #endif  // UPB_BASE_STATUS_HPP_