lilypond-0.0.62
[lilypond.git] / flower / include / pointer.hh
blob58f8e198b0537e4aae014ed1314972dee3723bbe
1 /*
2 pointer.hh -- declare P
4 source file of the Flower Library
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
10 #ifndef POINTER_HH
11 #define POINTER_HH
13 /** P<T> is a handy template to use iso T*. It inits to 0, deletes on
14 destruction, deep copies upon copying
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.
20 Sorry for the silly naming */
21 template <class T>
22 class P {
23 /**
24 Set contents to a copy of #t_l#
26 void copy(T const*t_l);
27 T* t_p;
29 /**
30 junk contents and set to 0
32 void junk();
33 public:
35 P(P const &src);
36 /**
37 Remove the pointer, and return it.
40 T *get_p() { T*p = t_p; t_p=0; return p; }
41 /**
42 return the pointer
44 T *get_l() { return t_p; }
46 T const *get_C() const { return t_p; }
47 /**
48 copy the contents of pointer, and return it
50 T *copy_p() const;
51 /**
52 swallow new_p, and set contents t new_p
54 void set_p (T *new_p);
55 /**
56 junk contents, and copy contents of t_l
58 void set_l (T const *t_C);
60 P &operator =(P const &);
61 ~P();
62 P() { t_p = 0; }
63 //P(T *p) { t_p = p; }
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; }
72 #endif // POINTER_HH