|
Video Processing Framework
|
00001 #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 00002 #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 00003 00004 #if !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/mark.h" 00010 #include "yaml-cpp/traits.h" 00011 #include <stdexcept> 00012 #include <string> 00013 #include <sstream> 00014 00015 namespace YAML 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 //const char * const KEY_NOT_FOUND_WITH_KEY = "KEY_NOT_FOUND_WITH_KEY"; 00075 00076 // template <typename T> 00077 // inline const std::string KEY_NOT_FOUND_WITH_KEY(const T&, typename disable_if<is_numeric<T> >::type * = 0) { 00078 // return KEY_NOT_FOUND; 00079 // } 00080 00081 template <typename T> 00082 inline const std::string KEY_NOT_FOUND_WITH_KEY() { 00083 return KEY_NOT_FOUND; 00084 } 00085 00086 00087 inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) { 00088 std::stringstream stream; 00089 stream << KEY_NOT_FOUND << ": " << key; 00090 return stream.str(); 00091 } 00092 00093 template <typename T> 00094 inline const std::string KEY_NOT_FOUND_WITH_KEY(const T& key, typename enable_if<is_numeric<T> >::type * = 0) { 00095 std::stringstream stream; 00096 stream << KEY_NOT_FOUND << ": " << key; 00097 return stream.str(); 00098 } 00099 } 00100 00101 class Exception: public std::runtime_error { 00102 public: 00103 Exception(const Mark& mark_, const std::string& msg_) 00104 : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {} 00105 virtual ~Exception() throw() {} 00106 00107 Mark mark; 00108 std::string msg; 00109 00110 private: 00111 static const std::string build_what(const Mark& mark, const std::string& msg) { 00112 std::stringstream output; 00113 output << "yaml-cpp: error at line " << mark.line+1 << ", column " << mark.column+1 << ": " << msg; 00114 return output.str(); 00115 } 00116 }; 00117 00118 class ParserException: public Exception { 00119 public: 00120 ParserException(const Mark& mark_, const std::string& msg_) 00121 : Exception(mark_, msg_) {} 00122 }; 00123 00124 class RepresentationException: public Exception { 00125 public: 00126 RepresentationException(const Mark& mark_, const std::string& msg_) 00127 : Exception(mark_, msg_) {} 00128 }; 00129 00130 // representation exceptions 00131 class InvalidScalar: public RepresentationException { 00132 public: 00133 InvalidScalar(const Mark& mark_) 00134 : RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {} 00135 }; 00136 00137 class KeyNotFound: public RepresentationException { 00138 public: 00139 template <typename T> 00140 KeyNotFound(const Mark& mark_, const T& key_) 00141 : RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {} 00142 }; 00143 00144 00145 template <typename T> 00146 class TypedKeyNotFound: public KeyNotFound { 00147 public: 00148 TypedKeyNotFound(const Mark& mark_, const T& key_) 00149 : KeyNotFound(mark_, key_), key(key_) {} 00150 virtual ~TypedKeyNotFound() throw() {} 00151 00152 T key; 00153 }; 00154 00155 template <typename T> 00156 inline TypedKeyNotFound <T> MakeTypedKeyNotFound(const Mark& mark, const T& key) { 00157 return TypedKeyNotFound <T> (mark, key); 00158 } 00159 00160 class BadDereference: public RepresentationException { 00161 public: 00162 BadDereference() 00163 : RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {} 00164 }; 00165 00166 class EmitterException: public Exception { 00167 public: 00168 EmitterException(const std::string& msg_) 00169 : Exception(Mark::null(), msg_) {} 00170 }; 00171 } 00172 00173 #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66