Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ErrorList.hpp@1:1a1cf1ae06f3, 2020-04-11 (annotated)
- Committer:
- kabukistarship
- Date:
- Sat Apr 11 08:47:51 2020 +0000
- Revision:
- 1:1a1cf1ae06f3
- Parent:
- 0:88767c46ae45
Change.Port to Arduino using SickBay programming model. #13 #A.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kabukistarship | 0:88767c46ae45 | 1 | /** Kabuki Tek @version 0.x |
kabukistarship | 0:88767c46ae45 | 2 | @link https://github.com/KabukiStarship/KabukiTek.git |
kabukistarship | 0:88767c46ae45 | 3 | @file /ErrorList.hpp |
kabukistarship | 0:88767c46ae45 | 4 | @author Cale McCollough <https://cale-mccollough.github.io> |
kabukistarship | 0:88767c46ae45 | 5 | @license Copyright 2020 (C) Kabuki Starship <kabukistarship.com>. |
kabukistarship | 0:88767c46ae45 | 6 | This Source Code Form is subject to the terms of the Mozilla Public License, |
kabukistarship | 0:88767c46ae45 | 7 | v. 2.0. If a copy of the MPL was not distributed with this file, you can obtain |
kabukistarship | 0:88767c46ae45 | 8 | one at <https://mozilla.org/MPL/2.0/>. */ |
kabukistarship | 0:88767c46ae45 | 9 | #pragma once |
kabukistarship | 0:88767c46ae45 | 10 | #include <_Config.h> |
kabukistarship | 0:88767c46ae45 | 11 | namespace _ { |
kabukistarship | 0:88767c46ae45 | 12 | |
kabukistarship | 0:88767c46ae45 | 13 | /* An array of error strings. |
kabukistarship | 0:88767c46ae45 | 14 | @code |
kabukistarship | 0:88767c46ae45 | 15 | ErrorList<5> Errors; |
kabukistarship | 0:88767c46ae45 | 16 | |
kabukistarship | 0:88767c46ae45 | 17 | @endcode |
kabukistarship | 0:88767c46ae45 | 18 | */ |
kabukistarship | 0:88767c46ae45 | 19 | template<unsigned int ErrorCountMax> |
kabukistarship | 0:88767c46ae45 | 20 | class ErrorList { |
kabukistarship | 0:88767c46ae45 | 21 | public: |
kabukistarship | 0:88767c46ae45 | 22 | |
kabukistarship | 0:88767c46ae45 | 23 | /* Default simple constructor. */ |
kabukistarship | 0:88767c46ae45 | 24 | ErrorList () |
kabukistarship | 0:88767c46ae45 | 25 | : ErrorCount (0) { |
kabukistarship | 0:88767c46ae45 | 26 | /// Nothing to do here! :-) |
kabukistarship | 0:88767c46ae45 | 27 | } |
kabukistarship | 0:88767c46ae45 | 28 | |
kabukistarship | 0:88767c46ae45 | 29 | /* Clears the error list. */ |
kabukistarship | 0:88767c46ae45 | 30 | void Clears () { ErrorCount = 0; } |
kabukistarship | 0:88767c46ae45 | 31 | |
kabukistarship | 0:88767c46ae45 | 32 | /* Gets the number of Errors. */ |
kabukistarship | 0:88767c46ae45 | 33 | unsigned int ErrorCountGet () { return ErrorCount; } |
kabukistarship | 0:88767c46ae45 | 34 | |
kabukistarship | 0:88767c46ae45 | 35 | /* Reports an error with the given message. */ |
kabukistarship | 0:88767c46ae45 | 36 | void Report (const char* Error) { |
kabukistarship | 0:88767c46ae45 | 37 | if (ErrorCount >= ErrorCountMax) return; |
kabukistarship | 0:88767c46ae45 | 38 | Errors[ErrorCount++] = Error; |
kabukistarship | 0:88767c46ae45 | 39 | return this; |
kabukistarship | 0:88767c46ae45 | 40 | } |
kabukistarship | 0:88767c46ae45 | 41 | |
kabukistarship | 0:88767c46ae45 | 42 | /* Reports an error with the given message. */ |
kabukistarship | 0:88767c46ae45 | 43 | ErrorList& operator += (const char* Error) { |
kabukistarship | 0:88767c46ae45 | 44 | Report (Error); |
kabukistarship | 0:88767c46ae45 | 45 | return this; |
kabukistarship | 0:88767c46ae45 | 46 | } |
kabukistarship | 0:88767c46ae45 | 47 | |
kabukistarship | 0:88767c46ae45 | 48 | virtual void Print () { |
kabukistarship | 0:88767c46ae45 | 49 | for (int i = 0; i < ErrorCount; ++i) |
kabukistarship | 0:88767c46ae45 | 50 | printf ("\r\n%s", Errors[i]); |
kabukistarship | 0:88767c46ae45 | 51 | } |
kabukistarship | 0:88767c46ae45 | 52 | |
kabukistarship | 0:88767c46ae45 | 53 | /* Returns the list of Errors. */ |
kabukistarship | 0:88767c46ae45 | 54 | const char* ErrorsGet () { return Errors; } |
kabukistarship | 0:88767c46ae45 | 55 | |
kabukistarship | 0:88767c46ae45 | 56 | private: |
kabukistarship | 0:88767c46ae45 | 57 | |
kabukistarship | 0:88767c46ae45 | 58 | unsigned int ErrorCount; |
kabukistarship | 0:88767c46ae45 | 59 | |
kabukistarship | 0:88767c46ae45 | 60 | const char* Errors[ErrorCountMax]; |
kabukistarship | 0:88767c46ae45 | 61 | }; |
kabukistarship | 0:88767c46ae45 | 62 | |
kabukistarship | 0:88767c46ae45 | 63 | } //< namespace _ |