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.h@6:02df5c1108f1, 2020-04-09 (annotated)
- Committer:
- kabukistarship
- Date:
- Thu Apr 09 22:40:13 2020 +0000
- Revision:
- 6:02df5c1108f1
- Parent:
- 2:aa9a1377aa0d
Renamed StatusLED to StatusIndicator.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kabukistarship | 2:aa9a1377aa0d | 1 | /* mbedBug @version 0.x |
kabukistarship | 2:aa9a1377aa0d | 2 | @link https://github.com/KabukiStarship/mbedbug.git |
kabukistarship | 2:aa9a1377aa0d | 3 | @file /error_list.h |
kabukistarship | 2:aa9a1377aa0d | 4 | @author Cale McCollough <https://cale-mccollough.github.io> |
kabukistarship | 2:aa9a1377aa0d | 5 | @license Copyright 2016-20 (C) Kabuki Starship <kabukistarship.com>; all rights |
kabukistarship | 2:aa9a1377aa0d | 6 | reserved (R). This Source Code Form is subject to the terms of the Mozilla |
kabukistarship | 2:aa9a1377aa0d | 7 | Public License, v. 2.0. If a copy of the MPL was not distributed with this file, |
kabukistarship | 2:aa9a1377aa0d | 8 | You can obtain one at <https://mozilla.org/MPL/2.0/>. */ |
kabukistarship | 2:aa9a1377aa0d | 9 | #pragma once |
kabukistarship | 6:02df5c1108f1 | 10 | #include <mbedBugConfig.h> |
kabukistarship | 2:aa9a1377aa0d | 11 | namespace mbedBug { |
kabukistarship | 2:aa9a1377aa0d | 12 | |
kabukistarship | 2:aa9a1377aa0d | 13 | /* An array of error strings. |
kabukistarship | 2:aa9a1377aa0d | 14 | @code |
kabukistarship | 2:aa9a1377aa0d | 15 | ErrorList<5> Errors; |
kabukistarship | 2:aa9a1377aa0d | 16 | |
kabukistarship | 2:aa9a1377aa0d | 17 | @endcode |
kabukistarship | 2:aa9a1377aa0d | 18 | */ |
kabukistarship | 2:aa9a1377aa0d | 19 | template<unsigned int ErrorCountMax> |
kabukistarship | 2:aa9a1377aa0d | 20 | class ErrorList { |
kabukistarship | 2:aa9a1377aa0d | 21 | public: |
kabukistarship | 2:aa9a1377aa0d | 22 | |
kabukistarship | 2:aa9a1377aa0d | 23 | /* Default simple constructor. */ |
kabukistarship | 2:aa9a1377aa0d | 24 | ErrorList () |
kabukistarship | 2:aa9a1377aa0d | 25 | : ErrorCount (0) { |
kabukistarship | 2:aa9a1377aa0d | 26 | /// Nothing to do here! :-) |
kabukistarship | 2:aa9a1377aa0d | 27 | } |
kabukistarship | 2:aa9a1377aa0d | 28 | |
kabukistarship | 2:aa9a1377aa0d | 29 | /* Clears the error list. */ |
kabukistarship | 2:aa9a1377aa0d | 30 | void Clears () { ErrorCount = 0; } |
kabukistarship | 2:aa9a1377aa0d | 31 | |
kabukistarship | 2:aa9a1377aa0d | 32 | /* Gets the number of Errors. */ |
kabukistarship | 2:aa9a1377aa0d | 33 | unsigned int ErrorCountGet () { return ErrorCount; } |
kabukistarship | 2:aa9a1377aa0d | 34 | |
kabukistarship | 2:aa9a1377aa0d | 35 | /* Reports an error with the given message. */ |
kabukistarship | 2:aa9a1377aa0d | 36 | void Report (const char* Error) { |
kabukistarship | 2:aa9a1377aa0d | 37 | if (ErrorCount >= ErrorCountMax) return; |
kabukistarship | 2:aa9a1377aa0d | 38 | Errors[ErrorCount++] = Error; |
kabukistarship | 2:aa9a1377aa0d | 39 | return this; |
kabukistarship | 2:aa9a1377aa0d | 40 | } |
kabukistarship | 2:aa9a1377aa0d | 41 | |
kabukistarship | 2:aa9a1377aa0d | 42 | /* Reports an error with the given message. */ |
kabukistarship | 2:aa9a1377aa0d | 43 | ErrorList& operator += (const char* Error) { |
kabukistarship | 2:aa9a1377aa0d | 44 | Report (Error); |
kabukistarship | 2:aa9a1377aa0d | 45 | return this; |
kabukistarship | 2:aa9a1377aa0d | 46 | } |
kabukistarship | 2:aa9a1377aa0d | 47 | |
kabukistarship | 2:aa9a1377aa0d | 48 | virtual void Print () { |
kabukistarship | 2:aa9a1377aa0d | 49 | for (int i = 0; i < ErrorCount; ++i) |
kabukistarship | 2:aa9a1377aa0d | 50 | printf ("\r\n%s", Errors[i]); |
kabukistarship | 2:aa9a1377aa0d | 51 | } |
kabukistarship | 2:aa9a1377aa0d | 52 | |
kabukistarship | 2:aa9a1377aa0d | 53 | /* Returns the list of Errors. */ |
kabukistarship | 2:aa9a1377aa0d | 54 | const char* ErrorsGet () { return Errors; } |
kabukistarship | 2:aa9a1377aa0d | 55 | |
kabukistarship | 2:aa9a1377aa0d | 56 | private: |
kabukistarship | 2:aa9a1377aa0d | 57 | |
kabukistarship | 2:aa9a1377aa0d | 58 | unsigned int ErrorCount; |
kabukistarship | 2:aa9a1377aa0d | 59 | |
kabukistarship | 2:aa9a1377aa0d | 60 | const char* Errors[ErrorCountMax]; |
kabukistarship | 2:aa9a1377aa0d | 61 | }; |
kabukistarship | 2:aa9a1377aa0d | 62 | |
kabukistarship | 2:aa9a1377aa0d | 63 | } //< namespace mbedBug |