~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to extern/bFTGL/include/FTList.h

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef    __FTList__
 
2
#define    __FTList__
 
3
 
 
4
#include "FTGL.h"
 
5
 
 
6
/**
 
7
* Provides a non-STL alternative to the STL list
 
8
 */
 
9
template <typename FT_LIST_ITEM_TYPE>
 
10
class FTGL_EXPORT FTList
 
11
{
 
12
    public:
 
13
        typedef FT_LIST_ITEM_TYPE value_type;
 
14
        typedef value_type& reference;
 
15
        typedef const value_type& const_reference;
 
16
        typedef size_t size_type;
 
17
 
 
18
        /**
 
19
         * Constructor
 
20
         */
 
21
        FTList()
 
22
        :   listSize(0),
 
23
            tail(0)
 
24
        {
 
25
            tail = NULL;
 
26
            head = new Node;
 
27
        }
 
28
 
 
29
        /**
 
30
         * Destructor
 
31
         */
 
32
        ~FTList()
 
33
        {
 
34
            Node* next;
 
35
            
 
36
            for( Node *walk = head; walk; walk = next)
 
37
            {
 
38
                next = walk->next;
 
39
                delete walk;
 
40
            }
 
41
        }
 
42
 
 
43
        /**
 
44
         * Get the number of items in the list
 
45
         */
 
46
        size_type size() const
 
47
        {
 
48
            return listSize;
 
49
        }
 
50
 
 
51
        /**
 
52
         * Add an item to the end of the list
 
53
         */
 
54
        void push_back( const value_type& item)
 
55
        {
 
56
            Node* node = new Node( item);
 
57
            
 
58
            if( head->next == NULL)
 
59
            {
 
60
                head->next = node;
 
61
            }
 
62
 
 
63
            if( tail)
 
64
            {
 
65
                tail->next = node;
 
66
            }
 
67
            tail = node;
 
68
            ++listSize;
 
69
        }
 
70
        
 
71
        /**
 
72
         * Get the item at the front of the list
 
73
         */
 
74
        reference front() const
 
75
        {
 
76
            return head->next->payload;
 
77
        }
 
78
 
 
79
        /**
 
80
         * Get the item at the end of the list
 
81
         */
 
82
        reference back() const
 
83
        {
 
84
            return tail->payload;
 
85
        }
 
86
 
 
87
    private:
 
88
        struct Node
 
89
        {
 
90
            Node()
 
91
            :   next(NULL)
 
92
            {}
 
93
 
 
94
            Node( const value_type& item)
 
95
            :   next(NULL)
 
96
            {
 
97
                payload = item;
 
98
            }
 
99
            
 
100
            Node* next;
 
101
            
 
102
            value_type payload;
 
103
        };
 
104
        
 
105
        size_type listSize;
 
106
 
 
107
        Node* head;
 
108
        Node* tail;
 
109
};
 
110
 
 
111
#endif // __FTList__
 
112