|
| 1 | +/* |
| 2 | +MIT License |
| 3 | +
|
| 4 | +Copyright (c) 2022 Cedric Jimenez |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +*/ |
| 24 | + |
| 25 | +#ifndef JSON_H |
| 26 | +#define JSON_H |
| 27 | + |
| 28 | +// Disable GCC warnings |
| 29 | +#ifdef __GNUC__ |
| 30 | +#pragma GCC diagnostic push |
| 31 | +#ifdef __clang__ |
| 32 | +#pragma GCC diagnostic ignored "-Wexceptions" |
| 33 | +#else |
| 34 | +#pragma GCC diagnostic ignored "-Wclass-memaccess" |
| 35 | +#endif |
| 36 | +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" |
| 37 | +#endif // __GNUC__ |
| 38 | + |
| 39 | +// Use exception for critical parse errors |
| 40 | +// instead of asserts |
| 41 | +#include <stdexcept> |
| 42 | +namespace rapidjson |
| 43 | +{ |
| 44 | +/** @brief Specific exception class dedicated to critical parse errors */ |
| 45 | +class parse_exception : public std::logic_error |
| 46 | +{ |
| 47 | + public: |
| 48 | + /** @brief Default constructor */ |
| 49 | + parse_exception(const char* reason) : std::logic_error(reason) { } |
| 50 | +}; |
| 51 | +} // namespace rapidjson |
| 52 | +#define EXCEPTION_REASON_STRINGIFY(x) #x |
| 53 | +#define RAPIDJSON_ASSERT(x) \ |
| 54 | + if (!(x)) \ |
| 55 | + throw parse_exception(EXCEPTION_REASON_STRINGIFY(x)) |
| 56 | + |
| 57 | +// Include rapidjson's headers |
| 58 | +#include "rapidjson/document.h" |
| 59 | +#include "rapidjson/error/en.h" |
| 60 | +#include "rapidjson/schema.h" |
| 61 | +#include "rapidjson/stringbuffer.h" |
| 62 | +#include "rapidjson/writer.h" |
| 63 | + |
| 64 | +// Restore GCC warnings |
| 65 | +#ifdef __GNUC__ |
| 66 | +#pragma GCC diagnostic pop |
| 67 | +#endif // __GNUC__ |
| 68 | + |
| 69 | +#endif // JSON_H |
0 commit comments