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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [include/] [llistt.hxx] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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