]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/pointer.hh
release: 0.0.62
[lilypond.git] / flower / include / pointer.hh
1 /*
2   pointer.hh -- declare P
3
4   source file of the Flower Library
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #ifndef POINTER_HH
11 #define POINTER_HH
12
13 /** P<T> is a handy template to use iso T*. It inits to 0, deletes on
14   destruction, deep copies upon copying
15
16   It is probably not feasible to use P<T> as template argument, since
17   a lot of auto conversion wouldn't work. new T would be called too
18   much anyway.
19   
20   Sorry for the silly naming */
21 template <class T>
22 class P {
23     /**
24       Set contents to a copy of #t_l#
25      */
26     void copy(T const*t_l);
27     T* t_p;
28
29     /**
30       junk contents and set to 0
31      */
32     void junk();
33 public:
34     
35     P(P const &src);
36     /**
37       Remove  the pointer, and return it.
38      */
39     
40     T *get_p() { T*p = t_p; t_p=0; return p; }
41     /**
42       return the pointer
43      */
44     T *get_l()  { return t_p; }
45
46     T const *get_C() const { return t_p; }
47     /**
48       copy the contents of pointer, and return it
49      */
50     T *copy_p() const;
51     /**
52       swallow new_p, and set contents t new_p
53      */
54     void set_p (T *new_p); 
55     /**
56       junk contents, and  copy contents of t_l
57      */
58     void set_l (T const *t_C); 
59     
60     P &operator =(P const &);
61     ~P();
62     P() { t_p = 0; }
63     //P(T *p) { t_p = p; }
64     
65     T *operator ->() { return t_p; }
66     operator T * () {  return t_p; }
67     const T *operator ->() const { return t_p ; }
68     T &operator *() { return *t_p; }
69     T const  &operator *() const { return *t_p; }
70     operator const T *() const { return t_p; }
71 };
72 #endif // POINTER_HH
73
74