1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgIntrospection - Copyright (C) 2005 Marco Jez
#ifndef OSGINTROSPECTION_EXCEPTIONS_
#define OSGINTROSPECTION_EXCEPTIONS_
#include <string>
#include <osgIntrospection/ExtendedTypeInfo>
namespace osgIntrospection
{
class Exception
{
public:
Exception(const std::string& msg): msg_(msg) {}
const std::string& what() const throw() { return msg_; }
private:
std::string msg_;
};
struct ReflectionException: public Exception
{
ReflectionException(const std::string& msg): Exception(msg) {}
};
struct TypeNotDefinedException: public ReflectionException
{
TypeNotDefinedException(const ExtendedTypeInfo &ti)
: ReflectionException("type `" + std::string(ti.name()) + "' is declared but not defined")
{
}
};
struct TypeIsAbstractException: public ReflectionException
{
TypeIsAbstractException(const ExtendedTypeInfo &ti)
: ReflectionException("cannot create instances of abstract type `" + std::string(ti.name()) + "'")
{
}
};
struct ConstructorNotFoundException: public ReflectionException
{
ConstructorNotFoundException(const ExtendedTypeInfo &ti)
: ReflectionException("could not find a suitable constructor in type `" + std::string(ti.name()) + "'")
{
}
};
struct ProtectedConstructorInvocationException: public ReflectionException
{
ProtectedConstructorInvocationException()
: ReflectionException("cannot invoke protected constructor")
{
}
};
struct InvokeNotImplementedException: public ReflectionException
{
InvokeNotImplementedException()
: ReflectionException("invoke() not implemented")
{
}
};
struct InvalidFunctionPointerException: public ReflectionException
{
InvalidFunctionPointerException()
: ReflectionException("invalid function pointer during invoke()")
{
}
};
struct ConstIsConstException: public ReflectionException
{
ConstIsConstException()
: ReflectionException("cannot modify a const value")
{
}
};
struct ProtectedMethodInvocationException: public ReflectionException
{
ProtectedMethodInvocationException()
: ReflectionException("cannot invoke protected method")
{
}
};
struct EmptyValueException: public ReflectionException
{
EmptyValueException()
: ReflectionException("cannot retrieve an empty value")
{
}
};
struct TypeNotFoundException: public ReflectionException
{
TypeNotFoundException(const std::string& qname)
: ReflectionException("type `" + qname + "' not found")
{
}
};
struct MethodNotFoundException: public ReflectionException
{
MethodNotFoundException(const std::string& name, const std::string& cname)
: ReflectionException("could not find a suitable method of name `" + name + "' in class `" + cname + "'")
{
}
};
struct StreamWriteErrorException: public ReflectionException
{
StreamWriteErrorException()
: ReflectionException("an error occured while trying to write to a stream")
{
}
};
struct StreamReadErrorException: public ReflectionException
{
StreamReadErrorException()
: ReflectionException("an error occured while trying to read from a stream")
{
}
};
class StreamingNotSupportedException: public ReflectionException
{
public:
enum OperationType
{
ANY,
TEXT_WRITE,
TEXT_READ,
BINARY_WRITE,
BINARY_READ
};
StreamingNotSupportedException(OperationType op, const ExtendedTypeInfo &type)
: ReflectionException(build_msg(op, type))
{
}
private:
std::string build_msg(OperationType op, const ExtendedTypeInfo &type)
{
std::string opstr;
switch (op)
{
case TEXT_WRITE: opstr = "writing to text stream"; break;
case TEXT_READ: opstr = "reading from text stream"; break;
case BINARY_WRITE: opstr = "writing to binary stream"; break;
case BINARY_READ: opstr = "reading from binary stream"; break;
case ANY:
default: opstr = "streaming";
}
return opstr + std::string(" is not supported on type `" + std::string(type.name()) + "'");
}
};
struct TypeConversionException: public ReflectionException
{
TypeConversionException(const ExtendedTypeInfo &type1, const ExtendedTypeInfo &type2)
: ReflectionException("cannot convert from type `" + std::string(type1.name()) + "' to type `" + std::string(type2.name()) + "'")
{
}
};
class PropertyAccessException: public ReflectionException
{
public:
enum AccessType
{
GET,
SET,
IGET,
ISET,
AGET,
ASET,
ADD,
INSERT,
REMOVE,
COUNT
};
PropertyAccessException(const std::string& pname, AccessType denied)
: ReflectionException(build_msg(pname, denied))
{
}
private:
std::string build_msg(const std::string& pname, AccessType denied) const
{
std::string msg;
switch (denied)
{
case GET: msg = "retrieved"; break;
case SET: msg = "set"; break;
case IGET: msg = "retrieved with indices"; break;
case ISET: msg = "set with indices"; break;
case AGET: msg = "retrieved with array index"; break;
case ASET: msg = "set with array index"; break;
case ADD: msg = "added"; break;
case INSERT: msg = "inserted"; break;
case REMOVE: msg = "removed"; break;
case COUNT: msg = "counted"; break;
default: msg = "?";
}
return std::string("value for property `" + pname + "' cannot be " + msg);
}
};
struct IndexValuesNotDefinedException: ReflectionException
{
IndexValuesNotDefinedException(const std::string& name, const std::string& iname)
: ReflectionException("couldn't determine a finite set of values for index `" + iname + "' of property `" + name + "'. Make sure that either: 1) the index is an enumeration, or 2) a valid custom indexing attribute was assigned to the property.")
{
}
};
struct ComparisonNotPermittedException: ReflectionException
{
ComparisonNotPermittedException(const ExtendedTypeInfo &ti)
: ReflectionException("comparison not permitted on type `" + std::string(ti.name()) + "'")
{
}
};
struct ComparisonOperatorNotSupportedException: ReflectionException
{
ComparisonOperatorNotSupportedException(const ExtendedTypeInfo &ti, const std::string& op)
: ReflectionException("comparison operator `" + op + "' is not supported on type `" + std::string(ti.name()) + "'")
{
}
};
}
#endif
|