Ignore:
Timestamp:
Apr 1, 2012, 10:44:45 PM (13 years ago)
Author:
ldelgass
Message:

style fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/Chain.cpp

    r2798 r2923  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 /*
    3  * Chain.cpp --
    4  *
    5  * The module implements a generic linked list package.
    6  *
    7  *      Copyright 1991-2004 George A Howlett.
    8  *
    9  *      Permission is hereby granted, free of charge, to any person obtaining
    10  *      a copy of this software and associated documentation files (the
    11  *      "Software"), to deal in the Software without restriction, including
    12  *      without limitation the rights to use, copy, modify, merge, publish,
    13  *      distribute, sublicense, and/or sell copies of the Software, and to
    14  *      permit persons to whom the Software is furnished to do so, subject to
    15  *      the following conditions:
    16  *
    17  *      The above copyright notice and this permission notice shall be
    18  *      included in all copies or substantial portions of the Software.
    19  *
    20  *      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    21  *      EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    22  *      MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    23  *      NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    24  *      LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    25  *      OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    26  *      WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    27  */
    28 
     2/* The module implements a generic linked list package.
     3 *
     4 * Copyright 1991-2004 George A Howlett.
     5 *
     6 * Permission is hereby granted, free of charge, to any person obtaining
     7 * a copy of this software and associated documentation files (the
     8 * "Software"), to deal in the Software without restriction, including
     9 * without limitation the rights to use, copy, modify, merge, publish,
     10 * distribute, sublicense, and/or sell copies of the Software, and to
     11 * permit persons to whom the Software is furnished to do so, subject to
     12 * the following conditions:
     13 *
     14 * The above copyright notice and this permission notice shall be
     15 * included in all copies or substantial portions of the Software.
     16 *
     17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     24 */
    2925#include <stdlib.h>
    3026#include <stdio.h>
     27
    3128#include "Chain.h"
    3229
    3330typedef int (QSortCompareProc) (const void *, const void *);
    3431
    35 /*
    36  *----------------------------------------------------------------------
    37  *
    38  * Reset --
    39  *
    40  *      Removes all the links from the chain, freeing the memory for each
    41  *      link.  Memory pointed to by the link (clientData) is not freed.  It's
    42  *      the caller's responsibility to deallocate it.
    43  *
    44  * Results:
    45  *      None.
    46  *
    47  *----------------------------------------------------------------------
    48  */
    49 void
    50 Chain::Reset() /* Chain to clear */
     32/**
     33 * Removes all the links from the chain, freeing the memory for each
     34 * link.  Memory pointed to by the link (clientData) is not freed.  It's
     35 * the caller's responsibility to deallocate it.
     36 */
     37void
     38Chain::reset()
    5139{
    5240    ChainLink *oldPtr;
     
    5543    while (linkPtr != NULL) {
    5644        oldPtr = linkPtr;
    57         linkPtr = linkPtr->Next();
     45        linkPtr = linkPtr->next();
    5846        delete oldPtr;
    5947    }
    60     Init();
    61 }
    62 
    63 /*
    64  *----------------------------------------------------------------------
    65  *
    66  * LinkAfter --
    67  *
    68  *      Inserts a link after another link.  If afterPtr is NULL, then the new
    69  *      link is prepended to the beginning of the chain.
    70  *
    71  * Results:
    72  *      None.
    73  *
    74  *----------------------------------------------------------------------
    75  */
    76 void
    77 Chain::LinkAfter(ChainLink *linkPtr, ChainLink *afterPtr)
     48    init();
     49}
     50
     51/**
     52 * Inserts a link after another link.  If afterPtr is NULL, then the new
     53 * link is prepended to the beginning of the chain.
     54 */
     55void
     56Chain::linkAfter(ChainLink *linkPtr, ChainLink *afterPtr)
    7857{
    7958    if (_head == NULL) {
     
    8766            _head = linkPtr;
    8867        } else {
    89             linkPtr->_next = afterPtr->Next();
     68            linkPtr->_next = afterPtr->next();
    9069            linkPtr->_prev = afterPtr;
    9170            if (afterPtr == _tail) {
    9271                _tail = linkPtr;
    9372            } else {
    94                 afterPtr->Next()->_prev = linkPtr;
     73                afterPtr->next()->_prev = linkPtr;
    9574            }
    9675            afterPtr->_next = linkPtr;
     
    10079}
    10180
    102 /*
    103  *----------------------------------------------------------------------
    104  *
    105  * LinkBefore --
    106  *
    107  *      Inserts a new link preceding a given link in a chain.  If beforePtr is
    108  *      NULL, then the new link is placed at the beginning of the list.
    109  *
    110  * Results:
    111  *      None.
    112  *
    113  *----------------------------------------------------------------------
    114  */
    115 void
    116 Chain::LinkBefore(
    117     ChainLink *linkPtr,         /* New entry to be inserted */
    118     ChainLink *beforePtr)       /* Entry to link before */
     81/**
     82 * Inserts a new link preceding a given link in a chain.  If beforePtr is
     83 * NULL, then the new link is placed at the beginning of the list.
     84 *
     85 * \param linkPtr New entry to be inserted
     86 * \param beforePtr Entry to link before
     87 */
     88void
     89Chain::linkBefore(ChainLink *linkPtr,
     90                  ChainLink *beforePtr)
    11991{
    12092    if (_head == NULL) {
     
    12294    } else {
    12395        if (beforePtr == NULL) {
    124             /* Append to the end of the chain. */
     96            // Append to the end of the chain.
    12597            linkPtr->_next = NULL;
    12698            linkPtr->_prev = _tail;
     
    128100            _tail = linkPtr;
    129101        } else {
    130             linkPtr->_prev = beforePtr->Prev();
     102            linkPtr->_prev = beforePtr->prev();
    131103            linkPtr->_next = beforePtr;
    132104            if (beforePtr == _head) {
    133105                _head = linkPtr;
    134106            } else {
    135                 beforePtr->Prev()->_next = linkPtr;
     107                beforePtr->prev()->_next = linkPtr;
    136108            }
    137109            beforePtr->_prev = linkPtr;
     
    141113}
    142114
    143 /*
    144  *----------------------------------------------------------------------
    145  *
    146  * Unlink --
    147  *
    148  *      Unlinks a link from the chain. The link is not deallocated,
    149  *      but only removed from the chain.
    150  *
    151  * Results:
    152  *      None.
    153  *
    154  *----------------------------------------------------------------------
    155  */
    156 void
    157 Chain::Unlink(ChainLink *linkPtr)
     115/**
     116 * Unlinks a link from the chain. The link is not deallocated,
     117 * but only removed from the chain.
     118 */
     119void
     120Chain::unlink(ChainLink *linkPtr)
    158121{
    159122    bool unlinked;              /* Indicates if the link is actually removed
     
    162125    unlinked = false;
    163126    if (_head == linkPtr) {
    164         _head = linkPtr->Next();
     127        _head = linkPtr->next();
    165128        unlinked = true;
    166129    }
    167130    if (_tail == linkPtr) {
    168         _tail = linkPtr->Prev();
    169         unlinked = true;
    170     }
    171     if (linkPtr->Next() != NULL) {
    172         linkPtr->Next()->_prev = linkPtr->Prev();
    173         unlinked = true;
    174     }
    175     if (linkPtr->Prev() != NULL) {
    176         linkPtr->Prev()->_next = linkPtr->Next();
     131        _tail = linkPtr->prev();
     132        unlinked = true;
     133    }
     134    if (linkPtr->next() != NULL) {
     135        linkPtr->next()->_prev = linkPtr->prev();
     136        unlinked = true;
     137    }
     138    if (linkPtr->prev() != NULL) {
     139        linkPtr->prev()->_next = linkPtr->next();
    177140        unlinked = true;
    178141    }
     
    183146}
    184147
    185 /*
    186  *----------------------------------------------------------------------
    187  *
    188  * DeleteLink --
    189  *
    190  *      Unlinks and frees the given link from the chain.  It's assumed that
    191  *      the link belong to the chain. No error checking is performed to verify
    192  *      this.
    193  *
    194  * Results:
    195  *      None.
    196  *
    197  *----------------------------------------------------------------------
    198  */
    199 void
    200 Chain::DeleteLink(ChainLink *linkPtr)
    201 {
    202     Unlink(linkPtr);
     148/**
     149 * Unlinks and frees the given link from the chain.  It's assumed that
     150 * the link belong to the chain. No error checking is performed to verify
     151 * this.
     152 */
     153void
     154Chain::deleteLink(ChainLink *linkPtr)
     155{
     156    unlink(linkPtr);
    203157    delete linkPtr;
    204158}
    205159
    206 /*
    207  *----------------------------------------------------------------------
    208  *
    209  * Append --
    210  *
    211  *      Creates and new link with the given data and appends it to the end of
    212  *      the chain.
    213  *
    214  * Results:
    215  *      Returns a pointer to the link created.
    216  *
    217  *----------------------------------------------------------------------
     160/**
     161 * Creates and new link with the given data and appends it to the end of
     162 * the chain.
     163 *
     164 * \return a pointer to the link created.
    218165 */
    219166ChainLink *
    220 Chain::Append(void *clientData)
     167Chain::append(void *clientData)
    221168{
    222169    ChainLink *linkPtr;
    223170
    224171    linkPtr = new ChainLink(clientData);
    225     LinkBefore(linkPtr, (ChainLink *)NULL);
     172    linkBefore(linkPtr, (ChainLink *)NULL);
    226173    return linkPtr;
    227174}
    228175
    229 /*
    230  *----------------------------------------------------------------------
    231  *
    232  * Prepend --
    233  *
    234  *      Creates and new link with the given data and prepends it to beginning
    235  *      of the chain.
    236  *
    237  * Results:
    238  *      Returns a pointer to the link created.
    239  *
    240  *----------------------------------------------------------------------
     176/**
     177 * Creates and new link with the given data and prepends it to beginning
     178 * of the chain.
     179 *
     180 * \return a pointer to the link created.
    241181 */
    242182ChainLink  *
    243 Chain::Prepend(void *clientData)
     183Chain::prepend(void *clientData)
    244184{
    245185    ChainLink *linkPtr;
    246186
    247187    linkPtr = new ChainLink(clientData);
    248     LinkAfter(linkPtr, (ChainLink *)NULL);
     188    linkAfter(linkPtr, (ChainLink *)NULL);
    249189    return linkPtr;
    250190}
    251191
    252 /*
    253  *----------------------------------------------------------------------
    254  *
    255  * GetNthLink --
    256  *
    257  *      Find the link at the given position in the chain.
    258  *
    259  * Results:
    260  *      Returns the pointer to the link, if that numbered link
    261  *      exists. Otherwise NULL.
    262  *
    263  *----------------------------------------------------------------------
     192/**
     193 * Find the link at the given position in the chain.
     194 *
     195 * \param position Index of link to select from front or back of the chain.
     196 *
     197 * \return  the pointer to the link, if that numbered link
     198 * exists. Otherwise NULL.
    264199 */
    265200ChainLink *
    266 Chain::GetNthLink(long position) /* Index of link to select from front or back
    267                                   * of the chain. */
    268 {
    269     ChainLink *linkPtr;
    270 
    271     for (linkPtr = _head; linkPtr != NULL; linkPtr = linkPtr->Next()) {
     201Chain::getNthLink(long position)
     202{
     203    ChainLink *linkPtr;
     204
     205    for (linkPtr = _head; linkPtr != NULL; linkPtr = linkPtr->next()) {
    272206        if (position == 0) {
    273207            return linkPtr;
     
    278212}
    279213
    280 /*
    281  *----------------------------------------------------------------------
    282  *
    283  * Sort --
    284  *
    285  *      Sorts the chain according to the given comparison routine. 
    286  *
    287  * Results:
    288  *      None.
     214/**
     215 * Sorts the chain according to the given comparison routine. 
    289216 *
    290217 * Side Effects:
    291  *      The chain is reordered.
    292  *
    293  *----------------------------------------------------------------------
    294  */
    295 
    296 void
    297 Chain::Sort(ChainCompareProc *proc)
     218 *   The chain is reordered.
     219 */
     220void
     221Chain::sort(ChainCompareProc *proc)
    298222{
    299223    ChainLink *linkPtr;
     
    308232    }
    309233    i = 0;
    310     for (linkPtr = _head; linkPtr != NULL; linkPtr = linkPtr->Next()) {
     234    for (linkPtr = _head; linkPtr != NULL; linkPtr = linkPtr->next()) {
    311235        linkArr[i++] = linkPtr;
    312236    }
     
    320244    for (i = 1; i < _nLinks; i++) {
    321245        linkPtr->_next = linkArr[i];
    322         linkPtr->Next()->_prev = linkPtr;
    323         linkPtr = linkPtr->Next();
     246        linkPtr->next()->_prev = linkPtr;
     247        linkPtr = linkPtr->next();
    324248    }
    325249    _tail = linkPtr;
     
    327251    delete [] linkArr;
    328252}
    329 
Note: See TracChangeset for help on using the changeset viewer.