exceptions.h
Go to the documentation of this file.
00001 #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00002 #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
00003 
00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
00005 #pragma once
00006 #endif
00007 
00008 
00009 #include "yaml-cpp-pm/mark.h"
00010 #include "yaml-cpp-pm/traits.h"
00011 #include <stdexcept>
00012 #include <string>
00013 #include <sstream>
00014 
00015 namespace YAML_PM
00016 {
00017         // error messages
00018         namespace ErrorMsg
00019         {
00020                 const char * const YAML_DIRECTIVE_ARGS    = "YAML directives must have exactly one argument";
00021                 const char * const YAML_VERSION           = "bad YAML version: ";
00022                 const char * const YAML_MAJOR_VERSION     = "YAML major version too large";
00023                 const char * const REPEATED_YAML_DIRECTIVE= "repeated YAML directive";
00024                 const char * const TAG_DIRECTIVE_ARGS     = "TAG directives must have exactly two arguments";
00025                 const char * const REPEATED_TAG_DIRECTIVE = "repeated TAG directive";
00026                 const char * const CHAR_IN_TAG_HANDLE     = "illegal character found while scanning tag handle";
00027                 const char * const TAG_WITH_NO_SUFFIX     = "tag handle with no suffix";
00028                 const char * const END_OF_VERBATIM_TAG    = "end of verbatim tag not found";
00029                 const char * const END_OF_MAP             = "end of map not found";
00030                 const char * const END_OF_MAP_FLOW        = "end of map flow not found";
00031                 const char * const END_OF_SEQ             = "end of sequence not found";
00032                 const char * const END_OF_SEQ_FLOW        = "end of sequence flow not found";
00033                 const char * const MULTIPLE_TAGS          = "cannot assign multiple tags to the same node";
00034                 const char * const MULTIPLE_ANCHORS       = "cannot assign multiple anchors to the same node";
00035                 const char * const MULTIPLE_ALIASES       = "cannot assign multiple aliases to the same node";
00036                 const char * const ALIAS_CONTENT          = "aliases can't have any content, *including* tags";
00037                 const char * const INVALID_HEX            = "bad character found while scanning hex number";
00038                 const char * const INVALID_UNICODE        = "invalid unicode: ";
00039                 const char * const INVALID_ESCAPE         = "unknown escape character: ";
00040                 const char * const UNKNOWN_TOKEN          = "unknown token";
00041                 const char * const DOC_IN_SCALAR          = "illegal document indicator in scalar";
00042                 const char * const EOF_IN_SCALAR          = "illegal EOF in scalar";
00043                 const char * const CHAR_IN_SCALAR         = "illegal character in scalar";
00044                 const char * const TAB_IN_INDENTATION     = "illegal tab when looking for indentation";
00045                 const char * const FLOW_END               = "illegal flow end";
00046                 const char * const BLOCK_ENTRY            = "illegal block entry";
00047                 const char * const MAP_KEY                = "illegal map key";
00048                 const char * const MAP_VALUE              = "illegal map value";
00049                 const char * const ALIAS_NOT_FOUND        = "alias not found after *";
00050                 const char * const ANCHOR_NOT_FOUND       = "anchor not found after &";
00051                 const char * const CHAR_IN_ALIAS          = "illegal character found while scanning alias";
00052                 const char * const CHAR_IN_ANCHOR         = "illegal character found while scanning anchor";
00053                 const char * const ZERO_INDENT_IN_BLOCK   = "cannot set zero indentation for a block scalar";
00054                 const char * const CHAR_IN_BLOCK          = "unexpected character in block scalar";
00055                 const char * const AMBIGUOUS_ANCHOR       = "cannot assign the same alias to multiple nodes";
00056                 const char * const UNKNOWN_ANCHOR         = "the referenced anchor is not defined";
00057 
00058                 const char * const INVALID_SCALAR         = "invalid scalar";
00059                 const char * const KEY_NOT_FOUND          = "key not found";
00060                 const char * const BAD_DEREFERENCE        = "bad dereference";
00061                 
00062                 const char * const UNMATCHED_GROUP_TAG    = "unmatched group tag";
00063                 const char * const UNEXPECTED_END_SEQ     = "unexpected end sequence token";
00064                 const char * const UNEXPECTED_END_MAP     = "unexpected end map token";
00065                 const char * const SINGLE_QUOTED_CHAR     = "invalid character in single-quoted string";
00066                 const char * const INVALID_ANCHOR         = "invalid anchor";
00067                 const char * const INVALID_ALIAS          = "invalid alias";
00068                 const char * const INVALID_TAG            = "invalid tag";
00069                 const char * const EXPECTED_KEY_TOKEN     = "expected key token";
00070                 const char * const EXPECTED_VALUE_TOKEN   = "expected value token";
00071                 const char * const UNEXPECTED_KEY_TOKEN   = "unexpected key token";
00072                 const char * const UNEXPECTED_VALUE_TOKEN = "unexpected value token";
00073 
00074                 template <typename T>
00075                 inline const std::string KEY_NOT_FOUND_WITH_KEY(const T&, typename disable_if<is_numeric<T> >::type * = 0) {
00076                         return KEY_NOT_FOUND;
00077                 }
00078 
00079                 inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) {
00080                         std::stringstream stream;
00081                         stream << KEY_NOT_FOUND << ": " << key;
00082                         return stream.str();
00083                 }
00084                 
00085                 template <typename T>
00086                 inline const std::string KEY_NOT_FOUND_WITH_KEY(const T& key, typename enable_if<is_numeric<T> >::type * = 0) {
00087                         std::stringstream stream;
00088                         stream << KEY_NOT_FOUND << ": " << key;
00089                         return stream.str();
00090                 }
00091         }
00092 
00093         class Exception: public std::runtime_error {
00094         public:
00095                 Exception(const Mark& mark_, const std::string& msg_)
00096                 : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
00097                 virtual ~Exception() throw() {}
00098 
00099                 Mark mark;
00100                 std::string msg;
00101 
00102         private:
00103                 static const std::string build_what(const Mark& mark, const std::string& msg) {
00104                         std::stringstream output;
00105                         output << "yaml-cpp: error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg;
00106                         return output.str();
00107                 }
00108         };
00109 
00110         class ParserException: public Exception {
00111         public:
00112                 ParserException(const Mark& mark_, const std::string& msg_)
00113                         : Exception(mark_, msg_) {}
00114         };
00115 
00116         class RepresentationException: public Exception {
00117         public:
00118                 RepresentationException(const Mark& mark_, const std::string& msg_)
00119                         : Exception(mark_, msg_) {}
00120         };
00121 
00122         // representation exceptions
00123         class InvalidScalar: public RepresentationException {
00124         public:
00125                 InvalidScalar(const Mark& mark_)
00126                         : RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
00127         };
00128 
00129         class KeyNotFound: public RepresentationException {
00130         public:
00131                 template <typename T>
00132                 KeyNotFound(const Mark& mark_, const T& key_)
00133                         : RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {}
00134         };
00135         
00136         template <typename T>
00137         class TypedKeyNotFound: public KeyNotFound {
00138         public:
00139                 TypedKeyNotFound(const Mark& mark_, const T& key_)
00140                         : KeyNotFound(mark_, key_), key(key_) {}
00141                 virtual ~TypedKeyNotFound() throw() {}
00142 
00143                 T key;
00144         };
00145 
00146         template <typename T>
00147         inline TypedKeyNotFound <T> MakeTypedKeyNotFound(const Mark& mark, const T& key) {
00148                 return TypedKeyNotFound <T> (mark, key);
00149         }
00150 
00151         class BadDereference: public RepresentationException {
00152         public:
00153                 BadDereference()
00154                 : RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {}
00155         };
00156         
00157         class EmitterException: public Exception {
00158         public:
00159                 EmitterException(const std::string& msg_)
00160                 : Exception(Mark::null(), msg_) {}
00161         };
00162 }
00163 
00164 #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:39