File: ptrlist.h

package info (click to toggle)
powder 117-2
  • links: PTS
  • area: non-free
  • in suites: stretch
  • size: 10,576 kB
  • ctags: 3,545
  • sloc: cpp: 55,002; makefile: 541; sh: 258; objc: 245; ansic: 107; csh: 54
file content (96 lines) | stat: -rw-r--r-- 2,188 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Licensed under BSD license.  See LICENCE.TXT  
 *
 * Produced by:	Jeff Lait
 *
 *      	7DRL Development
 *
 * NAME:        ptrlist.h ( Letter Hunt Library, C++ )
 *
 * COMMENTS:
 *	Implements a simple list of pointers.
 *	The observent will notice similarities to ptrstack defined
 *	itemstack.
 */

#ifndef __ptrlist_h__
#define __ptrlist_h__

template <typename PTR>
class PTRLIST
{
public:
    PTRLIST();
    ~PTRLIST();

    // No copy constructors as you should be passing by reference to build!
    // That is a noble sentiment, but we live in a corrupt world
    PTRLIST(const PTRLIST<PTR> &ref);
    PTRLIST<PTR> &operator=(const PTRLIST<PTR> &ref);

    void		 append(PTR item);
    void		 append(const PTRLIST<PTR> &list);

    // Reverses the order of the stack.
    void		 reverse();

    // Empties the stack
    void		 clear();

    // Sets array to constant value
    void		 constant(PTR ptr);

    // Sets entries to the given size.
    void		 resize(int size);

    PTR			 operator()(int idx) const;
    int			 entries() const;

    void		 set(int idx, PTR item);

    void		 insert(int idx, PTR item);

    // Removes all instances of "item" from
    // this list.
    void		 removePtr(PTR item);

    // Removes a given index
    void		 removeAt(int idx);

    // Returns the last item on this list and decreases
    // the length.
    PTR			 pop();

    // Swaps two entries
    void		 swapEntries(int i1, int i2);

    // Returns the last element.
    // The index allows you to specify N elements from the end, where
    // 0 is the last element and 1 second last.
    PTR			 top(int idx = 0) const { return (*this)(entries()-1-idx); }

    // Returns the first item from this list and
    // removes it.
    PTR			 removeFirst();

    // Finds the given item, returns -1 if fails.
    int			 find(PTR item) const;

    // Deletes all zero entries.
    void		 collapse();

    // I shouldn ot have to explain why you should never call this.
    PTR			*rawptr(int idx=0) const { return &myList[idx]; }

private:
    PTR			 *myList;
    int			  myStartPos;
    int			  myEntries;
    int			  mySize;
};

// For crappy platforms:
#include "ptrlist.cpp"

#endif