INSTANCE Item Attributes

From STX Wiki
< Programmer Guide‎ | Shell Items‎ | Instance
Revision as of 11:59, 8 November 2016 by Toni (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
Instance Item
NEW SET ATTRIBUTES

The following instance attributes are available.

!BASE

The !BASE attribute returns the name of the instance's base class, or an empty string if the instance is not derived from any class.

!CLASS

The !CLASS attribute returns the name of the instance's class.

!INSTANCEOF

The !INSTANCEOF instance attribute will return 1 if its argument is the name of a class from which the respective instance is derived. It will return 0 otherwise. See the example macro reflection.sts for a working example.


!IS_A

The !IS_A instance attribute will return 1 if the respective item is (directly or indirectly) derived from the class of the instance item supplied as the argument to !IS_A. It will return 0 otherwise. E.g.:

#butterfly := cobj new butterfly
if '$#butterfly[!is_a,insect]' == 1 then
   conlog 'class butterfly derived from insect'
else
   conlog 'class butterfly not derived from insect'
end
!MEMBER

The !MEMBER attribute returns the type of the member function specified in the first parameter. E.g:

$#instance[!member,myfunction]

This call will return the type of the function myfunction.

Possible types are:

public|protected|private or an empty string.

!PARENT

The !PARENT attribute returns the name of the instance's parent class or an empty string if the instance's class is not derived from another class.

!REFLECT

The !REFLECT attribute returns a blank separated list of methods implemented in the instance's class. The attribute can take three parameters:

$#instance[!reflect,wherefrom,format,access]

where

"wherefrom" is one of the keywords "all", "inherited", "trulyinherited", "overloaded" and "own". When using "own", you will get only the methods directly specified in the respective class. When using "inherited", you will get only methods inherited by the respective class. And, finally, when specifying "all" (which, by the way, is the default when omitted), you will get all methods of the respective class, including, but not restricted to, inherited methods. When using "trulyinherited", the "!REFLECT" instance item attribute will return a list of functions truly inherited by the respective class, i.e. of functions which are inherited but not overloaded. When, on the other hand, using "overloaded", you will only get a list of inherited functions that are overloaded by the respective class.

"format" is one of the keywords "prefixed", "scoped", "noprefix", and "unprefixed". When specifying either "prefixed" or "scoped" (they are synonymous), you will get the names of the methods including their access prefix, e.g. "public_testfunction" or "protected_myfunction". If, on the other hand, you use "noprefix" or "unprefixed", you will get the name of the methods naked, i.e. without any prefix. This, if you omit this argument, is default.

"access" is one of the keywords "public", "protected", "private", and "all". When either omitting this argument altogether or using "all", you will get all the appropriate methods regardless of their protection. When, on the other hand, specifying one out of "public", "protected", and "private", you will get only those methods which are public, protected, or private, respectively.

You may consider to have a look at the fine example script "reflection.sts".

For example, to get the list of all functions of instance #hugo, all you need to do is the following:

#list := $#hugo[!reflect]

If you are not interested in inherited methods, what you want to do is the following:

#list := $#hugo[!reflect,own]

!SHELL

The !SHELL attribute returns the id of the shell which created the instance.

!USERS

The !USERS attribute returns the number of linked items sharing the instance item.

!VARIABLE

The !VARIABLE attribute returns the value of the instance variable specified. E.g.:

$#instance[!variable,myvariable]

or

$#instance[!variable,&myvariable]

The class variable prefix character & is assumed, if not specified, and is therefor optional.

Navigation menu

Personal tools