summaryrefslogtreecommitdiff
path: root/src/core/script/Variant.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-10-20 23:22:56 +0000
committerandreas <andreas@daaaf23c-2e50-4459-9457-1e69db5a47bf>2014-10-20 23:22:56 +0000
commitc654793a3a513a9c8ffcd1aa9c3962b6a72e61bd (patch)
tree7f54a352a0c196dc85a3262783bb95183d3b1d40 /src/core/script/Variant.cpp
parent25fb41044ca080b794cbf4e85ff10e74e571ea24 (diff)
started to implement Function class which represents functions and methods, both on the host and the client side
git-svn-id: file:///var/local/svn/basicwriter@73 daaaf23c-2e50-4459-9457-1e69db5a47bf
Diffstat (limited to 'src/core/script/Variant.cpp')
-rw-r--r--src/core/script/Variant.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/core/script/Variant.cpp b/src/core/script/Variant.cpp
index a379735..b70f361 100644
--- a/src/core/script/Variant.cpp
+++ b/src/core/script/Variant.cpp
@@ -21,6 +21,49 @@
namespace ousia {
namespace script {
+/* Class VariantTypeException */
+
+static const char* getVariantTypeName(VariantType type)
+{
+ switch (type) {
+ case VariantType::null:
+ return "null";
+ case VariantType::boolean:
+ return "boolean";
+ case VariantType::integer:
+ return "integer";
+ case VariantType::number:
+ return "number";
+ case VariantType::string:
+ return "string";
+ case VariantType::array:
+ return "array";
+ case VariantType::map:
+ return "map";
+ case VariantType::function:
+ return "function";
+ case VariantType::object:
+ return "object";
+ case VariantType::buffer:
+ return "buffer";
+ }
+ return "unknown";
+}
+
+VariantTypeException::VariantTypeException(VariantType actualType,
+ VariantType requestedType) :
+ msg(std::string("Cannot get value of variant of type \"")
+ + getVariantTypeName(actualType)
+ + std::string("\" as \"") + getVariantTypeName(requestedType)),
+ actualType(actualType), requestedType(requestedType) {}
+
+const char* VariantTypeException::what() const noexcept
+{
+ return msg.c_str();
+}
+
+/* Global scope operator */
+
std::ostream& operator<< (std::ostream& os, const Variant &v)
{
switch (v.type) {