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