]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/pointer.hh
release: 0.0.49
[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     void copy(T*);
25     T* t_p;
26     void junk();
27 public:
28     
29     P(P const &src);
30     
31     T *get_p() { T*p = t_p; t_p=0; return p; }
32     T *get_l() { return t_p; }
33     T *copy_p() const;
34     void set_p (T *new_p); 
35     void set_l (T *t_l); 
36     
37     P &operator =(P const &);
38     ~P();
39     P() { t_p = 0; }
40     //P(T *p) { t_p = p; }
41     
42     T *operator ->() { return t_p; }
43     operator T * () {  return t_p; }
44     const T *operator ->() const { return t_p ; }
45     operator const T *() const { return t_p; }
46 };
47 #endif // POINTER_HH
48
49