Object

Object – Nsp object data type

Description
The Object data type is the base class of Nsp objects.

Operations on Objects

attributes
Attributes values are obtained through the dot operator which can be used to get or set values. Note that, when implementing a class, attributes may be restricted to be non writable. When attributes are internally stored as nsp objects its is possible to implement attribute access compatible with set and get chaining rules as in Obj.attr(2,:)=56. It is also possible to overload the (.) operator in order to access to attributes. It is possible to obtain the attribute names of a given object with __attrs or using a method as described in next paragraph.
object methods

Some functions
All the nsp objects must implements a set of methods requested for all objects. Thus a set of interfaced function at nsp level can accept any object as argument. The interface just redirect the computation to the object method. This is used for object display (print, sprint, fprint, info, sinfo, finfo), for read/write operations (printf,…, scanf), for logical operations, for saving and loading objects (save, load, serialize), for obtaining size information on objects, ….

Examples

a=%types.ClassA.new[cla_color=89,cla_thickness=56]; 
// ClassA is a predefined toy class. 
is(a,%types.Mat)  
is(a,%types.ClassA)  
a.__attrs 
a.cla_color = 32  
a.cla_val = rand(2,2) 
a.cla_val(3,3) = 1; 
a.set[cla_val=1:5,cla_color=56] 
a('cla_color') = 78  
a.get_method_names[]; 
// ClassB is a predefined toy class which inherits from ClassA 
b=%types.ClassB.new[cla_color=89,cla_thickness=56]; 
b.get_attribute_names[]; 
is(b,%types.ClassA)  
is(b,%types.ClassB)  
test(b);  

See also