# # $Id: object.icn,v 1.2 2004-02-12 17:07:56 rparlett Exp $ # # This file is in the public domain. # # Author: Robert Parlett (parlett@dial.pipex.com) # package lang class Object() # # Clone the object. # method clone(seen) return lang::object_clone(self, seen) end # # Return a string representation of the oject. # method to_string(depth, seen) return lang::object_to_string(self, depth, seen) end # # Test equality of this object with another # method equals(other, seen) return lang::object_equals(self, other, seen) end # # Return a hash code for the object # method hash_code(depth, seen) return lang::object_hash_code(self, depth, seen) end # # Return the class name as a string, e.g. lang__Object. # This method is deprecated. Consider using method className(). # method get_class_name() return lang::get_class_name(self) end # # Return the class instance number # method get_id() return lang::get_id(self) end # # Get the Class object for this object # method get_class() return lang::get_class(self) end # # Succeed if and only if this object is an instance of class with the # given name. # This method is deprecated. Consider using method instanceOf(). # method is_instance(name) return lang::is_instance(self, name) end # UniLib annexation of 2017. #
# <[Generates the name of the current class followed by all classes # that it inherits from.]> #
method Type() suspend lang::Type(self) end ## Is this class a subclass of another one? # <[returns the class if it's an instance of superClassname]> # <[fails otherwise]> #
method instanceOf(superClassname) # class name to check as superclass return lang::instanceof(self, superClassname) end ## <[returns the classname for the current class in package::class format]> #
method className() return Type() end ## Invoke a class method by name. # <[returns the outcome of the invocation]> # <[fails if no method exists with that name]> #
method invoke(mName, # Name of method to call args[]) # Remaining arguments are arguments to call if hasMethod(mName) then { suspend (self.__m[mName]) ! push(args, self) } end ## Produce the value of the named field. Fails if no such field. # <[returns the value of the fName field]> #
method getField(fName) # name of field if hasField(fName) then { return self[fName] } end ## Set the value of the named field. # <[returns value]> # <[fails if no field fName]> #
method setField(fName, # name of field value) # value to set field to if hasField(fName) then { return .(self[fName] := value) } end ## Does this class have a specific field? # <[returns fName]> # <[fails if no field fName]> #
method hasField(fName) # name of possible field return \fName == fieldNames() end ## <[generates the names of all fields]> #
method fieldNames() every ::name(self[3 to *self]) ? { &pos := upto('.')+1 suspend tab(0) } end ## What methods are available for this class? # <[generates the names of all methods]> #
method genMethods() suspend fieldnames(self.__m) end ## Does this class have a specific method? # <[returns mName]> # <[fails if no method mName exists]> #
method hasMethod(mName) # Method name to check for. return mName == genMethods() end end