somDumpSelfInt
This method outputs the internal state of an object. Intended to be overridden by class implementors. Not intended to be directly invoked by object clients.
For backward compatibility, this method does not take an Environment parameter.
- Original Class
- SOMObject
Syntax
void somDumpSelfInt (SOMObject receiver, long level)
Parameters
- receiver (SOMObject)
- A pointer to the object to be dumped.
- level (long)
- The nesting level for describing compound objects. It must be greater than or equal to 0. All lines in the description should be preceded by "2* level" spaces.
Return Code
rc (void)
Remarks
The somDumpSelfInt method should be overridden by a class implementor, to write out the instance data stored in an object. This method is invoked by the somDumpSelf method, which is used by object clients to output the state of an object.
The procedure used to override this method for a new class should begin by calling the parent class form of this method on each of the class parents, and should then write a description of the instance variables introduced by new class. This will result in a description of all the class's instance variables. The C and C++ implementation bindings provide a convenient macro for performing parent method calls on all parents, as illustrated below.
The character output routine pointed to by SOMOutCharRoutine should be used for output. The somLPrintf function is especially convenient for this, since level is handled appropriately.
Example Code
Below is a method overriding somDumpSelfInt for class "List", which has two attributes, val (which is a long) and next (which is a pointer to a "List" object).
SOM_Scope void SOMLINK somDumpSelfInt(List somSelf, int level) { ListData *somThis = ListGetData(somSelf); Environment *ev = somGetGlobalEnvironment(); List_parents_somDumpSelfInt(somSelf, level); somLPrintf(level, "This item: %i\n", __get_val(somSelf, ev); somLPrintf(level, "Next item: \n"); if (__get_next(somSelf, ev) != (List) NULL) _somDumpSelfInt(__get_next(somSelf, ev), level+1); else somLPrintf(level+1, "NULL\n"); }
Below is a client program that invokes the somDumpSelf method on "List" objects.
#include <list.h> main() { List L1, L2; long x = 7, y = 13; Environment *ev = somGetGlobalEnvironment(); L1 = ListNew(); L2 = ListNew(); __set_val(L1, ev, x); __set_next(L1, ev, (List) NULL); __set_val(L2, ev, y); __set_next(L2, ev, L1); _somDumpSelf(L2,0); _somFree(L1); _somFree(L2); }
Below is the output produced by this program:
{An instance of class List at 0x2005EA8 This item: 13 Next item: 1 This item: 7 1 Next item: 2 NULL }