File: newalloc.h

package info (click to toggle)
c%2B%2B-annotations 11.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,244 kB
  • sloc: cpp: 21,698; makefile: 1,505; ansic: 165; sh: 121; perl: 90
file content (67 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (7)
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
#ifndef INCLUDED_NEWALLOC_H_
#define INCLUDED_NEWALLOC_H_

#include <ostream>

template <typename Data>
class NewAlloc: public std::allocator<Data>
{
    template<typename IData>
    friend std::ostream &operator<<(std::ostream &out,
                                    NewAlloc<IData> const &alloc);
    Data *d_data;

    public:
        NewAlloc();
        NewAlloc(Data const &data);
        NewAlloc(NewAlloc<Data> const &other);
        ~NewAlloc();
        operator Data &();
        NewAlloc &operator=(Data const &data);
};

template<typename Data>
NewAlloc<Data>::NewAlloc()
:
    d_data(0)
{}

template<typename Data>
NewAlloc<Data>::NewAlloc(Data const &data)
:
    d_data(new Data(data))
{}

template<typename Data>
NewAlloc<Data>::NewAlloc(NewAlloc<Data> const &other)
:
    d_data(new Data(*other.d_data))
{}

template<typename Data>
NewAlloc<Data>::~NewAlloc()
{
    delete d_data;
}

template<typename Data>
NewAlloc<Data>::operator Data &()
{
    return *d_data;
}

template<typename Data>
NewAlloc<Data> &NewAlloc<Data>::operator=(Data const &data)
{
    *d_data = data;
}

template<typename IData>
inline std::ostream &operator<<(std::ostream &out,
                                NewAlloc<IData> const &alloc)
{
    return out << *alloc.d_data;
}


#endif