• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_CORE_MINDRT_INCLUDE_ASYNC_STATUS_H
18 #define MINDSPORE_CORE_MINDRT_INCLUDE_ASYNC_STATUS_H
19 
20 namespace mindspore {
21 class MindrtStatus {
22  public:
23   typedef int32_t Code;
24 
25   static const Code KINIT = 1;
26   static const Code KOK = 0;
27   static const Code KERROR = -1;
28 
29   // Create a success status.
MindrtStatus(int32_t c)30   explicit MindrtStatus(int32_t c) : code(c) {}
31 
MindrtStatus()32   MindrtStatus() : code(KINIT) {}
33 
~MindrtStatus()34   virtual ~MindrtStatus() {}
35 
36   // Returns true iff the status indicates success.
IsInit()37   bool IsInit() const { return (code == KINIT); }
38 
IsOK()39   bool IsOK() const { return (code == KOK); }
40 
IsError()41   bool IsError() const { return (code != KINIT && code != KOK); }
42 
43   // Return a success status.
OK()44   MindrtStatus OK() const { return MindrtStatus(KOK); }
45 
Error()46   MindrtStatus Error() const { return MindrtStatus(KERROR); }
47 
SetError()48   void SetError() {
49     code = KERROR;
50     return;
51   }
52 
SetOK()53   void SetOK() {
54     code = KOK;
55     return;
56   }
57 
GetCode()58   Code GetCode() const { return code; }
59 
SetCode(Code c)60   void SetCode(Code c) { code = c; }
61 
62  private:
63   Code code;
64 };
65 }  // namespace mindspore
66 
67 #endif
68