Tidying.
[synfig.git] / ETL / trunk / ETL / _handle.h
1 /* === E T L =============================================================== */
2 /*!     \file _handle.h
3 **      $Id$
4 **      \brief Template Object Handle Implementation
5 **      \internal
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 **
21 **      \note
22 **              This is an internal header file, included by other ETL headers.
23 **              You should not attempt to use it directly.
24 */
25 /* ========================================================================= */
26
27 /* === S T A R T =========================================================== */
28
29 #ifndef __ETL__HANDLE_H
30 #define __ETL__HANDLE_H
31
32 /* === H E A D E R S ======================================================= */
33
34 #include <cassert>
35
36 /* === M A C R O S ========================================================= */
37
38 /* === T Y P E D E F S ===================================================== */
39
40 #define ETL_SELF_DELETING_SHARED_OBJECT
41
42 /* === C L A S S E S & S T R U C T S ======================================= */
43
44 #ifdef NDEBUG
45 #define assert_cast             static_cast
46 #else
47 #define assert_cast             dynamic_cast
48 #endif
49
50
51 _ETL_BEGIN_NAMESPACE
52
53 // Forward Declarations
54 template <class T> class handle;
55 template <class T> class loose_handle;
56 template <class T> class rhandle;
57
58
59 // ========================================================================
60 /*!     \class  shared_object _handle.h ETL/handle
61 **      \brief  Shared Object Base Class
62 **      \see handle, loose_handle
63 **      \writeme
64 */
65 class shared_object
66 {
67 private:
68         mutable int refcount;
69
70 protected:
71         shared_object():refcount(0) { }
72
73 #ifdef ETL_SELF_DELETING_SHARED_OBJECT
74         virtual ~shared_object() { }
75 #else
76         ~shared_object() { }
77 #endif
78
79 public:
80         void ref()const
81                 { assert(refcount>=0); refcount++; }
82
83         //! Returns \c false if object needs to be deleted
84         bool unref()const
85         {
86                 assert(refcount>0);
87
88                 refcount--;
89
90                 if(refcount==0) {
91 #ifdef ETL_SELF_DELETING_SHARED_OBJECT
92                         refcount=-666;
93                         delete this;
94 #endif
95                         return false;
96                 }
97
98                 return true;
99         }
100
101         int count()const
102                 { return refcount; }
103 }; // END of class shared_object
104
105 // ========================================================================
106 /*!     \class  virtual_shared_object _handle.h ETL/handle
107 **      \brief  Virtual Shared Object Base Class
108 **      \see handle, loose_handle
109 **      \writeme
110 */
111 class virtual_shared_object
112 {
113 protected:
114         virtual_shared_object() { }
115 public:
116         virtual ~virtual_shared_object()=0;
117         virtual void ref()const=0;
118         virtual bool unref()const=0;
119         virtual int count()const=0;
120         virtual virtual_shared_object *clone()=0;
121 }; // END of class virtual_shared_object
122
123 // ========================================================================
124 /*!     \class  handle _handle.h        ETL/handle
125 **      \brief  Object Handle
126 **      \see shared_object, loose_handle
127 **      \writeme
128 */
129 template <class T>
130 class handle
131 {
132 public:
133
134         typedef T value_type;
135         typedef T& reference;
136         typedef const T& const_reference;
137         typedef T* pointer;
138         typedef const T* const_pointer;
139         typedef int count_type;
140         typedef int size_type;
141
142 protected:
143         value_type *obj;                //!< Pointer to object
144
145 public:
146
147         //! Default constructor - empty handle
148         handle():obj(NULL) {}
149
150         //! Constructor that constructs from a pointer to new object
151         handle(pointer x):obj(x)
152         {
153                 if(obj)
154                         obj->ref();
155         }
156
157         //! Default copy constructor
158         handle(const handle<value_type> &x):obj(x.get())
159         {
160                 if(obj)
161                         obj->ref();
162         }
163
164         //! Handle is released on deletion
165         ~handle() { detach(); }
166
167         //! Template Assignment operator
168         /*! \note This class may not be necessary, and may be removed
169         **              at some point in the future.
170         */
171         /*
172         template <class U> handle<value_type> &
173         operator=(const handle<U> &x)
174         {
175                 if(x.get()==obj)
176                         return *this;
177
178                 detach();
179
180                 obj=static_cast<value_type*>(x.get());
181                 if(obj)obj->ref();
182                 return *this;
183         }
184         */
185
186         //! Assignment operator
187         handle<value_type> &
188         operator=(const handle<value_type> &x)
189         {
190                 if(x.get()==obj)
191                         return *this;
192
193                 detach();
194
195                 obj=x.get();
196                 if(obj)obj->ref();
197                 return *this;
198         }
199
200         //! Swaps the values of two handles without reference counts
201         handle<value_type> &
202         swap(handle<value_type> &x)
203         {
204                 pointer ptr=x.obj;
205                 x.obj=x.get();
206                 obj=ptr;
207                 return *this;
208         }
209
210         //! Handle detach procedure
211         /*! unref()'s the object and sets the internal object pointer to \c NULL */
212         void
213         detach()
214         {
215                 pointer xobj(obj);
216                 obj=0;
217 #ifdef ETL_SELF_DELETING_SHARED_OBJECT
218                 if(xobj)
219                         xobj->unref();
220 #else
221                 if(xobj && !xobj->unref())
222                         delete xobj;
223 #endif
224         }
225
226         // This will be reintroduced with a new function
227         //void release() { detach(); }
228
229         void reset() { detach(); }
230
231         bool empty()const { return obj==0; }
232
233         //! Creates a new instance of a T object and puts it in the handle.
234         /*! Uses the default constructor */
235         void spawn() { operator=(handle(new T())); }
236
237         handle<value_type> clone()const { assert(obj); return static_cast<value_type*>(obj->clone()); }
238
239         //! Returns a constant handle to our object
240         handle<const value_type> constant()const { assert(obj); return *this; }
241
242         //! Returns number of instances
243         count_type
244         count()const
245                 { return obj?obj->count():0; }
246
247         //! Returns true if there is only one instance of the object
248         bool
249         unique()const
250                 { assert(obj); return count()==1; }
251
252         reference
253         operator*()const
254                 { assert(obj); return *obj; }
255
256         pointer
257         operator->()const
258                 { assert(obj); return obj; }
259
260         //! More explicit bool cast
261         operator bool()const
262                 { return obj!=NULL; }
263
264         operator handle<const value_type>()const
265         { return handle<const value_type>(static_cast<const_pointer>(obj)); }
266
267
268         //! <tt> static_cast\<\> </tt> wrapper
269         template <class U> static
270         handle<T> cast_static(const handle<U> &x)
271         { return handle<T>(static_cast<T*>(x.get())); }
272
273         //! <tt> dynamic_cast\<\> </tt> wrapper
274         template <class U> static
275         handle<T> cast_dynamic(const handle<U> &x)
276         { return handle<T>(dynamic_cast<T*>(x.get())); }
277
278         //! <tt> const_cast\<\> </tt> wrapper
279         template <class U> static
280         handle<T> cast_const(const handle<U> &x)
281         { return handle<T>(const_cast<T*>(x.get())); }
282
283         //! <tt> reinterpret_cast\<\> </tt> wrapper
284         template <class U> static
285         handle<T> cast_reinterpret(const handle<U> &x)
286         { return handle<T>(reinterpret_cast<T*>(x.get())); }
287
288         template<class U> static handle<T> cast_static(const loose_handle<U> &x);
289         template<class U> static handle<T> cast_dynamic(const loose_handle<U> &x);
290         template<class U> static handle<T> cast_const(const loose_handle<U> &x);
291         template<class U> static handle<T> cast_reinterpret(const loose_handle<U> &x);
292
293         template<class U> static handle<T> cast_static(const rhandle<U> &x);
294         template<class U> static handle<T> cast_dynamic(const rhandle<U> &x);
295         template<class U> static handle<T> cast_const(const rhandle<U> &x);
296         template<class U> static handle<T> cast_reinterpret(const rhandle<U> &x);
297
298         template<class U> static handle<T> cast_static(U* x);
299         template<class U> static handle<T> cast_dynamic(U* x);
300         template<class U> static handle<T> cast_const(U* x);
301         template<class U> static handle<T> cast_reinterpret(U* x);
302
303         //! Returns pointer to the object that is being wrapped
304         pointer get()const { return obj; }
305
306         bool
307         operator!()const
308                 { return !obj; }
309
310         //! static_cast<> overload -- Useful for implicit casts
311         template <class U>
312         operator handle<U>()const
313         { return handle<U>(static_cast<U*>(obj)); }
314 }; // END of template class handle
315
316 // ========================================================================
317 /*!     \class  rshared_object _handle.h        ETL/handle
318 **      \brief  Replaceable Shared Object Base Class
319 **      \see rhandle
320 **      \writeme
321 */
322 class rshared_object : public shared_object
323 {
324 private:
325         mutable int rrefcount;
326
327 public:
328         void *front_;
329         void *back_;
330
331 protected:
332         rshared_object():rrefcount(0),front_(0),back_(0) { }
333
334 public:
335         void rref()const
336                 { rrefcount++; }
337
338         void runref()const
339         {
340                 assert(rrefcount>0);
341                 rrefcount--;
342         }
343
344         int rcount()const
345                 { return rrefcount; }
346 }; // END of class rshared_object
347
348 // ========================================================================
349 /*!     \class  rhandle _handle.h       ETL/handle
350 **      \brief  Replaceable Object Handle
351 **      \see rshared_object, handle, loose_handle
352 **      \writeme
353 */
354 template <class T>
355 class rhandle : public handle<T>
356 {
357         friend class rshared_object;
358 public:
359
360         typedef T value_type;
361         typedef T& reference;
362         typedef const T& const_reference;
363         typedef T* pointer;
364         typedef const T* const_pointer;
365         typedef int count_type;
366         typedef int size_type;
367
368
369         using handle<value_type>::count;
370         using handle<value_type>::unique;
371         using handle<value_type>::operator bool;
372         using handle<value_type>::get;
373         using handle<value_type>::operator *;
374         using handle<value_type>::operator ->;
375
376         /*
377         operator const handle<value_type>&()const
378         { return *this; }
379         */
380
381 private:
382         using handle<value_type>::obj;
383
384         rhandle<value_type> *prev_;
385         rhandle<value_type> *next_;
386
387         void add_to_rlist()
388         {
389 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
390
391                 assert(obj);
392                 obj->rref();
393
394                 // If this is the first reversible handle
395                 if(!obj->front_)
396                 {
397                         obj->front_=obj->back_=this;
398                         prev_=next_=0;
399                         return;
400                 }
401
402                 prev_=reinterpret_cast<rhandle<value_type>*>(obj->back_);
403                 next_=0;
404                 prev_->next_=this;
405                 obj->back_=this;
406         }
407
408         void del_from_rlist()
409         {
410 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
411                 assert(obj);
412                 obj->runref();
413
414                 // If this is the last reversible handle
415                 if(obj->front_==obj->back_)
416                 {
417                         obj->front_=obj->back_=0;
418                         prev_=next_=0;
419                         return;
420                 }
421
422                 if(!prev_)
423                         obj->front_=(void*)next_;
424                 else
425                         prev_->next_=next_;
426
427                 if(!next_)
428                         obj->back_=(void*)prev_;
429                 else
430                         next_->prev_=prev_;
431         }
432
433 public:
434
435         //! Default constructor - empty handle
436         rhandle() {}
437
438         //! Constructor that constructs from a pointer to new object
439         rhandle(pointer x):handle<T>(x)
440         {
441 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
442                 if(obj)add_to_rlist();
443         }
444
445         rhandle(const handle<value_type> &x):handle<T>(x)
446         {
447 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
448                 if(obj)add_to_rlist();
449         }
450
451         //! Default copy constructor
452         rhandle(const rhandle<value_type> &x):handle<T>(x)
453         {
454 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
455                 if(obj)add_to_rlist();
456         }
457
458         //! Handle is released on deletion
459         ~rhandle() { detach(); }
460
461         //! Template Assignment operator
462         /*! \note This class may not be necessary, and may be removed
463         **              at some point in the future.
464         */
465         /*
466         template <class U> const handle<value_type> &
467         operator=(const handle<U> &x)
468         {
469                 if(x.get()==obj)
470                         return *this;
471
472                 detach();
473
474                 obj=static_cast<value_type*>(x.get());
475                 if(obj)
476                 {
477                         obj->ref();
478                         add_to_rlist();
479                 }
480                 return *this;
481         }
482         */
483
484         //! Assignment operator
485         rhandle<value_type> &
486         operator=(const rhandle<value_type> &x)
487         {
488 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
489                 if(x.get()==obj)
490                         return *this;
491
492                 detach();
493
494                 obj=x.get();
495                 if(obj)
496                 {
497                         obj->ref();
498                         add_to_rlist();
499                 }
500                 return *this;
501         }
502
503         rhandle<value_type>&
504         operator=(const handle<value_type> &x)
505         {
506 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
507                 if(x.get()==obj)
508                         return *this;
509
510                 detach();
511
512                 obj=x.get();
513                 if(obj)
514                 {
515                         obj->ref();
516                         add_to_rlist();
517                 }
518                 return *this;
519         }
520
521         rhandle<value_type>&
522         operator=(value_type* x)
523         {
524 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
525                 if(x==obj)
526                         return *this;
527
528                 detach();
529
530                 obj=x;
531                 if(obj)
532                 {
533                         obj->ref();
534                         add_to_rlist();
535                 }
536                 return *this;
537         }
538
539         //! Handle release procedure
540         /*! unref()'s the object and sets the internal object pointer to \c NULL */
541         void
542         detach()
543         {
544 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
545                 if(obj)del_from_rlist();
546                 handle<value_type>::detach();
547                 obj=0;
548         }
549
550         // This will be reintroduced with a new function
551         //void release() { detach(); }
552
553         void reset() { detach(); }
554
555         //! Creates a new instance of a T object and puts it in the handle.
556         /*! Uses the default constructor */
557         void spawn() { operator=(handle<value_type>(new T())); }
558
559         //! Returns number of reversible instances
560         count_type
561         rcount()const
562         {
563 //              value_type*const& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
564                 return obj?obj->rcount():0;
565         }
566
567         //! Returns true if there is only one instance of the object
568         bool
569         runique()const
570         {
571 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
572                 assert(obj); return obj->front_==obj->back_;
573         }
574
575         //! \writeme
576         int replace(const handle<value_type> &x)
577         {
578 //              value_type*& obj(handle<T>::obj); // Required to keep gcc 3.4.2 from barfing
579                 assert(obj);
580                 assert(x.get()!=obj);
581
582                 if(x.get()==obj)
583                         return 0;
584
585                 rhandle<value_type> *iter;
586                 rhandle<value_type> *next;
587
588                 iter=reinterpret_cast<rhandle<value_type>*>(obj->front_);
589
590                 assert(iter);
591
592                 next=iter->next_;
593
594                 int i=0;
595                 #ifndef NDEBUG
596                 pointer obj_=obj;
597                 #endif
598
599                 for(;iter;iter=next,next=iter?iter->next_:0,i++)
600                 {
601                         assert(iter->get()==obj_);
602                         (*iter)=x;
603                 }
604
605                 assert(obj==x.get());
606
607                 return i;
608         }
609
610         //! Swaps the values of two handles without reference counts
611         /*!     \warning not yet implemented. \writeme */
612         handle<value_type> &
613         swap(handle<value_type> &x);
614         /*
615         {
616                 assert(0);
617                 pointer ptr=x.obj;
618                 x.obj=x.get();
619                 obj=ptr;
620                 return *this;
621         }
622         */
623 }; // END of template class rhandle
624
625
626 // ========================================================================
627 /*!     \class  loose_handle _handle.h  ETL/handle
628 **      \brief  Loose Object Handle
629 **      \see shared_object, handle
630 **      \writeme
631 */
632 template <class T>
633 class loose_handle
634 {
635 public:
636
637         typedef T value_type;
638         typedef T& reference;
639         typedef const T& const_reference;
640         typedef T* pointer;
641         typedef const T* const_pointer;
642         typedef int count_type;
643         typedef int size_type;
644
645 protected:
646         value_type *obj;                //!< Pointer to object
647
648 public:
649
650         //! Default constructor - empty handle
651         loose_handle():obj(0) {}
652
653         //! Constructor that constructs from a pointer to new object
654         loose_handle(pointer x):obj(x) { }
655
656         //! Default copy constructor
657         loose_handle(const loose_handle<value_type> &x):obj(x.get()) { }
658
659         loose_handle(const handle<value_type> &x):obj(x.get()) { }
660
661         template <class U> const loose_handle<value_type> &
662         operator=(const handle<U> &x)
663         {
664                 if(x.get()==obj)
665                         return *this;
666
667                 obj=static_cast<value_type*>(x.get());
668                 return *this;
669         }
670
671         template <class U> const loose_handle<value_type> &
672         operator=(const loose_handle<U> &x)
673         {
674                 if(x.get()==obj)
675                         return *this;
676
677                 obj=static_cast<value_type*>(x.get());
678                 return *this;
679         }
680
681         //! Assignment operator
682         const loose_handle<value_type> &
683         operator=(const loose_handle<value_type> &x)
684         {
685                 if(x.get()==obj)
686                         return *this;
687
688                 obj=x.get();
689                 return *this;
690         }
691
692         //! Swaps the values of two handles without reference counts
693         loose_handle<value_type> &
694         swap(loose_handle<value_type> &x)
695         {
696                 pointer ptr=x.obj;
697                 x.obj=x.get();
698                 obj=ptr;
699                 return *this;
700         }
701
702         //! Handle release procedure
703         void detach() { obj=0;  }
704
705         // This will be reintroduced with a new function
706         //void release() { detach(); }
707
708         void reset() { detach(); }
709
710         bool empty()const { return obj==0; }
711
712         handle<value_type> clone()const { assert(obj); return obj->clone(); }
713
714         //! Returns a constant handle to our object
715         loose_handle<const value_type> constant()const { return *this; }
716
717         //! Returns number of instances
718         count_type
719         count()const
720                 { return obj?obj->count():0; }
721
722         reference
723         operator*()const
724                 { assert(obj); return *obj; }
725
726         pointer
727         operator->()const
728                 { assert(obj); return obj; }
729
730         //! static_cast<> overload
731         //template <class U>
732         //operator loose_handle<U>()const
733         //{ return loose_handle<U>(static_cast<U*>(obj)); }
734
735         //! static_cast<> overload (for consts)
736         operator loose_handle<const value_type>()const
737         { return loose_handle<const value_type>(static_cast<const_pointer>(obj)); }
738
739         operator handle<value_type>()const
740         { return handle<value_type>(obj); }
741
742         operator rhandle<value_type>()const
743         { return rhandle<value_type>(obj); }
744
745         //! Returns pointer to the object that is being wrapped
746         pointer get()const { return obj; }
747
748         //! More explicit bool cast
749         operator bool()const
750                 { return obj!=0; }
751
752         bool
753         operator!()const
754                 { return !obj; }
755
756         void ref() { if(obj)obj->ref(); }
757
758         bool unref() { if(obj && !obj->unref()){ obj=0; return false; } return true; }
759 }; // END of template class loose_handle
760
761 // cast loose_handle<> -> handle<>
762 template <class T> template <class U> handle<T> handle<T>::cast_static     (const loose_handle<U>& x) { return handle<T>(static_cast     <T*>(x.get())); }
763 template <class T> template <class U> handle<T> handle<T>::cast_dynamic    (const loose_handle<U>& x) { return handle<T>(dynamic_cast    <T*>(x.get())); }
764 template <class T> template <class U> handle<T> handle<T>::cast_const      (const loose_handle<U>& x) { return handle<T>(const_cast              <T*>(x.get())); }
765 template <class T> template <class U> handle<T> handle<T>::cast_reinterpret(const loose_handle<U>& x) { return handle<T>(reinterpret_cast<T*>(x.get())); }
766
767 // cast rhandle_handle<> -> handle<>
768 template <class T> template <class U> handle<T> handle<T>::cast_static     (const rhandle<U>&      x) { return handle<T>(static_cast     <T*>(x.get())); }
769 template <class T> template <class U> handle<T> handle<T>::cast_dynamic    (const rhandle<U>&      x) { return handle<T>(dynamic_cast    <T*>(x.get())); }
770 template <class T> template <class U> handle<T> handle<T>::cast_const      (const rhandle<U>&      x) { return handle<T>(const_cast              <T*>(x.get())); }
771 template <class T> template <class U> handle<T> handle<T>::cast_reinterpret(const rhandle<U>&      x) { return handle<T>(reinterpret_cast<T*>(x.get())); }
772
773 // cast U* -> handle<>
774 template <class T> template <class U> handle<T> handle<T>::cast_static     (U*                                     x) { return handle<T>(static_cast     <T*>(x));               }
775 template <class T> template <class U> handle<T> handle<T>::cast_dynamic    (U*                                     x) { return handle<T>(dynamic_cast    <T*>(x));               }
776 template <class T> template <class U> handle<T> handle<T>::cast_const      (U*                                     x) { return handle<T>(const_cast              <T*>(x));               }
777 template <class T> template <class U> handle<T> handle<T>::cast_reinterpret(U*                                     x) { return handle<T>(reinterpret_cast<T*>(x));               }
778
779 // operator== for handle<>, loose_handle<> and T*
780 template <class T,class U> bool operator==(const handle          <T>& lhs,const handle          <U>& rhs) { return (lhs.get()==rhs.get()); }
781 template <class T,class U> bool operator==(const loose_handle<T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()==rhs.get()); }
782 template <class T,class U> bool operator==(const handle          <T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()==rhs.get()); }
783 template <class T,class U> bool operator==(const loose_handle<T>& lhs,const handle              <U>& rhs) { return (lhs.get()==rhs.get()); }
784 template <class T>                 bool operator==(const handle<T>&               lhs,const T*                           rhs) { return (lhs.get()==rhs);           }
785 template <class T>                 bool operator==(const loose_handle<T>& lhs,const T*                           rhs) { return (lhs.get()==rhs);           }
786 template <class T>                 bool operator==(const T*                               lhs,const handle<T>&           rhs) { return (lhs              ==rhs.get()); }
787 template <class T>                 bool operator==(const T*                               lhs,const loose_handle<T>& rhs) { return (lhs          ==rhs.get()); }
788
789 // operator!= for handle<>, loose_handle<> and T*
790 template <class T,class U> bool operator!=(const handle          <T>& lhs,const handle          <U>& rhs) { return (lhs.get()!=rhs.get()); }
791 template <class T,class U> bool operator!=(const loose_handle<T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()!=rhs.get()); }
792 template <class T,class U> bool operator!=(const handle          <T>& lhs,const loose_handle<U>& rhs) { return (lhs.get()!=rhs.get()); }
793 template <class T,class U> bool operator!=(const loose_handle<T>& lhs,const handle              <U>& rhs) { return (lhs.get()!=rhs.get()); }
794 template <class T>                 bool operator!=(const handle<T>&               lhs,const T*                           rhs) { return (lhs.get()!=rhs);           }
795 template <class T>                 bool operator!=(const loose_handle<T>& lhs,const T*                           rhs) { return (lhs.get()!=rhs);           }
796 template <class T>                 bool operator!=(const T*                               lhs,const handle<T>&           rhs) { return (lhs              !=rhs.get()); }
797 template <class T>                 bool operator!=(const T*                               lhs,const loose_handle<T>& rhs) { return (lhs          !=rhs.get()); }
798
799 // operator< for handle<>, loose_handle<> and T*
800 template <class T,class U> bool operator<(const handle<T>&                lhs,const handle<U>&           rhs) { return (lhs.get()<rhs.get());  }
801 template <class T,class U> bool operator<(const loose_handle<T>&  lhs,const loose_handle<U>& rhs) { return (lhs.get()<rhs.get());  }
802 template <class T,class U> bool operator<(const handle<T>&                lhs,const loose_handle<U>& rhs) { return (lhs.get()<rhs.get());  }
803 template <class T,class U> bool operator<(const loose_handle<T>&  lhs,const handle<U>&           rhs) { return (lhs.get()<rhs.get());  }
804 template <class T>                 bool operator<(const handle<T>&                lhs,const T*                           rhs) { return (lhs.get()<rhs);            }
805 template <class T>                 bool operator<(const loose_handle<T>&  lhs,const T*                           rhs) { return (lhs.get()<rhs);            }
806 template <class T>                 bool operator<(const T*                                lhs,const handle<T>&           rhs) { return (lhs              <rhs.get());  }
807 template <class T>                 bool operator<(const T*                                lhs,const loose_handle<T>& rhs) { return (lhs          <rhs.get());  }
808
809 _ETL_END_NAMESPACE
810
811 /* === E N D =============================================================== */
812
813 #endif