@@ -25,52 +25,44 @@ CGRAPH_NAMESPACE_BEGIN
2525static const int STATUS_OK = 0 ; /* * 正常流程返回值 */
2626static const int STATUS_ERR = -1 ; /* * 异常流程返回值 */
2727static const int STATUS_CRASH = -996 ; /* * 异常流程返回值 */
28- static const char * STATUS_ERROR_INFO_CONNECTOR = " && " ; /* * 多异常信息连接符号 */
2928
3029class CSTATUS {
3130public:
3231 explicit CSTATUS () = default;
3332
34- explicit CSTATUS (const std::string &errorInfo,
35- const std::string &locateInfo = CGRAPH_EMPTY) {
33+ explicit CSTATUS (const std::string &errorInfo) {
3634 this ->error_code_ = STATUS_ERR; // 默认的error code信息
3735 this ->error_info_ = errorInfo;
38- this ->error_locate_ = locateInfo;
3936 }
4037
41- explicit CSTATUS (int errorCode, const std::string &errorInfo,
42- const std::string &locateInfo = CGRAPH_EMPTY) {
38+ explicit CSTATUS (int errorCode, const std::string &errorInfo) {
4339 this ->error_code_ = errorCode;
4440 this ->error_info_ = errorInfo;
45- this ->error_locate_ = locateInfo;
4641 }
4742
4843 CSTATUS (const CSTATUS &status) {
49- if (status.isOK () ) {
44+ if (status.error_code_ == error_code_ ) {
5045 return ;
5146 }
5247
5348 this ->error_code_ = status.error_code_ ;
5449 this ->error_info_ = status.error_info_ ;
55- this ->error_locate_ = status.error_locate_ ;
5650 }
5751
5852 CSTATUS (const CSTATUS &&status) noexcept {
59- if (status.isOK () ) {
53+ if (status.error_code_ == error_code_ ) {
6054 return ;
6155 }
6256
6357 this ->error_code_ = status.error_code_ ;
6458 this ->error_info_ = status.error_info_ ;
65- this ->error_locate_ = status.error_locate_ ;
6659 }
6760
6861 CSTATUS& operator =(const CSTATUS& status) {
69- if (! status.isOK () ) {
62+ if (this -> error_code_ != status.error_code_ ) {
7063 // 如果status是正常的话,则所有数据保持不变
7164 this ->error_code_ = status.error_code_ ;
7265 this ->error_info_ = status.error_info_ ;
73- this ->error_locate_ = status.error_locate_ ;
7466 }
7567 return (*this );
7668 }
@@ -83,12 +75,21 @@ class CSTATUS {
8375 if (!this ->isErr () && cur.isErr ()) {
8476 this ->error_code_ = cur.error_code_ ;
8577 this ->error_info_ = cur.error_info_ ;
86- this ->error_locate_ = cur.error_locate_ ;
8778 }
8879
8980 return (*this );
9081 }
9182
83+ /* *
84+ * 恢复状态信息
85+ */
86+ void reset () {
87+ if (this ->error_code_ != STATUS_OK) {
88+ this ->error_code_ = STATUS_OK;
89+ this ->error_info_ .clear ();
90+ }
91+ }
92+
9293 /* *
9394 * 获取异常值信息
9495 * @return
@@ -105,14 +106,6 @@ class CSTATUS {
105106 return this ->error_info_ ;
106107 }
107108
108- /* *
109- * 获取报错位置
110- * @return
111- */
112- const std::string& getLocate () const {
113- return this ->error_locate_ ;
114- }
115-
116109 /* *
117110 * 判断当前状态是否可行
118111 * @return
@@ -129,6 +122,14 @@ class CSTATUS {
129122 return error_code_ < STATUS_OK; // 约定异常信息,均为负值
130123 }
131124
125+ /* *
126+ * 没有异常。包含 > 0 的警告类型
127+ * @return
128+ */
129+ bool isNotErr () const {
130+ return error_code_ >= STATUS_OK;
131+ }
132+
132133 /* *
133134 * 判断当前状态是否是崩溃了
134135 * @return
@@ -137,6 +138,29 @@ class CSTATUS {
137138 return STATUS_CRASH == error_code_;
138139 }
139140
141+ /* *
142+ * 设置异常信息
143+ * @param code
144+ * @param info
145+ * @return
146+ */
147+ CSTATUS* setInfo (int code, const std::string& info) {
148+ error_code_ = code;
149+ error_info_ = (STATUS_OK == error_code_) ? CGRAPH_EMPTY : info;
150+ return this ;
151+ }
152+
153+ /* *
154+ * 设置异常信息
155+ * @param info
156+ * @return
157+ */
158+ CSTATUS* setErrorInfo (const std::string& info) {
159+ error_code_ = STATUS_ERR;
160+ error_info_ = info;
161+ return this ;
162+ }
163+
140164private:
141165 int error_code_ = STATUS_OK; // 错误码信息
142166 std::string error_info_; // 错误信息描述
0 commit comments