Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-12 09:08:09

0001 #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003 
0004 #if defined(_MSC_VER) ||                                            \
0005     (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006      (__GNUC__ >= 4))  // GCC supports "pragma once" correctly since 3.4
0007 #pragma once
0008 #endif
0009 
0010 #include "ATOOLS/YAML/yaml-cpp/mark.h"
0011 #include "ATOOLS/YAML/yaml-cpp/noexcept.h"
0012 #include "ATOOLS/YAML/yaml-cpp/traits.h"
0013 #include <sstream>
0014 #include <stdexcept>
0015 #include <string>
0016 
0017 namespace SHERPA_YAML {
0018 // error messages
0019 namespace ErrorMsg {
0020 const char* const YAML_DIRECTIVE_ARGS =
0021     "YAML directives must have exactly one argument";
0022 const char* const YAML_VERSION = "bad YAML version: ";
0023 const char* const YAML_MAJOR_VERSION = "YAML major version too large";
0024 const char* const REPEATED_YAML_DIRECTIVE = "repeated YAML directive";
0025 const char* const TAG_DIRECTIVE_ARGS =
0026     "TAG directives must have exactly two arguments";
0027 const char* const REPEATED_TAG_DIRECTIVE = "repeated TAG directive";
0028 const char* const CHAR_IN_TAG_HANDLE =
0029     "illegal character found while scanning tag handle";
0030 const char* const TAG_WITH_NO_SUFFIX = "tag handle with no suffix";
0031 const char* const END_OF_VERBATIM_TAG = "end of verbatim tag not found";
0032 const char* const END_OF_MAP = "end of map not found";
0033 const char* const END_OF_MAP_FLOW = "end of map flow not found";
0034 const char* const END_OF_SEQ = "end of sequence not found";
0035 const char* const END_OF_SEQ_FLOW = "end of sequence flow not found";
0036 const char* const MULTIPLE_TAGS =
0037     "cannot assign multiple tags to the same node";
0038 const char* const MULTIPLE_ANCHORS =
0039     "cannot assign multiple anchors to the same node";
0040 const char* const MULTIPLE_ALIASES =
0041     "cannot assign multiple aliases to the same node";
0042 const char* const ALIAS_CONTENT =
0043     "aliases can't have any content, *including* tags";
0044 const char* const INVALID_HEX = "bad character found while scanning hex number";
0045 const char* const INVALID_UNICODE = "invalid unicode: ";
0046 const char* const INVALID_ESCAPE = "unknown escape character: ";
0047 const char* const UNKNOWN_TOKEN = "unknown token";
0048 const char* const DOC_IN_SCALAR = "illegal document indicator in scalar";
0049 const char* const EOF_IN_SCALAR = "illegal EOF in scalar";
0050 const char* const CHAR_IN_SCALAR = "illegal character in scalar";
0051 const char* const TAB_IN_INDENTATION =
0052     "illegal tab when looking for indentation";
0053 const char* const FLOW_END = "illegal flow end";
0054 const char* const BLOCK_ENTRY = "illegal block entry";
0055 const char* const MAP_KEY = "illegal map key";
0056 const char* const MAP_VALUE = "illegal map value";
0057 const char* const ALIAS_NOT_FOUND = "alias not found after *";
0058 const char* const ANCHOR_NOT_FOUND = "anchor not found after &";
0059 const char* const CHAR_IN_ALIAS =
0060     "illegal character found while scanning alias";
0061 const char* const CHAR_IN_ANCHOR =
0062     "illegal character found while scanning anchor";
0063 const char* const ZERO_INDENT_IN_BLOCK =
0064     "cannot set zero indentation for a block scalar";
0065 const char* const CHAR_IN_BLOCK = "unexpected character in block scalar";
0066 const char* const AMBIGUOUS_ANCHOR =
0067     "cannot assign the same alias to multiple nodes";
0068 const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined";
0069 
0070 const char* const INVALID_NODE =
0071     "invalid node; this may result from using a map iterator as a sequence "
0072     "iterator, or vice-versa";
0073 const char* const INVALID_SCALAR = "invalid scalar";
0074 const char* const KEY_NOT_FOUND = "key not found";
0075 const char* const BAD_CONVERSION = "bad conversion";
0076 const char* const BAD_DEREFERENCE = "bad dereference";
0077 const char* const BAD_SUBSCRIPT = "operator[] call on a scalar";
0078 const char* const BAD_PUSHBACK = "appending to a non-sequence";
0079 const char* const BAD_INSERT = "inserting in a non-convertible-to-map";
0080 
0081 const char* const UNMATCHED_GROUP_TAG = "unmatched group tag";
0082 const char* const UNEXPECTED_END_SEQ = "unexpected end sequence token";
0083 const char* const UNEXPECTED_END_MAP = "unexpected end map token";
0084 const char* const SINGLE_QUOTED_CHAR =
0085     "invalid character in single-quoted string";
0086 const char* const INVALID_ANCHOR = "invalid anchor";
0087 const char* const INVALID_ALIAS = "invalid alias";
0088 const char* const INVALID_TAG = "invalid tag";
0089 const char* const BAD_FILE = "bad file";
0090 
0091 template <typename T>
0092 inline const std::string KEY_NOT_FOUND_WITH_KEY(
0093     const T&, typename disable_if<is_numeric<T>>::type* = 0) {
0094   return KEY_NOT_FOUND;
0095 }
0096 
0097 inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) {
0098   std::stringstream stream;
0099   stream << KEY_NOT_FOUND << ": " << key;
0100   return stream.str();
0101 }
0102 
0103 inline const std::string KEY_NOT_FOUND_WITH_KEY(const char* key) {
0104   std::stringstream stream;
0105   stream << KEY_NOT_FOUND << ": " << key;
0106   return stream.str();
0107 }
0108 
0109 template <typename T>
0110 inline const std::string KEY_NOT_FOUND_WITH_KEY(
0111     const T& key, typename enable_if<is_numeric<T>>::type* = 0) {
0112   std::stringstream stream;
0113   stream << KEY_NOT_FOUND << ": " << key;
0114   return stream.str();
0115 }
0116 
0117 template <typename T>
0118 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
0119     const T&, typename disable_if<is_numeric<T>>::type* = nullptr) {
0120   return BAD_SUBSCRIPT;
0121 }
0122 
0123 inline const std::string BAD_SUBSCRIPT_WITH_KEY(const std::string& key) {
0124   std::stringstream stream;
0125   stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")";
0126   return stream.str();
0127 }
0128 
0129 inline const std::string BAD_SUBSCRIPT_WITH_KEY(const char* key) {
0130   std::stringstream stream;
0131   stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")";
0132   return stream.str();
0133 }
0134 
0135 template <typename T>
0136 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
0137     const T& key, typename enable_if<is_numeric<T>>::type* = nullptr) {
0138   std::stringstream stream;
0139   stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")";
0140   return stream.str();
0141 }
0142 
0143 inline const std::string INVALID_NODE_WITH_KEY(const std::string& key) {
0144   std::stringstream stream;
0145   if (key.empty()) {
0146     return INVALID_NODE;
0147   }
0148   stream << "invalid node; first invalid key: \"" << key << "\"";
0149   return stream.str();
0150 }
0151 }  // namespace ErrorMsg
0152 
0153 class YAML_CPP_API Exception : public std::runtime_error {
0154  public:
0155   Exception(const Mark& mark_, const std::string& msg_)
0156       : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
0157   ~Exception() YAML_CPP_NOEXCEPT override;
0158 
0159   Exception(const Exception&) = default;
0160 
0161   Mark mark;
0162   std::string msg;
0163 
0164  private:
0165   static const std::string build_what(const Mark& mark,
0166                                       const std::string& msg) {
0167     if (mark.is_null()) {
0168       return msg;
0169     }
0170 
0171     std::stringstream output;
0172     output << "ATOOLS/YAML/yaml-cpp: error at line " << mark.line + 1 << ", column "
0173            << mark.column + 1 << ": " << msg;
0174     return output.str();
0175   }
0176 };
0177 
0178 class YAML_CPP_API ParserException : public Exception {
0179  public:
0180   ParserException(const Mark& mark_, const std::string& msg_)
0181       : Exception(mark_, msg_) {}
0182   ParserException(const ParserException&) = default;
0183   ~ParserException() YAML_CPP_NOEXCEPT override;
0184 };
0185 
0186 class YAML_CPP_API RepresentationException : public Exception {
0187  public:
0188   RepresentationException(const Mark& mark_, const std::string& msg_)
0189       : Exception(mark_, msg_) {}
0190   RepresentationException(const RepresentationException&) = default;
0191   ~RepresentationException() YAML_CPP_NOEXCEPT override;
0192 };
0193 
0194 // representation exceptions
0195 class YAML_CPP_API InvalidScalar : public RepresentationException {
0196  public:
0197   InvalidScalar(const Mark& mark_)
0198       : RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
0199   InvalidScalar(const InvalidScalar&) = default;
0200   ~InvalidScalar() YAML_CPP_NOEXCEPT override;
0201 };
0202 
0203 class YAML_CPP_API KeyNotFound : public RepresentationException {
0204  public:
0205   template <typename T>
0206   KeyNotFound(const Mark& mark_, const T& key_)
0207       : RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
0208   }
0209   KeyNotFound(const KeyNotFound&) = default;
0210   ~KeyNotFound() YAML_CPP_NOEXCEPT override;
0211 };
0212 
0213 template <typename T>
0214 class YAML_CPP_API TypedKeyNotFound : public KeyNotFound {
0215  public:
0216   TypedKeyNotFound(const Mark& mark_, const T& key_)
0217       : KeyNotFound(mark_, key_), key(key_) {}
0218   ~TypedKeyNotFound() YAML_CPP_NOEXCEPT override = default;
0219 
0220   T key;
0221 };
0222 
0223 template <typename T>
0224 inline TypedKeyNotFound<T> MakeTypedKeyNotFound(const Mark& mark,
0225                                                 const T& key) {
0226   return TypedKeyNotFound<T>(mark, key);
0227 }
0228 
0229 class YAML_CPP_API InvalidNode : public RepresentationException {
0230  public:
0231   InvalidNode(const std::string& key)
0232       : RepresentationException(Mark::null_mark(),
0233                                 ErrorMsg::INVALID_NODE_WITH_KEY(key)) {}
0234   InvalidNode(const InvalidNode&) = default;
0235   ~InvalidNode() YAML_CPP_NOEXCEPT override;
0236 };
0237 
0238 class YAML_CPP_API BadConversion : public RepresentationException {
0239  public:
0240   explicit BadConversion(const Mark& mark_)
0241       : RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {}
0242   BadConversion(const BadConversion&) = default;
0243   ~BadConversion() YAML_CPP_NOEXCEPT override;
0244 };
0245 
0246 template <typename T>
0247 class TypedBadConversion : public BadConversion {
0248  public:
0249   explicit TypedBadConversion(const Mark& mark_) : BadConversion(mark_) {}
0250 };
0251 
0252 class YAML_CPP_API BadDereference : public RepresentationException {
0253  public:
0254   BadDereference()
0255       : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
0256   BadDereference(const BadDereference&) = default;
0257   ~BadDereference() YAML_CPP_NOEXCEPT override;
0258 };
0259 
0260 class YAML_CPP_API BadSubscript : public RepresentationException {
0261  public:
0262   template <typename Key>
0263   BadSubscript(const Mark& mark_, const Key& key)
0264       : RepresentationException(mark_, ErrorMsg::BAD_SUBSCRIPT_WITH_KEY(key)) {}
0265   BadSubscript(const BadSubscript&) = default;
0266   ~BadSubscript() YAML_CPP_NOEXCEPT override;
0267 };
0268 
0269 class YAML_CPP_API BadPushback : public RepresentationException {
0270  public:
0271   BadPushback()
0272       : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
0273   BadPushback(const BadPushback&) = default;
0274   ~BadPushback() YAML_CPP_NOEXCEPT override;
0275 };
0276 
0277 class YAML_CPP_API BadInsert : public RepresentationException {
0278  public:
0279   BadInsert()
0280       : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
0281   BadInsert(const BadInsert&) = default;
0282   ~BadInsert() YAML_CPP_NOEXCEPT override;
0283 };
0284 
0285 class YAML_CPP_API EmitterException : public Exception {
0286  public:
0287   EmitterException(const std::string& msg_)
0288       : Exception(Mark::null_mark(), msg_) {}
0289   EmitterException(const EmitterException&) = default;
0290   ~EmitterException() YAML_CPP_NOEXCEPT override;
0291 };
0292 
0293 class YAML_CPP_API BadFile : public Exception {
0294  public:
0295   explicit BadFile(const std::string& filename)
0296       : Exception(Mark::null_mark(),
0297                   std::string(ErrorMsg::BAD_FILE) + ": " + filename) {}
0298   BadFile(const BadFile&) = default;
0299   ~BadFile() YAML_CPP_NOEXCEPT override;
0300 };
0301 }  // namespace SHERPA_YAML
0302 
0303 #endif  // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66