Permalink
Browse files

class_name method in internal classes and better message on method no…

…t found
  • Loading branch information...
1 parent 2a73710 commit 011c83d2e6bcb02aa2cb58df107384a64897d599 @NotFound committed Oct 25, 2011
Showing with 53 additions and 1 deletion.
  1. +13 −1 winxedxx.h
  2. +25 −0 winxedxx_classes.cxx
  3. +1 −0 winxedxx_default.h
  4. +3 −0 winxedxx_integer.h
  5. +1 −0 winxedxx_null.h
  6. +1 −0 winxedxx_object.h
  7. +8 −0 winxedxx_objectptr.cxx
  8. +1 −0 winxedxx_types.h
View
@@ -464,6 +464,7 @@ class WxxClass : public WxxDefault
typedef WxxObjectPtr (*memberfun)(WxxObjectPtr &, const WxxObjectArray &);
WxxClass(const std::string &name);
+ std::string class_name() const;
void addattribute(const std::string &attrname);
void addfunction(const std::string &fname, memberfun);
memberfun getfunction(const std::string &fname);
@@ -489,6 +490,11 @@ WxxClass::WxxClass(const std::string &name) :
reg[name] = this;
}
+std::string WxxClass::class_name() const
+{
+ return clname;
+}
+
void WxxClass::addattribute(const std::string &attrname)
{
attrs.push_back(attrname);
@@ -509,6 +515,7 @@ class WxxInstance : public WxxDefault
{
public:
WxxInstance(const std::string &clname);
+ std::string class_name() const;
WxxObjectPtr call_method(const std::string &methname, WxxObjectArray &args);
private:
WxxClass *cl;
@@ -522,6 +529,11 @@ WxxInstance::WxxInstance(const std::string &clname) :
throw wxx_error("class not found: " + clname);
}
+std::string WxxInstance::class_name() const
+{
+ return cl->class_name();
+}
+
WxxObjectPtr WxxInstance::call_method(const std::string &methname, WxxObjectArray &args)
{
WxxClass::memberfun fun = cl->getfunction(methname);
@@ -530,7 +542,7 @@ WxxObjectPtr WxxInstance::call_method(const std::string &methname, WxxObjectArra
return (*fun)(obj, args);
}
else
- throw wxx_error("method not found");
+ throw wxx_error("method '" + methname + "' not found in '" + class_name() + "'");
return winxedxxnull;
}
View
@@ -17,6 +17,11 @@ namespace WinxedXX
//*************************************************************
+std::string WxxNull::class_name() const
+{
+ return "Null";
+}
+
int WxxNull::is_null() const { return 1; }
int WxxNull::instanceof(const std::string &type)
@@ -187,6 +192,11 @@ WxxDefault::~WxxDefault()
//std::cerr << "~WxxDefault " << name << "\n";
}
+std::string WxxDefault::class_name() const
+{
+ return name;
+}
+
int WxxDefault::is_null() const
{ return 0; }
@@ -350,6 +360,11 @@ WxxInteger::WxxInteger(int value) : WxxDefault("Integer")
i = value;
}
+std::string WxxInteger::class_name() const
+{
+ return "Integer";
+}
+
int WxxInteger::get_integer() { return i; };
double WxxInteger::get_number() { return i; }
@@ -382,6 +397,11 @@ WxxFloat::WxxFloat(double value) : WxxDefault("Float")
n = value;
}
+std::string WxxFloat::class_name() const
+{
+ return "Float";
+}
+
int WxxFloat::get_integer() { return n; };
double WxxFloat::get_number() { return n; }
@@ -414,6 +434,11 @@ WxxString::WxxString(std::string value) : WxxDefault("String")
str = value;
}
+std::string WxxString::class_name() const
+{
+ return "String";
+}
+
std::string WxxString::get_string() { return str; }
WxxObject & WxxString::set(const char *s)
View
@@ -15,6 +15,7 @@ class WxxDefault : public WxxObject
WxxDefault(const std::string &name);
~WxxDefault();
public:
+ std::string class_name() const;
int is_null() const;
std::string getname() const;
int instanceof(const std::string &type);
View
@@ -14,6 +14,7 @@ class WxxInteger : public WxxDefault
{
public:
WxxInteger(int value);
+ std::string class_name() const;
int get_integer();
double get_number();
std::string get_string();
@@ -28,6 +29,7 @@ class WxxFloat : public WxxDefault
{
public:
WxxFloat(double value);
+ std::string class_name() const;
int get_integer();
double get_number();
std::string get_string();
@@ -42,6 +44,7 @@ class WxxString : public WxxDefault
{
public:
WxxString(std::string value);
+ std::string class_name() const;
std::string get_string();
WxxObject & set(const char *s);
WxxObject & set(const std::string &s);
View
@@ -11,6 +11,7 @@ namespace WinxedXX
class WxxNull : public WxxObject
{
public:
+ std::string class_name() const;
int is_null() const;
int instanceof(const std::string &type);
int get_bool();
View
@@ -11,6 +11,7 @@ class WxxObject
{
public:
virtual int is_null() const = 0;
+ virtual std::string class_name() const = 0;
virtual int instanceof(const std::string &type) = 0;
virtual int get_bool() = 0;
virtual int get_integer() = 0;
View
@@ -54,6 +54,14 @@ WxxObjectPtr::~WxxObjectPtr()
object->decref();
}
+std::string WxxObjectPtr::class_name() const
+{
+ if (object)
+ return object->class_name();
+ else
+ return "Null";
+}
+
WxxObjectPtr & WxxObjectPtr::set(int value)
{
object->set(value);
View
@@ -42,6 +42,7 @@ class WxxObjectPtr
WxxObjectPtr(const WxxObjectPtr &old);
WxxObjectPtr(WxxObject * obj);
~WxxObjectPtr();
+ std::string class_name() const;
WxxObjectPtr & set(int value);
WxxObjectPtr & set(double value);
WxxObjectPtr & set(const char *s);

0 comments on commit 011c83d

Please sign in to comment.