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


[Back: somDumpSelfInt - Related Methods]
[Next: somDumpSelfInt - Topics]