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 
143  T key;
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
YAML_PM::TypedKeyNotFound::key
T key
Definition: exceptions.h:143
YAML_PM::ErrorMsg::UNMATCHED_GROUP_TAG
const char *const UNMATCHED_GROUP_TAG
Definition: exceptions.h:62
YAML_PM::ErrorMsg::END_OF_MAP
const char *const END_OF_MAP
Definition: exceptions.h:29
YAML_PM::ErrorMsg::CHAR_IN_ALIAS
const char *const CHAR_IN_ALIAS
Definition: exceptions.h:51
YAML_PM::ErrorMsg::KEY_NOT_FOUND
const char *const KEY_NOT_FOUND
Definition: exceptions.h:59
YAML_PM::Exception::Exception
Exception(const Mark &mark_, const std::string &msg_)
Definition: exceptions.h:95
YAML_PM::ErrorMsg::MULTIPLE_ALIASES
const char *const MULTIPLE_ALIASES
Definition: exceptions.h:35
YAML_PM::ErrorMsg::CHAR_IN_ANCHOR
const char *const CHAR_IN_ANCHOR
Definition: exceptions.h:52
YAML_PM::ErrorMsg::CHAR_IN_BLOCK
const char *const CHAR_IN_BLOCK
Definition: exceptions.h:54
YAML_PM::ErrorMsg::END_OF_VERBATIM_TAG
const char *const END_OF_VERBATIM_TAG
Definition: exceptions.h:28
YAML_PM::ErrorMsg::INVALID_HEX
const char *const INVALID_HEX
Definition: exceptions.h:37
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::ErrorMsg::INVALID_SCALAR
const char *const INVALID_SCALAR
Definition: exceptions.h:58
YAML_PM::ErrorMsg::REPEATED_YAML_DIRECTIVE
const char *const REPEATED_YAML_DIRECTIVE
Definition: exceptions.h:23
YAML_PM::ErrorMsg::UNKNOWN_ANCHOR
const char *const UNKNOWN_ANCHOR
Definition: exceptions.h:56
YAML_PM::ErrorMsg::INVALID_ALIAS
const char *const INVALID_ALIAS
Definition: exceptions.h:67
YAML_PM::ErrorMsg::SINGLE_QUOTED_CHAR
const char *const SINGLE_QUOTED_CHAR
Definition: exceptions.h:65
YAML_PM::ErrorMsg::INVALID_TAG
const char *const INVALID_TAG
Definition: exceptions.h:68
YAML_PM::MakeTypedKeyNotFound
TypedKeyNotFound< T > MakeTypedKeyNotFound(const Mark &mark, const T &key)
Definition: exceptions.h:147
YAML_PM::ErrorMsg::EXPECTED_KEY_TOKEN
const char *const EXPECTED_KEY_TOKEN
Definition: exceptions.h:69
YAML_PM::InvalidScalar::InvalidScalar
InvalidScalar(const Mark &mark_)
Definition: exceptions.h:125
YAML_PM::ErrorMsg::INVALID_ESCAPE
const char *const INVALID_ESCAPE
Definition: exceptions.h:39
YAML_PM::ErrorMsg::ANCHOR_NOT_FOUND
const char *const ANCHOR_NOT_FOUND
Definition: exceptions.h:50
YAML_PM::ErrorMsg::YAML_DIRECTIVE_ARGS
const char *const YAML_DIRECTIVE_ARGS
Definition: exceptions.h:20
YAML_PM::ErrorMsg::UNEXPECTED_END_MAP
const char *const UNEXPECTED_END_MAP
Definition: exceptions.h:64
YAML_PM::ErrorMsg::MULTIPLE_TAGS
const char *const MULTIPLE_TAGS
Definition: exceptions.h:33
YAML_PM::KeyNotFound::KeyNotFound
KeyNotFound(const Mark &mark_, const T &key_)
Definition: exceptions.h:132
YAML_PM::Mark::line
int line
Definition: mark.h:19
YAML_PM::TypedKeyNotFound::~TypedKeyNotFound
virtual ~TypedKeyNotFound()
Definition: exceptions.h:141
YAML_PM::ErrorMsg::MAP_KEY
const char *const MAP_KEY
Definition: exceptions.h:47
YAML_PM::disable_if
Definition: traits.h:53
YAML_PM::ErrorMsg::MAP_VALUE
const char *const MAP_VALUE
Definition: exceptions.h:48
YAML_PM::ErrorMsg::INVALID_UNICODE
const char *const INVALID_UNICODE
Definition: exceptions.h:38
YAML_PM::ErrorMsg::BAD_DEREFERENCE
const char *const BAD_DEREFERENCE
Definition: exceptions.h:60
testing::internal::string
::std::string string
Definition: gtest.h:1979
YAML_PM::ErrorMsg::UNEXPECTED_END_SEQ
const char *const UNEXPECTED_END_SEQ
Definition: exceptions.h:63
YAML_PM::ErrorMsg::UNEXPECTED_KEY_TOKEN
const char *const UNEXPECTED_KEY_TOKEN
Definition: exceptions.h:71
YAML_PM::ParserException
Definition: exceptions.h:110
YAML_PM::is_numeric
Definition: traits.h:12
YAML_PM::ErrorMsg::INVALID_ANCHOR
const char *const INVALID_ANCHOR
Definition: exceptions.h:66
YAML_PM::ErrorMsg::CHAR_IN_SCALAR
const char *const CHAR_IN_SCALAR
Definition: exceptions.h:43
YAML_PM::ErrorMsg::MULTIPLE_ANCHORS
const char *const MULTIPLE_ANCHORS
Definition: exceptions.h:34
YAML_PM::ErrorMsg::ALIAS_NOT_FOUND
const char *const ALIAS_NOT_FOUND
Definition: exceptions.h:49
YAML_PM::ErrorMsg::CHAR_IN_TAG_HANDLE
const char *const CHAR_IN_TAG_HANDLE
Definition: exceptions.h:26
YAML_PM::RepresentationException
Definition: exceptions.h:116
YAML_PM::ErrorMsg::DOC_IN_SCALAR
const char *const DOC_IN_SCALAR
Definition: exceptions.h:41
YAML_PM::TypedKeyNotFound
Definition: exceptions.h:137
YAML_PM::Mark::column
int column
Definition: mark.h:19
YAML_PM::ErrorMsg::EOF_IN_SCALAR
const char *const EOF_IN_SCALAR
Definition: exceptions.h:42
YAML_PM::ErrorMsg::TAG_DIRECTIVE_ARGS
const char *const TAG_DIRECTIVE_ARGS
Definition: exceptions.h:24
YAML_PM::ErrorMsg::KEY_NOT_FOUND_WITH_KEY
const std::string KEY_NOT_FOUND_WITH_KEY(const T &key, typename enable_if< is_numeric< T > >::type *=0)
Definition: exceptions.h:86
YAML_PM::Exception::build_what
static const std::string build_what(const Mark &mark, const std::string &msg)
Definition: exceptions.h:103
YAML_PM::RepresentationException::RepresentationException
RepresentationException(const Mark &mark_, const std::string &msg_)
Definition: exceptions.h:118
YAML_PM::ErrorMsg::END_OF_SEQ_FLOW
const char *const END_OF_SEQ_FLOW
Definition: exceptions.h:32
YAML_PM::ErrorMsg::FLOW_END
const char *const FLOW_END
Definition: exceptions.h:45
YAML_PM::ErrorMsg::TAB_IN_INDENTATION
const char *const TAB_IN_INDENTATION
Definition: exceptions.h:44
YAML_PM::ErrorMsg::REPEATED_TAG_DIRECTIVE
const char *const REPEATED_TAG_DIRECTIVE
Definition: exceptions.h:25
YAML_PM::ErrorMsg::EXPECTED_VALUE_TOKEN
const char *const EXPECTED_VALUE_TOKEN
Definition: exceptions.h:70
YAML_PM::ErrorMsg::YAML_VERSION
const char *const YAML_VERSION
Definition: exceptions.h:21
YAML_PM::ErrorMsg::TAG_WITH_NO_SUFFIX
const char *const TAG_WITH_NO_SUFFIX
Definition: exceptions.h:27
YAML_PM::KeyNotFound
Definition: exceptions.h:129
YAML_PM::ErrorMsg::ZERO_INDENT_IN_BLOCK
const char *const ZERO_INDENT_IN_BLOCK
Definition: exceptions.h:53
YAML_PM::ErrorMsg::AMBIGUOUS_ANCHOR
const char *const AMBIGUOUS_ANCHOR
Definition: exceptions.h:55
YAML_PM::ParserException::ParserException
ParserException(const Mark &mark_, const std::string &msg_)
Definition: exceptions.h:112
YAML_PM::BadDereference
Definition: exceptions.h:151
YAML_PM::Mark
Definition: mark.h:13
YAML_PM::Exception::~Exception
virtual ~Exception()
Definition: exceptions.h:97
std
YAML_PM::Exception
Definition: exceptions.h:93
YAML_PM::InvalidScalar
Definition: exceptions.h:123
YAML_PM::ErrorMsg::UNEXPECTED_VALUE_TOKEN
const char *const UNEXPECTED_VALUE_TOKEN
Definition: exceptions.h:72
YAML_PM::EmitterException::EmitterException
EmitterException(const std::string &msg_)
Definition: exceptions.h:159
YAML_PM::ErrorMsg::BLOCK_ENTRY
const char *const BLOCK_ENTRY
Definition: exceptions.h:46
YAML_PM::BadDereference::BadDereference
BadDereference()
Definition: exceptions.h:153
YAML_PM::ErrorMsg::ALIAS_CONTENT
const char *const ALIAS_CONTENT
Definition: exceptions.h:36
YAML_PM::Exception::mark
Mark mark
Definition: exceptions.h:99
YAML_PM::ErrorMsg::END_OF_SEQ
const char *const END_OF_SEQ
Definition: exceptions.h:31
YAML_PM::ErrorMsg::UNKNOWN_TOKEN
const char *const UNKNOWN_TOKEN
Definition: exceptions.h:40
YAML_PM::ErrorMsg::YAML_MAJOR_VERSION
const char *const YAML_MAJOR_VERSION
Definition: exceptions.h:22
traits.h
YAML_PM::ErrorMsg::KEY_NOT_FOUND_WITH_KEY
const std::string KEY_NOT_FOUND_WITH_KEY(const T &, typename disable_if< is_numeric< T > >::type *=0)
Definition: exceptions.h:75
YAML_PM::enable_if
Definition: traits.h:42
YAML_PM::EmitterException
Definition: exceptions.h:157
mark.h
YAML_PM::Exception::msg
std::string msg
Definition: exceptions.h:100
YAML_PM::TypedKeyNotFound::TypedKeyNotFound
TypedKeyNotFound(const Mark &mark_, const T &key_)
Definition: exceptions.h:139
YAML_PM::ErrorMsg::END_OF_MAP_FLOW
const char *const END_OF_MAP_FLOW
Definition: exceptions.h:30


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:57