Skip to content

Commit

Permalink
class_name method in internal classes and better message on method no…
Browse files Browse the repository at this point in the history
…t found
  • Loading branch information
NotFound committed Oct 25, 2011
1 parent 2a73710 commit 011c83d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 1 deletion.
14 changes: 13 additions & 1 deletion winxedxx.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ class WxxClass : public WxxDefault
typedef WxxObjectPtr (*memberfun)(WxxObjectPtr &, const WxxObjectArray &); typedef WxxObjectPtr (*memberfun)(WxxObjectPtr &, const WxxObjectArray &);


WxxClass(const std::string &name); WxxClass(const std::string &name);
std::string class_name() const;
void addattribute(const std::string &attrname); void addattribute(const std::string &attrname);
void addfunction(const std::string &fname, memberfun); void addfunction(const std::string &fname, memberfun);
memberfun getfunction(const std::string &fname); memberfun getfunction(const std::string &fname);
Expand All @@ -489,6 +490,11 @@ WxxClass::WxxClass(const std::string &name) :
reg[name] = this; reg[name] = this;
} }


std::string WxxClass::class_name() const
{
return clname;
}

void WxxClass::addattribute(const std::string &attrname) void WxxClass::addattribute(const std::string &attrname)
{ {
attrs.push_back(attrname); attrs.push_back(attrname);
Expand All @@ -509,6 +515,7 @@ class WxxInstance : public WxxDefault
{ {
public: public:
WxxInstance(const std::string &clname); WxxInstance(const std::string &clname);
std::string class_name() const;
WxxObjectPtr call_method(const std::string &methname, WxxObjectArray &args); WxxObjectPtr call_method(const std::string &methname, WxxObjectArray &args);
private: private:
WxxClass *cl; WxxClass *cl;
Expand All @@ -522,6 +529,11 @@ WxxInstance::WxxInstance(const std::string &clname) :
throw wxx_error("class not found: " + 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) WxxObjectPtr WxxInstance::call_method(const std::string &methname, WxxObjectArray &args)
{ {
WxxClass::memberfun fun = cl->getfunction(methname); WxxClass::memberfun fun = cl->getfunction(methname);
Expand All @@ -530,7 +542,7 @@ WxxObjectPtr WxxInstance::call_method(const std::string &methname, WxxObjectArra
return (*fun)(obj, args); return (*fun)(obj, args);
} }
else else
throw wxx_error("method not found"); throw wxx_error("method '" + methname + "' not found in '" + class_name() + "'");
return winxedxxnull; return winxedxxnull;
} }


Expand Down
25 changes: 25 additions & 0 deletions winxedxx_classes.cxx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace WinxedXX


//************************************************************* //*************************************************************


std::string WxxNull::class_name() const
{
return "Null";
}

int WxxNull::is_null() const { return 1; } int WxxNull::is_null() const { return 1; }


int WxxNull::instanceof(const std::string &type) int WxxNull::instanceof(const std::string &type)
Expand Down Expand Up @@ -187,6 +192,11 @@ WxxDefault::~WxxDefault()
//std::cerr << "~WxxDefault " << name << "\n"; //std::cerr << "~WxxDefault " << name << "\n";
} }


std::string WxxDefault::class_name() const
{
return name;
}

int WxxDefault::is_null() const int WxxDefault::is_null() const
{ return 0; } { return 0; }


Expand Down Expand Up @@ -350,6 +360,11 @@ WxxInteger::WxxInteger(int value) : WxxDefault("Integer")
i = value; i = value;
} }


std::string WxxInteger::class_name() const
{
return "Integer";
}

int WxxInteger::get_integer() { return i; }; int WxxInteger::get_integer() { return i; };


double WxxInteger::get_number() { return i; } double WxxInteger::get_number() { return i; }
Expand Down Expand Up @@ -382,6 +397,11 @@ WxxFloat::WxxFloat(double value) : WxxDefault("Float")
n = value; n = value;
} }


std::string WxxFloat::class_name() const
{
return "Float";
}

