Permalink
Browse files

improve get and set attributes

  • Loading branch information...
1 parent 5323c33 commit d670257637722ddabaad2f45140ba9335280f202 @NotFound committed Jun 13, 2012
Showing with 32 additions and 2 deletions.
  1. +24 −1 winxedxx_classes.cxx
  2. +4 −1 winxedxx_default.cxx
  3. +4 −0 winxedxx_integer.h
View
@@ -218,7 +218,12 @@ WxxObjectPtr WxxClass::get_class()
WxxObjectPtr WxxClass::instantiate()
{
- return new WxxInstance(*this);
+ WxxInstance *instance = new WxxInstance(*this);
+ for (std::vector<std::string>::const_iterator it = attrs.begin();
+ it != attrs.end();
+ ++it)
+ instance->attributes.insert(std::make_pair(*it, winxedxxnull));
+ return instance;
}
WxxObjectPtr WxxClass::call_method(const std::string &methname, WxxObjectArray &args)
@@ -255,6 +260,24 @@ WxxObjectPtr WxxInstance::get_class()
return cl;
}
+WxxObjectPtr & WxxInstance::get_attr_str(const std::string &s)
+{
+ std::map<std::string, WxxObjectPtr>::iterator attr = attributes.find(s);
+ if (attr == attributes.end())
+ throw wxx_error("No such attribute '" + s + "'");
+ else
+ return attr->second;
+}
+
+void WxxInstance::set_attr_str(const std::string &s, const WxxObjectPtr &value)
+{
+ std::map<std::string, WxxObjectPtr>::iterator attr = attributes.find(s);
+ if (attr == attributes.end())
+ throw wxx_error("No such attribute '" + s + "'");
+ else
+ attr->second = value;
+}
+
WxxObjectPtr WxxInstance::call_method(const std::string &methname, WxxObjectArray &args)
{
WxxClass::memberfun fun = cl->getfunction(methname);
View
@@ -194,7 +194,10 @@ WxxObjectPtr & WxxDefault::get_attr_str(const std::string &s)
void WxxDefault::set_attr_str(const std::string &s, const WxxObjectPtr &value)
{
- attributes.insert(std::make_pair(s, value));
+ std::pair <std::map<std::string, WxxObjectPtr>::iterator, bool> found =
+ attributes.insert(std::make_pair(s, value));
+ if (! found.second)
+ found.first->second = value;
}
WxxObjectPtr WxxDefault::get_iter()
View
@@ -310,9 +310,13 @@ class WxxInstance : public WxxDefault
WxxInstance(WxxClass &cassobjl);
std::string class_name() const;
WxxObjectPtr get_class();
+ WxxObjectPtr & get_attr_str(const std::string &s);
+ void set_attr_str(const std::string &s, const WxxObjectPtr &value);
WxxObjectPtr call_method(const std::string &methname, WxxObjectArray &args);
private:
+ friend WxxObjectPtr WxxClass::instantiate();
WxxClass *cl;
+ std::map<std::string, WxxObjectPtr> attributes;
};
class WxxLibrary : public WxxDefault

0 comments on commit d670257

Please sign in to comment.