
// @(#) 1.3 com/src/samples/utils/iodlink.cpp, odutilspart, od96nt, odnt9712d 10/2/96 16:26:23 [ 3/21/97 17:37:49 ]
//#====START_GENERATED_PROLOG======================================
//#
//#
//#   COMPONENT_NAME: odsamples
//#
//#   CLASSES: none
//#
//#   ORIGINS: 27
//#
//#
//#   (C) COPYRIGHT International Business Machines Corp. 1995,1996
//#   All Rights Reserved
//#   Licensed Materials - Property of IBM
//#   US Government Users Restricted Rights - Use, duplication or
//#   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//#
//#   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
//#   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//#   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
//#   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
//#   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
//#   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
//#   OR PERFORMANCE OF THIS SOFTWARE.
//#
//#====END_GENERATED_PROLOG========================================
//#
/*
 *  This file was generated by the SOM Compiler and Emitter Framework.
 *  Generated using: 
 *      SOM Emitter emitxtm.dll: Development
 */

#ifndef SOM_Module_iodlink_Source
#define SOM_Module_iodlink_Source
#endif
#define IODLink_Class_Source
#define IODLinkedList_Class_Source
#define VARIABLE_MACROS
#define METHOD_MACROS

#include <ODTypes.h>
#include "iodlink.xih"


SOM_Scope ODPtr  SOMLINK IODLinkContent(IODLink *somSelf,  Environment *ev)
{
    IODLinkData *somThis = IODLinkGetData(somSelf);
    IODLinkMethodDebug("IODLink","IODLinkContent");

    return _fContent;
}

SOM_Scope IODLink*  SOMLINK IODLinkNext(IODLink *somSelf,  Environment *ev)
{
    IODLinkData *somThis = IODLinkGetData(somSelf);
    IODLinkMethodDebug("IODLink","IODLinkNext");

    return _fNext;
}

SOM_Scope void  SOMLINK IODLinksetContent(IODLink *somSelf,  Environment *ev, 
                                          ODPtr content)
{
    IODLinkData *somThis = IODLinkGetData(somSelf);
    IODLinkMethodDebug("IODLink","IODLinksetContent");

    _fContent = content;
}

SOM_Scope void  SOMLINK IODLinksetNext(IODLink *somSelf,  Environment *ev, 
                                       IODLink* next)
{
    IODLinkData *somThis = IODLinkGetData(somSelf);
    IODLinkMethodDebug("IODLink","IODLinksetNext");

    _fNext = next;
}

SOM_Scope void  SOMLINK IODLinksomInit(IODLink *somSelf)
{
    IODLinkData *somThis = IODLinkGetData(somSelf);
    IODLinkMethodDebug("IODLink","IODLinksomInit");

    IODLink_parent_ODObject_somInit(somSelf);

    _fContent = _fNext = kODNULL;
}

SOM_Scope void  SOMLINK IODLinksomUninit(IODLink *somSelf)
{
    IODLinkData *somThis = IODLinkGetData(somSelf);
    IODLinkMethodDebug("IODLink","IODLinksomUninit");

    IODLink_parent_ODObject_somUninit(somSelf);
}


SOM_Scope IODLink*  SOMLINK IODLinkedListFirst(IODLinkedList *somSelf, 
                                                Environment *ev)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListFirst");

    return _fRoot;
}

SOM_Scope void  SOMLINK IODLinkedListAddFirst(IODLinkedList *somSelf, 
                                               Environment *ev, 
                                              ODPtr content)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListAddFirst");

    IODLink *node = new IODLink;
    node->setContent(ev, content);
    node->setNext(ev, _fRoot);
    _fRoot = node;
}

SOM_Scope void  SOMLINK IODLinkedListAddLast(IODLinkedList *somSelf, 
                                              Environment *ev, 
                                             ODPtr content)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListAddLast");

    if (_fRoot->Content(ev) == kODNULL) {
       somSelf->AddFirst (ev, content);
       return;
    }

    IODLink *node = _fRoot, *prev = _fRoot;

    while (node->Next(ev) != kODNULL) {
       prev = node;
       node = node->Next(ev);
    }
    IODLink *newNode = new IODLink;
    newNode->setContent (ev, content);
    newNode->setNext (ev, node);
    prev->setNext (ev, newNode);

}

SOM_Scope void  SOMLINK IODLinkedListRemove(IODLinkedList *somSelf, 
                                             Environment *ev, 
                                            ODPtr content)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListRemove");

    if (somSelf->Contains(ev, content) == kODFalse)
       return;

    if (_fRoot->Content(ev) == content) {
       IODLink *temp = _fRoot;
       _fRoot = _fRoot->Next(ev);
       delete temp;
       return;
    }

    IODLink *node = _fRoot, *prev = _fRoot;

    while (node->Content(ev) != content) {
       prev = node;
       node = node->Next(ev);
    }
    prev->setNext (ev, node->Next(ev));
    delete node;

}

SOM_Scope void  SOMLINK IODLinkedListRemoveAll(IODLinkedList *somSelf, 
                                                Environment *ev)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListRemoveAll");

    IODLink *node = _fRoot;
    while (node->Next(ev)) {
       IODLink *temp = node;
       node = node->Next(ev);
       delete temp;
    }
    _fRoot = node;

}

SOM_Scope ODBoolean  SOMLINK IODLinkedListContains(IODLinkedList *somSelf, 
                                                    Environment *ev, 
                                                   ODPtr content)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListContains");

    IODLink *node = _fRoot;
    while(node->Next(ev)) {
       if (node->Content(ev) == content)
          return kODTrue;
       node = node->Next(ev);
    }
    return kODFalse;
}

SOM_Scope ODULong  SOMLINK IODLinkedListCount(IODLinkedList *somSelf, 
                                               Environment *ev)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListCount");

    ODULong retVal = 0;
    IODLink *node = _fRoot;
    while (node->Next(ev)) {
       retVal++;
       node = node->Next(ev);
    }
    return retVal;
}

SOM_Scope void  SOMLINK IODLinkedListsomInit(IODLinkedList *somSelf)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListsomInit");

    IODLinkedList_parent_ODObject_somInit(somSelf);

    _fRoot = new IODLink;
}

SOM_Scope void  SOMLINK IODLinkedListsomUninit(IODLinkedList *somSelf)
{
    IODLinkedListData *somThis = IODLinkedListGetData(somSelf);
    IODLinkedListMethodDebug("IODLinkedList","IODLinkedListsomUninit");

    Environment *ev = somGetGlobalEnvironment();
    IODLink *node = _fRoot;
    while (node->Next(ev)) {
       IODLink *temp = node->Next(ev);
       delete node;
       node = temp;
    }
    delete node;

    IODLinkedList_parent_ODObject_somUninit(somSelf);
}

