OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [include/] [llistt.hxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_KERNEL_LLISTT_HXX
2
#define CYGONCE_KERNEL_LLISTT_HXX
3
 
4
//==========================================================================
5
//
6
//      llistt.hxx
7
//
8
//      Llistt linked list template class declarations
9
//
10
//==========================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//==========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   hmt
46
// Contributors:        hmt
47
// Date:        1998-02-10
48
// Purpose:     Define Llistt template class
49
// Description: The classes defined here provide the APIs for llistts.
50
// Usage:       #include 
51
//
52
//
53
//####DESCRIPTIONEND####
54
//
55
//==========================================================================
56
 
57
#include 
58
#include             // assertion macros
59
#include 
60
 
61
// -------------------------------------------------------------------------
62
// A simple linked list template; each item also contains a pointer of type
63
// T, and you can search for a particular T* in a list.
64
//
65
// It is intended that this list be amenable to the trick of using the
66
// address of the pointer that is the list head, cast to an item pointer,
67
// as the "zeroth" element of the list; prev of the first item is the
68
// address of the head pointer, and inserting before the first item works
69
// correctly.  For this reason, a "getprev" is not provided; iteration may
70
// only be forwards, until a NULL is found.
71
//
72
// It is expected that derived classes will be used to hold other
73
// information than just the T* but that is beyond our discussion here;
74
// only the T* can be searched for using code provided here.
75
//
76
// This module is NOT thread-safe; it is expected that all clients will be
77
// seeing that that themselves.
78
 
79
template 
80
class Cyg_Llistt
81
{
82
private:
83
    Cyg_Llistt *next, *prev;
84
    T *tptr;
85
 
86
private:
87
    // make initialisation _without_ a T* impossible.
88
    Cyg_Llistt &operator=(Cyg_Llistt &);
89
    Cyg_Llistt(Cyg_Llistt &);
90
    Cyg_Llistt();
91
 
92
public:
93
 
94
    CYGDBG_DEFINE_CHECK_THIS
95
 
96
    Cyg_Llistt( T *tvalue ) // Constructor
97
    {
98
        tptr = tvalue;
99
        next = prev = NULL;
100
    }
101
 
102
    ~Cyg_Llistt()                       // Destructor
103
    {
104
        CYG_ASSERT( NULL == next, "bad item next - still in list" );
105
        CYG_ASSERT( NULL == prev, "bad item prev - still in list" );
106
    }
107
 
108
    // iterator, basically.
109
    Cyg_Llistt * getnext() { return next; }
110
 
111
    // get the value
112
    T * getitem() { return tptr; }
113
 
114
    // look up a particular T value in the llist
115
    static Cyg_Llistt *
116
    find( Cyg_Llistt *list, T *tvalue )
117
    {
118
        for ( ; list ; list = list->next ) {
119
            if ( list->tptr == tvalue )
120
                break;
121
        }
122
        return list;
123
    }
124
 
125
    // unlink an item from the list
126
    void
127
    unlink()
128
    {
129
        CYG_ASSERT( prev, "not in a list" );
130
        prev->next = next;
131
        if ( next ) {
132
            next->prev = prev;
133
        }
134
        next = prev = NULL;
135
    }
136
 
137
    // insert a new item in the list after "this"
138
    void
139
    insertafter( Cyg_Llistt *item )
140
    {
141
        CYG_ASSERT( item, "null item" );
142
        CYG_ASSERT( NULL == item->next, "bad item next - already linked" );
143
        CYG_ASSERT( NULL == item->prev, "bad item prev - already linked" );
144
        item->next = next;
145
        item->prev = this;
146
        if ( next )
147
            next->prev = item;
148
        next = item;
149
    }
150
 
151
    // insert a new item in the list before "this"
152
    void
153
    insertbefore( Cyg_Llistt *item )
154
    {
155
        CYG_ASSERT( prev, "this not in a list" );
156
        CYG_ASSERT( item, "null item" );
157
        CYG_ASSERT( NULL == item->next, "bad item next - already linked" );
158
        CYG_ASSERT( NULL == item->prev, "bad item prev - already linked" );
159
        item->prev = prev;
160
        item->next = this;
161
        prev->next = item;
162
              prev = item;
163
    }
164
};
165
 
166
 
167
 
168
// -------------------------------------------------------------------------
169
#endif // ifndef CYGONCE_KERNEL_LLISTT_HXX
170
// EOF llistt.hxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.