diff options
Diffstat (limited to 'fluid/nodes')
| -rw-r--r-- | fluid/nodes/Function_Node.cxx | 15 | ||||
| -rw-r--r-- | fluid/nodes/Function_Node.h | 16 | ||||
| -rw-r--r-- | fluid/nodes/Node.cxx | 13 | ||||
| -rw-r--r-- | fluid/nodes/Node.h | 3 |
4 files changed, 33 insertions, 14 deletions
diff --git a/fluid/nodes/Function_Node.cxx b/fluid/nodes/Function_Node.cxx index 3e98a898f..42c3f3996 100644 --- a/fluid/nodes/Function_Node.cxx +++ b/fluid/nodes/Function_Node.cxx @@ -1513,7 +1513,6 @@ Class_Node Class_Node::prototype; */ Class_Node::Class_Node() : Node(), - subclass_of(nullptr), public_(1) { } @@ -1521,8 +1520,6 @@ Class_Node::Class_Node() : Destructor. */ Class_Node::~Class_Node() { - if (subclass_of) - free((void*)subclass_of); } /** @@ -1549,7 +1546,7 @@ Node *Class_Node::make(Strategy strategy) { Class_Node *o = new Class_Node(); o->name("UserInterface"); o->prefix(""); - o->subclass_of = nullptr; + o->base_class(""); o->public_ = 1; o->add(anchor, strategy); o->factory = this; @@ -1563,9 +1560,9 @@ Node *Class_Node::make(Strategy strategy) { */ void Class_Node::write_properties(fld::io::Project_Writer &f) { Node::write_properties(f); - if (subclass_of) { + if (!base_class().empty()) { f.write_string(":"); - f.write_word(subclass_of); + f.write_word(base_class().c_str()); } switch (public_) { case 0: f.write_string("private"); break; @@ -1582,7 +1579,7 @@ void Class_Node::read_property(fld::io::Project_Reader &f, const char *c) { } else if (!strcmp(c,"protected")) { public_ = 2; } else if (!strcmp(c,":")) { - storestring(f.read_word(), subclass_of); + base_class(f.read_word()); } else { Node::read_property(f, c); } @@ -1608,7 +1605,9 @@ void Class_Node::write_code1(fld::io::Code_Writer& f) { f.write_h("class %s %s ", prefix().c_str(), name()); else f.write_h("class %s ", name()); - if (subclass_of) f.write_h(": %s ", subclass_of); + if (!base_class().empty()) { + f.write_h(": %s ", base_class().c_str()); + } f.write_h("{\n"); } diff --git a/fluid/nodes/Function_Node.h b/fluid/nodes/Function_Node.h index 282f33312..33bcc1849 100644 --- a/fluid/nodes/Function_Node.h +++ b/fluid/nodes/Function_Node.h @@ -271,9 +271,9 @@ public: typedef Node super; static Class_Node prototype; private: - const char* subclass_of; - char public_; + std::string base_class_; std::string prefix_; + char public_; public: Class_Node(); ~Class_Node(); @@ -294,16 +294,20 @@ public: bool is_a(Type inType) const override { return (inType==Type::Class) ? true : super::is_a(inType); } void write_properties(fld::io::Project_Writer &f) override; void read_property(fld::io::Project_Reader &f, const char *) override; - const char* base_class_name() { return subclass_of; } - void base_class_name(const char* name) { storestring(name, subclass_of); } + + /** Get base class access and name. */ + std::string base_class() { return base_class_; } + /** Set base class access and name, i.e. `public Fl_Widget`. */ + void base_class(const std::string& name) { storestring(name, base_class_); } + char visibility() { return public_; } void visibility(char v) { public_ = v; } // class prefix attribute access - /** Set the text between `class` and the class name */ - void prefix(const std::string& p) { prefix_ = p; } /** Get the text between `class` and the class name */ std::string prefix() const { return prefix_; } + /** Set the text between `class` and the class name */ + void prefix(const std::string& p) { prefix_ = p; } }; #endif // FLUID_NODES_FUNCTION_NODE_H diff --git a/fluid/nodes/Node.cxx b/fluid/nodes/Node.cxx index 7557e61f4..a84528b59 100644 --- a/fluid/nodes/Node.cxx +++ b/fluid/nodes/Node.cxx @@ -455,6 +455,19 @@ int storestring(const char *n, const char * & p, int nostrip) { return 1; } +// C++11 version, still using the original to copy all the side effects. +int storestring(const std::string& n, std::string& p, int nostrip) { + const char *buffer { nullptr }; + int ret = storestring(n.c_str(), buffer); + if (buffer) { + p = buffer; + free((void*)buffer); + } else { + p.clear(); + } + return ret; +} + /** Update the `visible` flag for `p` and all its descendants. \param[in] p start here and update all descendants */ diff --git a/fluid/nodes/Node.h b/fluid/nodes/Node.h index f6fce09b4..900addc6b 100644 --- a/fluid/nodes/Node.h +++ b/fluid/nodes/Node.h @@ -22,6 +22,8 @@ #include <FL/Fl_Widget.H> #include <FL/fl_draw.H> +#include <string> + class Node; class Group_Node; class Window_Node; @@ -113,6 +115,7 @@ enum class Type { void update_visibility_flag(Node *p); void delete_all(int selected_only=0); int storestring(const char *n, const char * & p, int nostrip=0); +int storestring(const std::string& n, std::string& p, int nostrip=0); void select_all_cb(Fl_Widget *,void *); void select_none_cb(Fl_Widget *,void *); |
