#include <maindoc.h>
Public Member Functions | |
virtual void * | this_pointer () const =0 |
returns a pointer to the actual object wrapped by this object. | |
method-call methods | |
These methods forward method calls to the wrapped object. | |
virtual void | call (const string &name) const =0 throw (TypeMismatch, UnknownMember) |
calls a member function without arguments. | |
virtual void | call (const string &name, int x) const =0 throw (TypeMismatch, UnknownMember) |
calls a member function with int argument. | |
virtual void | call (const string &name, char x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with char argument | |
virtual void | call (const string &name, long x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with long argument | |
virtual void | call (const string &name, bool x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with bool argument | |
virtual void | call (const string &name, float x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with float argument | |
virtual void | call (const string &name, double x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with double argument | |
virtual void | call (const string &name, const string &x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with const string & argument | |
virtual void | call (const string &name, const char *x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with const char * argument | |
virtual void | call (const string &name, void *x) const =0 throw (TypeMismatch, UnknownMember) |
calls this member function with void * argument | |
assignment methods | |
These methods allow the user to assign values to a data member of the dynamic object. | |
virtual void | assign (const string &name, int x) const =0 throw (TypeMismatch, UnknownMember) |
assign an int value to this data member | |
virtual void | assign (const string &name, char x) const =0 throw (TypeMismatch, UnknownMember) |
assign an char value to this data member | |
virtual void | assign (const string &, long) const =0 throw (TypeMismatch, UnknownMember) |
assign an long value to this data member | |
virtual void | assign (const string &, bool) const =0 throw (TypeMismatch, UnknownMember) |
assign an bool value to this data member | |
virtual void | assign (const string &, float) const =0 throw (TypeMismatch, UnknownMember) |
assign an float value to this data member | |
virtual void | assign (const string &, double) const =0 throw (TypeMismatch, UnknownMember) |
assign an double value to this data member | |
virtual void | assign (const string &, const string &) const =0 throw (TypeMismatch, UnknownMember) |
assign an const string & value to this data member | |
virtual void | assign (const string &, char *) const =0 throw (TypeMismatch, UnknownMember) |
assign an char * value to this data member | |
virtual void | assign (const string &, const char *) const =0 throw (TypeMismatch, UnknownMember) |
assign a const char * value to this data member | |
virtual void | assign (const string &, void *) const =0 throw (TypeMismatch, UnknownMember) |
assign an void * value to this data member | |
access methods by reference | |
These methods give direct access to data members of the dynamic object. Direct access means access by reference to data members. | |
virtual int & | int_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as int reference | |
virtual char & | char_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as char reference | |
virtual long & | long_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as long reference | |
virtual bool & | bool_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as bool reference | |
virtual double & | double_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as double reference | |
virtual float & | float_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as float reference | |
virtual char *& | char_p_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as a C-string reference | |
virtual const char *& | const_char_p_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as a const C-string reference | |
virtual string & | string_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as string reference | |
virtual const string & | const_string_attribute (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as char * reference | |
access methods by value | |
These methods give "read-only" access to data members of the dynamic object. | |
virtual int | int_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as int value | |
virtual char | char_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as char value | |
virtual long | long_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as long value | |
virtual bool | bool_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as bool value | |
virtual double | double_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as double value | |
virtual float | float_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as float value | |
virtual char * | char_p_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as a C-string value | |
virtual const char * | const_char_p_value (const string &) const =0 throw (TypeMismatch, UnknownMember) |
access member as a const C-string value | |
direct access to the internal "dynamic" object | |
Member | member (const string &name) const throw () |
returns a proxy object for the given data member or member function. |
Object
provides access to data members and member functions of an object of a dynamically-loaded class. Instances (i.e., objects) of the Object
class are constructed through a Class object represeting the dynamically-loaded class, by calling one of the "constructor" methods on that Class object.
An object of this class wraps an object of the dynamically-loaded class, and allows one to call methods or assign data members of that object. For example:
// // create dynamic class and instantiates an object // Class * employee_class = load_class("Employee", "employee.so"); Object * joe = employee_class.new_object("Joe"); // // access data members and call methods on that object // joe->assign("salary", 120); joe->call("add_project", "Testing SDL"); cout << "Joe's salary is " << joe->int_attribute("salary") << endl;
A data member of a n object of a dynamically-loaded class can be assigned values through one of the assign() methods of the Object class, but it can also be accessed directly through the attribute methods of Object. In the above example the int_attribute method is used, consistently with the type of the attribute. Notice that int_attribute returns a reference to the requested data member, and can therefore be used as the left-hand side of an assignment, as in the following example:
// // access data members and call methods on that object // joe->int_attribute("salary") = 120; cout << "Joe's salary is " << joe->int_attribute("salary") << endl;
Also, notice that in order to access a given data member, the user program must know both the name and type of that data member. This is because no static type information can be available for dynamically-loaded classes. Thus, the type of the attribute is "encoded" in the name of the access method (e.g., int_attribute(), float_attribute(), etc.). If the attribute does not need to be used as a reference (e.g., as the left-hand side of an assignment), then a more flexible way to access its value is through the "value" access methods int_attribute(), float_attribute(), etc. These access methods allow for a more relaxed type-checking. So, for example, if the actual type of a data member is string
, then its value can be accessed as a string
through string_attribute() or as a const char *
through {const_char_p_value}().
In any case, the above access methods must explicitly request a type. An access method that does not require an explicit type request is given by the member method through the Member class. This class offers a more uniform and convenient way to access data members and member functions of an object of a dynamically-loaded class. For example:
joe->member("salary") = 120; joe->member("add_project")("Siena");
See the documentation of the Member class for more details on this access mechanism.
A wrapper object can also return the pointer to the actual object contained in it through the this_pointer() method. Because the Object wrapper is generic, this_pointer() must return a generic (void) pointer. However, if the user application knows the type (or a supertype) of the dynamically-loaded class, it can easily cast it to its actual type, and use the properties of the dynamic object directly. For example:
#include "Person.h" // // load the dynamic class "Employee" and instantiates an object // Class * employee_class = load_class("Employee", "employee.so"); Object * joe = employee_class.new_object("Joe"); // // the "Employee" class is known to be of type Person, so... // Person * p = dynamic_cast<Person *>(joe->this_pointer()); if (p == 0) { cerr << "Error: the 'Employee' class is not of type Person!" << endl; } else { cout << "Joe is " << p->age << endl; }
|
assign an void * value to this data member
|
|
assign a const char * value to this data member
|
|
assign an char * value to this data member
|
|
assign an const string & value to this data member
|
|
assign an double value to this data member
|
|
assign an float value to this data member
|
|
assign an bool value to this data member
|
|
assign an long value to this data member
|
|
assign an char value to this data member
|
|
assign an int value to this data member
|
|
access member as bool reference
|
|
access member as bool value
|
|
calls this member function with void * argument
|
|
calls this member function with const char * argument
|
|
calls this member function with const string & argument
|
|
calls this member function with double argument
|
|
calls this member function with float argument
|
|
calls this member function with bool argument
|
|
calls this member function with long argument
|
|
calls this member function with char argument
|
|
calls a member function with int argument.
|
|
calls a member function without arguments.
|
|
access member as char reference
|
|
access member as a C-string reference
|
|
access member as a C-string value
|
|
access member as char value
|
|
access member as a const C-string reference
|
|
access member as a const C-string value
|
|
access member as char * reference
|
|
access member as double reference
|
|
access member as double value
|
|
access member as float reference
|
|
access member as float value
|
|
access member as int reference
|
|
access member as int value
|
|
access member as long reference
|
|
access member as long value
|
|
access member as string reference
|