int WxxFloat::get_integer() { return n; }; int WxxFloat::get_integer() { return n; };


double WxxFloat::get_number() { return n; } double WxxFloat::get_number() { return n; }
Expand Down Expand Up @@ -414,6 +434,11 @@ WxxString::WxxString(std::string value) : WxxDefault("String")
str = value; str = value;
} }


std::string WxxString::class_name() const
{
return "String";
}

std::string WxxString::get_string() { return str; } std::string WxxString::get_string() { return str; }


WxxObject & WxxString::set(const char *s) WxxObject & WxxString::set(const char *s)
Expand Down
1 change: 1 addition & 0 deletions winxedxx_default.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class WxxDefault : public WxxObject
WxxDefault(const std::string &name); WxxDefault(const std::string &name);
~WxxDefault(); ~WxxDefault();
public: public:
std::string class_name() const;
int is_null() const; int is_null() const;
std::string getname() const; std::string getname() const;
int instanceof(const std::string &type); int instanceof(const std::string &type);
Expand Down
3 changes: 3 additions & 0 deletions winxedxx_integer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class WxxInteger : public WxxDefault
{ {
public: public:
WxxInteger(int value); WxxInteger(int value);
std::string class_name() const;
int get_integer(); int get_integer();
double get_number(); double get_number();
std::string get_string(); std::string get_string();
Expand All @@ -28,6 +29,7 @@ class WxxFloat : public WxxDefault
{ {
public: public:
WxxFloat(double value); WxxFloat(double value);
std::string class_name() const;
int get_integer(); int get_integer();
double get_number(); double get_number();
std::string get_string(); std::string get_string();
Expand All @@ -42,6 +44,7 @@ class WxxString : public WxxDefault
{ {
public: public:
WxxString(std::string value); WxxString(std::string value);
std::string class_name() const;
std::string get_string(); std::string get_string();
WxxObject & set(const char *s); WxxObject & set(const char *s);
WxxObject & set(const std::string &s); WxxObject & set(const std::string &s);
Expand Down
1 change: 1 addition & 0 deletions winxedxx_null.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace WinxedXX
class WxxNull : public WxxObject class WxxNull : public WxxObject
{ {
public: public:
std::string class_name() const;
int is_null() const; int is_null() const;
int instanceof(const std::string &type); int instanceof(const std::string &type);
int get_bool(); int get_bool();
Expand Down
1 change: 1 addition & 0 deletions winxedxx_object.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class WxxObject
{ {
public: public:
virtual int is_null() const = 0; virtual int is_null() const = 0;
virtual std::string class_name() const = 0;
virtual int instanceof(const std::string &type) = 0; virtual int instanceof(const std::string &type) = 0;
virtual int get_bool() = 0; virtual int get_bool() = 0;
virtual int get_integer() = 0; virtual int get_integer() = 0;
Expand Down
8 changes: 8 additions & 0 deletions winxedxx_objectptr.cxx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ WxxObjectPtr::~WxxObjectPtr()
object->decref(); object->decref();
} }


std::string WxxObjectPtr::class_name() const
{
if (object)
return object->class_name();
else
return "Null";
}

WxxObjectPtr & WxxObjectPtr::set(int value) WxxObjectPtr & WxxObjectPtr::set(int value)
{ {
object->set(value); object->set(value);
Expand Down
1 change: 1 addition & 0 deletions winxedxx_types.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WxxObjectPtr
WxxObjectPtr(const WxxObjectPtr &old); WxxObjectPtr(const WxxObjectPtr &old);
WxxObjectPtr(WxxObject * obj); WxxObjectPtr(WxxObject * obj);
~WxxObjectPtr(); ~WxxObjectPtr();
std::string class_name() const;
WxxObjectPtr & set(int value); WxxObjectPtr & set(int value);
WxxObjectPtr & set(double value); WxxObjectPtr & set(double value);
WxxObjectPtr & set(const char *s); WxxObjectPtr & set(const char *s);
Expand Down

0 comments on commit 011c83d

Please sign in to comment.