Simple Dynamic Loader Library Documentation (v. 1.1.0)
Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

sdl::Object Class Reference

proxy for an object of a dynamically-loaded class More...

#include <maindoc.h>

List of all members.

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.


Detailed Description

proxy for an object of a dynamically-loaded class

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;
}


Member Function Documentation

virtual void sdl::Object::assign const string &  ,
void * 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an void * value to this data member

Exceptions:
TypeMismatch if this is not a data member of type void *.

virtual void sdl::Object::assign const string &  ,
const char * 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign a const char * value to this data member

Exceptions:
TypeMismatch if this is not a data member of type const char * or string.

virtual void sdl::Object::assign const string &  ,
char * 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an char * value to this data member

Exceptions:
TypeMismatch if this is not a data member of type char *, const char * or string.

virtual void sdl::Object::assign const string &  ,
const string & 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an const string & value to this data member

Exceptions:
TypeMismatch if this is not a data member of type const string &.

virtual void sdl::Object::assign const string &  ,
double 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an double value to this data member

Exceptions:
TypeMismatch if this is not a data member of type double.

virtual void sdl::Object::assign const string &  ,
float 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an float value to this data member

Exceptions:
TypeMismatch if this is not a data member of type float or double.

virtual void sdl::Object::assign const string &  ,
bool 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an bool value to this data member

Exceptions:
TypeMismatch if this is not a data member of type bool.

virtual void sdl::Object::assign const string &  ,
long 
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an long value to this data member

Exceptions:
TypeMismatch if this is not a data member of type long.

virtual void sdl::Object::assign const string &  name,
char  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an char value to this data member

Parameters:
name name of the member function.
x value assigned to data member.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if the given name identifies a member other than a data member of type char, int, or long.

virtual void sdl::Object::assign const string &  name,
int  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

assign an int value to this data member

Parameters:
name name of the data member.
x value assigned to data member.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if this is not a data member of type int or long.

virtual bool& sdl::Object::bool_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as bool reference

Exceptions:
TypeMismatch if this is not a bool data member

virtual bool sdl::Object::bool_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as bool value

Exceptions:
TypeMismatch if this is not a bool data member

virtual void sdl::Object::call const string &  name,
void *  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with void * argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if this is not a member function taking a parameter of type void *.

virtual void sdl::Object::call const string &  name,
const char *  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with const char * argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if this is not a member function taking a parameter of type const char *.

virtual void sdl::Object::call const string &  name,
const string &  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with const string & argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if this is not a member function taking a parameter of type const string &.

virtual void sdl::Object::call const string &  name,
double  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with double argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if this is not a member function taking a parameter of type double.

virtual void sdl::Object::call const string &  name,
float  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with float argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if this is not a member function taking a parameter of type float or double.

virtual void sdl::Object::call const string &  name,
bool  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with bool argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if this is not a member function taking a parameter of type bool.

virtual void sdl::Object::call const string &  name,
long  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with long argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if the given name is not bound to a member function taking a parameter of type long.

virtual void sdl::Object::call const string &  name,
char  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls this member function with char argument

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if the given name is not bound to a member function taking one parameter of type char, * int, or long.

virtual void sdl::Object::call const string &  name,
int  x
const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls a member function with int argument.

Parameters:
name name of the member function.
x parameter passed to the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if the given name is not bound to a member function with no parameters.

virtual void sdl::Object::call const string &  name  )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

calls a member function without arguments.

Parameters:
name name of the member function.
Exceptions:
UnknownMember if the given name does not identify any member function or data member.
TypeMismatch if the requested member function or data member exist, but it is not a member function without arguments.

virtual char& sdl::Object::char_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as char reference

Exceptions:
TypeMismatch if this is not a char data member

virtual char* & sdl::Object::char_p_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as a C-string reference

Exceptions:
TypeMismatch if this is not a char * data member

virtual char* sdl::Object::char_p_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as a C-string value

Exceptions:
TypeMismatch if this is not a char * data member

virtual char sdl::Object::char_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as char value

Exceptions:
TypeMismatch if this is not a char data member

virtual const char* & sdl::Object::const_char_p_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as a const C-string reference

Exceptions:
TypeMismatch if this is not a const char * data member

virtual const char* sdl::Object::const_char_p_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as a const C-string value

Exceptions:
TypeMismatch if this is not a const char * data member

virtual const string& sdl::Object::const_string_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as char * reference

Exceptions:
TypeMismatch if this is not a char * data member

virtual double& sdl::Object::double_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as double reference

Exceptions:
TypeMismatch if this is not a double data member

virtual double sdl::Object::double_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as double value

Exceptions:
TypeMismatch if this is not a double data member

virtual float& sdl::Object::float_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as float reference

Exceptions:
TypeMismatch if this is not a float data member

virtual float sdl::Object::float_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as float value

Exceptions:
TypeMismatch if this is not a float data member

virtual int& sdl::Object::int_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as int reference

Exceptions:
TypeMismatch if this is not a int data member

virtual int sdl::Object::int_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as int value

Exceptions:
TypeMismatch if this is not a int data member

virtual long& sdl::Object::long_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as long reference

Exceptions:
TypeMismatch if this is not a long data member

virtual long sdl::Object::long_value const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as long value

Exceptions:
TypeMismatch if this is not a long data member

virtual string& sdl::Object::string_attribute const string &   )  const throw (TypeMismatch, UnknownMember) [pure virtual]
 

access member as string reference

Exceptions:
TypeMismatch if this is not a string data member


The documentation for this class was generated from the following file: