exceptions.h
Go to the documentation of this file.
1 #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5 #pragma once
6 #endif
7 
8 
9 #include "yaml-cpp-pm/mark.h"
10 #include "yaml-cpp-pm/traits.h"
11 #include <stdexcept>
12 #include <string>
13 #include <sstream>
14 
15 namespace YAML_PM
16 {
17  // error messages
18  namespace ErrorMsg
19  {
20  const char * const YAML_DIRECTIVE_ARGS = "YAML directives must have exactly one argument";
21  const char * const YAML_VERSION = "bad YAML version: ";
22  const char * const YAML_MAJOR_VERSION = "YAML major version too large";
23  const char * const REPEATED_YAML_DIRECTIVE= "repeated YAML directive";
24  const char * const TAG_DIRECTIVE_ARGS = "TAG directives must have exactly two arguments";
25  const char * const REPEATED_TAG_DIRECTIVE = "repeated TAG directive";
26  const char * const CHAR_IN_TAG_HANDLE = "illegal character found while scanning tag handle";
27  const char * const TAG_WITH_NO_SUFFIX = "tag handle with no suffix";
28  const char * const END_OF_VERBATIM_TAG = "end of verbatim tag not found";
29  const char * const END_OF_MAP = "end of map not found";
30  const char * const END_OF_MAP_FLOW = "end of map flow not found";
31  const char * const END_OF_SEQ = "end of sequence not found";
32  const char * const END_OF_SEQ_FLOW = "end of sequence flow not found";
33  const char * const MULTIPLE_TAGS = "cannot assign multiple tags to the same node";
34  const char * const MULTIPLE_ANCHORS = "cannot assign multiple anchors to the same node";
35  const char * const MULTIPLE_ALIASES = "cannot assign multiple aliases to the same node";
36  const char * const ALIAS_CONTENT = "aliases can't have any content, *including* tags";
37  const char * const INVALID_HEX = "bad character found while scanning hex number";
38  const char * const INVALID_UNICODE = "invalid unicode: ";
39  const char * const INVALID_ESCAPE = "unknown escape character: ";
40  const char * const UNKNOWN_TOKEN = "unknown token";
41  const char * const DOC_IN_SCALAR = "illegal document indicator in scalar";
42  const char * const EOF_IN_SCALAR = "illegal EOF in scalar";
43  const char * const CHAR_IN_SCALAR = "illegal character in scalar";
44  const char * const TAB_IN_INDENTATION = "illegal tab when looking for indentation";
45  const char * const FLOW_END = "illegal flow end";
46  const char * const BLOCK_ENTRY = "illegal block entry";
47  const char * const MAP_KEY = "illegal map key";
48  const char * const MAP_VALUE = "illegal map value";
49  const char * const ALIAS_NOT_FOUND = "alias not found after *";
50  const char * const ANCHOR_NOT_FOUND = "anchor not found after &";
51  const char * const CHAR_IN_ALIAS = "illegal character found while scanning alias";
52  const char * const CHAR_IN_ANCHOR = "illegal character found while scanning anchor";
53  const char * const ZERO_INDENT_IN_BLOCK = "cannot set zero indentation for a block scalar";
54  const char * const CHAR_IN_BLOCK = "unexpected character in block scalar";
55  const char * const AMBIGUOUS_ANCHOR = "cannot assign the same alias to multiple nodes";
56  const char * const UNKNOWN_ANCHOR = "the referenced anchor is not defined";
57 
58  const char * const INVALID_SCALAR = "invalid scalar";
59  const char * const KEY_NOT_FOUND = "key not found";
60  const char * const BAD_DEREFERENCE = "bad dereference";
61 
62  const char * const UNMATCHED_GROUP_TAG = "unmatched group tag";
63  const char * const UNEXPECTED_END_SEQ = "unexpected end sequence token";
64  const char * const UNEXPECTED_END_MAP = "unexpected end map token";
65  const char * const SINGLE_QUOTED_CHAR = "invalid character in single-quoted string";
66  const char * const INVALID_ANCHOR = "invalid anchor";
67  const char * const INVALID_ALIAS = "invalid alias";
68  const char * const INVALID_TAG = "invalid tag";
69  const char * const EXPECTED_KEY_TOKEN = "expected key token";
70  const char * const EXPECTED_VALUE_TOKEN = "expected value token";
71  const char * const UNEXPECTED_KEY_TOKEN = "unexpected key token";
72  const char * const UNEXPECTED_VALUE_TOKEN = "unexpected value token";
73 
74  template <typename T>
75  inline const std::string KEY_NOT_FOUND_WITH_KEY(const T&, typename disable_if<is_numeric<T> >::type * = 0) {
76  return KEY_NOT_FOUND;
77  }
78 
79  inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) {
80  std::stringstream stream;
81  stream << KEY_NOT_FOUND << ": " << key;
82  return stream.str();
83  }
84 
85  template <typename T>
86  inline const std::string KEY_NOT_FOUND_WITH_KEY(const T& key, typename enable_if<is_numeric<T> >::type * = 0) {
87  std::stringstream stream;
88  stream << KEY_NOT_FOUND << ": " << key;
89  return stream.str();
90  }
91  }
92 
93  class Exception: public std::runtime_error {
94  public:
95  Exception(const Mark& mark_, const std::string& msg_)
96  : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
97  virtual ~Exception() throw() {}
98 
101 
102  private:
103  static const std::string build_what(const Mark& mark, const std::string& msg) {
104  std::stringstream output;
105  output << "yaml-cpp: error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg;
106  return output.str();
107  }
108  };
109 
110  class ParserException: public Exception {
111  public:
112  ParserException(const Mark& mark_, const std::string& msg_)
113  : Exception(mark_, msg_) {}
114  };
115 
117  public:
118  RepresentationException(const Mark& mark_, const std::string& msg_)
119  : Exception(mark_, msg_) {}
120  };
121 
122  // representation exceptions
124  public:
125  InvalidScalar(const Mark& mark_)
126  : RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
127  };
128 
130  public:
131  template <typename T>
132  KeyNotFound(const Mark& mark_, const T& key_)
133  : RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {}
134  };
135 
136  template <typename T>
138  public:
139  TypedKeyNotFound(const Mark& mark_, const T& key_)
140  : KeyNotFound(mark_, key_), key(key_) {}
141  virtual ~TypedKeyNotFound() throw() {}
142 
144  };
145 
146  template <typename T>
147  inline TypedKeyNotFound <T> MakeTypedKeyNotFound(const Mark& mark, const T& key) {
148  return TypedKeyNotFound <T> (mark, key);
149  }
150 
152  public:
154  : RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {}
155  };
156 
157  class EmitterException: public Exception {
158  public:
160  : Exception(Mark::null(), msg_) {}
161  };
162 }
163 
164 #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
const char *const ALIAS_NOT_FOUND
Definition: exceptions.h:49
const char *const ANCHOR_NOT_FOUND
Definition: exceptions.h:50
const char *const INVALID_HEX
Definition: exceptions.h:37
const char *const CHAR_IN_ALIAS
Definition: exceptions.h:51
const char *const UNKNOWN_ANCHOR
Definition: exceptions.h:56
static const std::string build_what(const Mark &mark, const std::string &msg)
Definition: exceptions.h:103
const char *const END_OF_SEQ_FLOW
Definition: exceptions.h:32
const char *const CHAR_IN_TAG_HANDLE
Definition: exceptions.h:26
ParserException(const Mark &mark_, const std::string &msg_)
Definition: exceptions.h:112
const char *const ZERO_INDENT_IN_BLOCK
Definition: exceptions.h:53
const char *const MAP_KEY
Definition: exceptions.h:47
Exception(const Mark &mark_, const std::string &msg_)
Definition: exceptions.h:95
const char *const TAG_WITH_NO_SUFFIX
Definition: exceptions.h:27
int line
Definition: mark.h:19
::std::string string
Definition: gtest.h:1979
const char *const MULTIPLE_ALIASES
Definition: exceptions.h:35
const char *const SINGLE_QUOTED_CHAR
Definition: exceptions.h:65
const std::string KEY_NOT_FOUND_WITH_KEY(const T &, typename disable_if< is_numeric< T > >::type *=0)
Definition: exceptions.h:75
const char *const BAD_DEREFERENCE
Definition: exceptions.h:60
const char *const INVALID_ESCAPE
Definition: exceptions.h:39
const char *const UNKNOWN_TOKEN
Definition: exceptions.h:40
const char *const INVALID_SCALAR
Definition: exceptions.h:58
int column
Definition: mark.h:19
KeyNotFound(const Mark &mark_, const T &key_)
Definition: exceptions.h:132
const char *const INVALID_ALIAS
Definition: exceptions.h:67
const char *const CHAR_IN_SCALAR
Definition: exceptions.h:43
const char *const INVALID_ANCHOR
Definition: exceptions.h:66
const char *const EXPECTED_KEY_TOKEN
Definition: exceptions.h:69
const char *const UNEXPECTED_KEY_TOKEN
Definition: exceptions.h:71
const char *const YAML_DIRECTIVE_ARGS
Definition: exceptions.h:20
const char *const EOF_IN_SCALAR
Definition: exceptions.h:42
const char *const END_OF_VERBATIM_TAG
Definition: exceptions.h:28
const char *const BLOCK_ENTRY
Definition: exceptions.h:46
const char *const CHAR_IN_ANCHOR
Definition: exceptions.h:52
InvalidScalar(const Mark &mark_)
Definition: exceptions.h:125
const char *const UNEXPECTED_END_MAP
Definition: exceptions.h:64
const char *const REPEATED_TAG_DIRECTIVE
Definition: exceptions.h:25
const char *const YAML_VERSION
Definition: exceptions.h:21
std::string msg
Definition: exceptions.h:100
const char *const MULTIPLE_ANCHORS
Definition: exceptions.h:34
EmitterException(const std::string &msg_)
Definition: exceptions.h:159
RepresentationException(const Mark &mark_, const std::string &msg_)
Definition: exceptions.h:118
const char *const FLOW_END
Definition: exceptions.h:45
virtual ~Exception()
Definition: exceptions.h:97
const char *const ALIAS_CONTENT
Definition: exceptions.h:36
const char *const UNMATCHED_GROUP_TAG
Definition: exceptions.h:62
const char *const DOC_IN_SCALAR
Definition: exceptions.h:41
const char *const INVALID_UNICODE
Definition: exceptions.h:38
const char *const YAML_MAJOR_VERSION
Definition: exceptions.h:22
const char *const REPEATED_YAML_DIRECTIVE
Definition: exceptions.h:23
const char *const CHAR_IN_BLOCK
Definition: exceptions.h:54
const char *const AMBIGUOUS_ANCHOR
Definition: exceptions.h:55
const char *const UNEXPECTED_VALUE_TOKEN
Definition: exceptions.h:72
const char *const TAB_IN_INDENTATION
Definition: exceptions.h:44
const char *const MAP_VALUE
Definition: exceptions.h:48
TypedKeyNotFound(const Mark &mark_, const T &key_)
Definition: exceptions.h:139
const char *const END_OF_SEQ
Definition: exceptions.h:31
const char *const UNEXPECTED_END_SEQ
Definition: exceptions.h:63
const char *const END_OF_MAP_FLOW
Definition: exceptions.h:30
const char *const INVALID_TAG
Definition: exceptions.h:68
const char *const KEY_NOT_FOUND
Definition: exceptions.h:59
const char *const END_OF_MAP
Definition: exceptions.h:29
const char *const MULTIPLE_TAGS
Definition: exceptions.h:33
const char *const EXPECTED_VALUE_TOKEN
Definition: exceptions.h:70
TypedKeyNotFound< T > MakeTypedKeyNotFound(const Mark &mark, const T &key)
Definition: exceptions.h:147
const char *const TAG_DIRECTIVE_ARGS
Definition: exceptions.h:24


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:36:30