/*  This file was generated by the SOM Compiler and Emitter Framework.
 *  Generated using:
 *      SOM Emitter emitctm: 2.7
 */

#define Animal_Class_Source
#include <animal.ih>

/*
 * The name of the animal.
 */

SOM_Scope void  SOMLINK animal__set_name(Animal *somSelf, string myName)
{
    AnimalData *somThis = AnimalGetData(somSelf);
    AnimalMethodDebug("Animal","animal__set_name");

    if (_name)
        SOMFree(_name);
    if (myName) {
        _name = (string) SOMMalloc(strlen(myName) + 1);
        strcpy(_name, myName);
    } else
        _name = (string) NULL;

}

/*
 * The kind of sound that an animal makes.
 */

SOM_Scope void  SOMLINK animal__set_sound(Animal *somSelf, string mySound)
{
    AnimalData *somThis = AnimalGetData(somSelf);
    AnimalMethodDebug("Animal","animal__set_sound");

    if (_sound)
        SOMFree(_sound);
    if (mySound) {
        _sound = (string) SOMMalloc(strlen(mySound) + 1);
        strcpy(_sound, mySound);
    } else
        _sound = (string) NULL;

}

/*
 * The genus of animal.
 * The "_get_" method for this attribute should be overridden
 * by derived classes.  The default version here just gives
 * "<unknown>" as the genus.
 */

SOM_Scope string  SOMLINK animal__get_genus(Animal *somSelf)
{
    AnimalMethodDebug("Animal","animal__get_genus");

    return ("<Unknown>");
}

/*
 * The species of animal.
 * The "_get" method for this attribute should be overridden
 * by derived classes.  The default version here just gives
 * "<unknown>" as the species.
 */

SOM_Scope string  SOMLINK animal__get_species(Animal *somSelf)
{
    AnimalMethodDebug("Animal","animal__get_species");

    return ("<Unknown>");
}

/*
 * Ask the animal to talk.  Normally this just prints out the
 * string corresponding to the sound attribute, but it can be
 * overridden to do something else.
 */

SOM_Scope void  SOMLINK animal_talk(Animal *somSelf)
{
    AnimalData *somThis = AnimalGetData(somSelf);
    AnimalMethodDebug("Animal","animal_talk");

    somPrintf("\t%s\n", _sound ? _sound : "<Unknown>");
}

/*
 * Displays an animal.	Derived classes should override this to
 * display new derived information, and then call their parent
 * version. Note: this method makes use of talk() to describe what
 * the animal says.
 */

SOM_Scope void  SOMLINK animal_display(Animal *somSelf)
{
    AnimalMethodDebug("Animal","animal_display");

    somPrintf ("\nThe animal named %s", Animal__get_name (somSelf));
    somPrintf (" (Genus: %s,", Animal__get_genus (somSelf));
    somPrintf (" Species: %s) says:\n", Animal__get_species (somSelf));
    Animal_talk (somSelf);
}

SOM_Scope void  SOMLINK animal_somFree(Animal *somSelf)
{
    AnimalMethodDebug("Animal","animal_somFree");

    /* Reduce the animal population */
    Animal_parent_SOMObject_somFree(somSelf);
}

SOM_Scope void  SOMLINK animal_somInit(Animal *somSelf)
{
    AnimalData *somThis = AnimalGetData(somSelf);
    AnimalMethodDebug("Animal","animal_somInit");

    Animal_parent_SOMObject_somInit(somSelf);
    _sound = (string) NULL;
}

SOM_Scope void  SOMLINK animal_somUninit(Animal *somSelf)
{
    AnimalData *somThis = AnimalGetData(somSelf);
    AnimalMethodDebug("Animal","animal_somUninit");

    if (_sound)
        SOMFree (_sound);
    Animal_parent_SOMObject_somUninit(somSelf);
}

SOM_Scope void  SOMLINK animal_somDumpSelfInt(Animal *somSelf,
                                              long level)
{
    AnimalData *somThis = AnimalGetData(somSelf);
    AnimalMethodDebug("Animal","animal_somDumpSelfInt");

    Animal_display (somSelf);
    Animal_parent_SOMObject_somDumpSelfInt(somSelf, level);
}
