summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/util/UtilTreeX.H
blob: 820adf251e20532a44aa09bebacc212d01443065 (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/util/UtilTreeX.H $                   */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2004,2012              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#ifndef __UTIL_UTILTREEX_H
#define __UTIL_UTILTREEX_H

#include "UtilTree.H"

template <class _T>
class UtilTreeX
{
    public:
        UtilTreeX();
        UtilTreeX(const UtilTreeX<_T> &);

        void insert(_T &);
        void remove(_T &);
        bool find(_T &);
        const _T & peek();
        void empty() { cv_tree.empty(); };

        void printTree()
            {
                cv_tree.printTree();
            };

    private:
        UtilTree cv_tree;

        class treeXComparator : public UtilTree::comparator
        {
            public:
                virtual int operator() (void * _a, void * _b) const
                    {
                        _T * a;
                        _T * b;

                        a = static_cast<_T *>(_a);
                        b = static_cast<_T *>(_b);

                        return (*a < *b ? -1 : (*a == *b ? 0 : 1));
                    }
        };

        class treeXCleanup : public UtilTree::cleanup
        {
            public:
                virtual void operator() (void * _a) const
                    {
                        _T * a = static_cast<_T *>(_a);
                        delete a;
                    };
        };

        class treeXCopier : public UtilTree::copier
        {
            public:
                virtual void * operator() (void * _a) const
                {
                    _T * a = static_cast<_T *>(_a);
                    return (void *) new _T(*a);
                };
        };

        treeXComparator cv_compare;
        treeXCleanup cv_clean;
        treeXCopier cv_copy;

    public:
        class iterator
        {
            private:
                UtilTree::iterator _pos;
            public:
                iterator(UtilTree::iterator i) { _pos = i; };
                iterator & operator++()
                    { ++_pos; return *this; };
                iterator & operator--()
                    { --_pos; return *this; };
                bool operator==(const iterator& i) const
                    { return _pos == i._pos; };
                bool operator!=(const iterator& i) const
                    { return _pos != i._pos; };
                _T operator*()
                    {
                        _T * a = static_cast<_T *>(*_pos);
                        if (NULL == a)
                            return _T();
                        return *a;
                    };
        };
        iterator end() const { return iterator(cv_tree.end()); };
        iterator begin() const { return iterator(cv_tree.begin()); };
};

template <class _T>
UtilTreeX<_T>::UtilTreeX()
{
    cv_tree.setComparator(&cv_compare);
    cv_tree.setCleanup(&cv_clean);
    cv_tree.setCopier(&cv_copy);
};

template <class _T>
UtilTreeX<_T>::UtilTreeX(const UtilTreeX<_T> & i_copy)
{
    cv_tree = i_copy.cv_tree;
    cv_tree.setComparator(&cv_compare);
    cv_tree.setCleanup(&cv_clean);
    cv_tree.setCopier(&cv_copy);
};


template <class _T>
void UtilTreeX<_T>::insert(_T & i)
{
    cv_tree.insert((void *)new _T(i));
};

template <class _T>
void UtilTreeX<_T>::remove(_T & i)
{
    cv_tree.remove((void *)&i);
};

template <class _T>
bool UtilTreeX<_T>::find(_T & i)
{
    return (NULL != cv_tree.find((void *)&i));
};

template <class _T>
const _T & UtilTreeX<_T>::peek()
{
    static const _T l = _T();
    void * tmp = cv_tree.peek();
    if (NULL == tmp)
        return l;
    return *static_cast<const _T *>(tmp);
};


#endif

// Change Log *********************************************************
//
//  Flag Reason   Vers Date     Coder    Description
//  ---- -------- ---- -------- -------- -------------------------------
//       F494911  f310 03/04/05 iawillia Initial File Creation
//
// End Change Log *****************************************************
OpenPOWER on IntegriCloud