• 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 
22 class MindrtStatus {
23  public:
24   typedef int32_t Code;
25 
26   static const Code KINIT = 1;
27   static const Code KOK = 0;
28   static const Code KERROR = -1;
29 
30   // Create a success status.
MindrtStatus(int32_t c)31   explicit MindrtStatus(int32_t c) : code(c) {}
32 
MindrtStatus()33   MindrtStatus() : code(KINIT) {}
34 
~MindrtStatus()35   virtual ~MindrtStatus() {}
36 
37   // Returns true iff the status indicates success.
IsInit()38   bool IsInit() const { return (code == KINIT); }
39 
IsOK()40   bool IsOK() const { return (code == KOK); }
41 
IsError()42   bool IsError() const { return (code != KINIT && code != KOK); }
43 
44   // Return a success status.
OK()45   MindrtStatus OK() const { return MindrtStatus(KOK); }
46 
Error()47   MindrtStatus Error() const { return MindrtStatus(KERROR); }
48 
SetError()49   void SetError() {
50     code = KERROR;
51     return;
52   }
53 
SetOK()54   void SetOK() {
55     code = KOK;
56     return;
57   }
58 
GetCode()59   Code GetCode() const { return code; }
60 
SetCode(Code c)61   void SetCode(Code c) { code = c; }
62 
63  private:
64   Code code;
65 };
66 
67 }  // namespace mindspore
68 
69 #endif
70