[964] | 1 | /*
|
---|
| 2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
| 3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
| 4 | */
|
---|
| 5 | /*
|
---|
| 6 | Based on the FS Import classes:
|
---|
| 7 | Copyright (C) 2005-2006 Feeling Software Inc
|
---|
| 8 | Copyright (C) 2005-2006 Autodesk Media Entertainment
|
---|
| 9 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | @file FUStatus.h
|
---|
| 14 | This file contains the FUStatus class.
|
---|
| 15 | */
|
---|
| 16 |
|
---|
| 17 | #ifndef _FU_STATUS_H_
|
---|
| 18 | #define _FU_STATUS_H_
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | A return status structure that includes a string.
|
---|
| 22 | Contains a return code as well as a string which explains the errors and warnings
|
---|
| 23 | attached to the return code. The return code is either 'successful' or 'failure'.
|
---|
| 24 | If the return code is 'failure', proceeding normally may be dangerous.
|
---|
| 25 | This structure is used by the FCDocument classes to explain parsing errors.
|
---|
| 26 |
|
---|
| 27 | @ingroup FUtils
|
---|
| 28 | */
|
---|
| 29 | class FCOLLADA_EXPORT FUStatus
|
---|
| 30 | {
|
---|
| 31 | private:
|
---|
| 32 | fstring errorString;
|
---|
| 33 | bool callSuccessful;
|
---|
| 34 |
|
---|
| 35 | public:
|
---|
| 36 | /** Default Constructor.
|
---|
| 37 | The default return code is 'successful'.
|
---|
| 38 | @param _callSuccessful Whether the return code should be set to 'successful'. */
|
---|
| 39 | FUStatus(bool _callSuccessful=true) { callSuccessful = _callSuccessful; }
|
---|
| 40 |
|
---|
| 41 | /** Sets the value of the return code to 'failure'.
|
---|
| 42 | @return The error code structure. Returns itself to support
|
---|
| 43 | multiple subsequent operations in one statement. */
|
---|
| 44 | FUStatus& Fail() { callSuccessful = false; return *this; }
|
---|
| 45 |
|
---|
| 46 | /** Sets the value of the return code to 'failure'.
|
---|
| 47 | @param str The error string for the error encountered.
|
---|
| 48 | @param line A line number.
|
---|
| 49 | @return The return status structure. Returns itself to support
|
---|
| 50 | multiple subsequent operations in one statement. */
|
---|
| 51 | FUStatus& Fail(const fstring& str, size_t line=0) { callSuccessful = false; AppendString(FS("ERROR[") + TO_FSTRING(line) + FS("]: ") + str); return *this; }
|
---|
| 52 | FUStatus& Fail(const fchar* str, size_t line=0) { callSuccessful = false; AppendString(FS("ERROR[") + TO_FSTRING(line) + FS("]: ") + str); return *this; } /**< See above. */
|
---|
| 53 |
|
---|
| 54 | /** Adds a warning to the return status. A warning does not set the return code to 'failure'.
|
---|
| 55 | @param str The warning string for the error encountered.
|
---|
| 56 | @param line A line number.
|
---|
| 57 | @return The return status structure. Returns itself to support
|
---|
| 58 | multiple subsequent operations in one statement. */
|
---|
| 59 | FUStatus& Warning(const fstring& str, size_t line=0) { AppendString(FS("WARNING[") + TO_FSTRING(line) + FS("]: ") + str); return *this; }
|
---|
| 60 | FUStatus& Warning(const fchar* str, size_t line=0) { AppendString(FS("WARNING[") + TO_FSTRING(line) + FS("]: ") + str); return *this; } /**< See above. */
|
---|
| 61 |
|
---|
| 62 | /** Merges two return stati together.
|
---|
| 63 | Appends to this return status the error string from the given status.
|
---|
| 64 | The merged return code is 'failure', if either return codes are 'failure'.
|
---|
| 65 | @param a The return status to merge with. */
|
---|
| 66 | void AppendStatus(const FUStatus& a) { AppendString(a.errorString); callSuccessful &= a.callSuccessful; }
|
---|
| 67 |
|
---|
| 68 | /** Appends a return string to the return status.
|
---|
| 69 | A 'newline' code is added between return strings.
|
---|
| 70 | @param str The return string to append. */
|
---|
| 71 | void AppendString(const fstring& str) { AppendString(str.c_str()); }
|
---|
| 72 | void AppendString(const fchar* str) { if (*str != 0) { if (!errorString.empty()) errorString += FC("\r\n"); errorString += str; } } /**< See above. */
|
---|
| 73 |
|
---|
| 74 | /** Retrieves the error/return string for this return status.
|
---|
| 75 | @return The return string. */
|
---|
| 76 | const fchar* GetErrorString() const { return errorString.empty() ? (callSuccessful ? FC("Success") : FC("Failure")) : errorString.c_str(); }
|
---|
| 77 |
|
---|
| 78 | /** Retrieves whether the return status is 'successful'.
|
---|
| 79 | @return Whether the return status is 'successful'. */
|
---|
| 80 | bool IsSuccessful() const { return callSuccessful; }
|
---|
| 81 |
|
---|
| 82 | /** Retrieves whether the return status is 'failure'.
|
---|
| 83 | @return Whether the return status is 'failure'. */
|
---|
| 84 | bool IsFailure() const { return !callSuccessful; }
|
---|
| 85 |
|
---|
| 86 | /** Transforms the return status into a boolean primitive.
|
---|
| 87 | @return Whether the return status is 'successful'. */
|
---|
| 88 | operator bool() const { return callSuccessful; }
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | #endif // _FU_STATUS_H_
|
---|