casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
nullptr.h
Go to the documentation of this file.
00001 //# nullptr.h: pointer classes (currently only counted pointer) used within casadbus
00002 //#
00003 //# Copyright (C) 2011
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id$
00028 
00029 #ifndef __casadbus_nullptr_h__
00030 #define __casadbus_nullptr_h__
00031 #include <tr1/memory>
00032 
00033 namespace casa {
00034 
00035     namespace memory {
00036 
00037         class _nullptr_t_ {
00038             public:
00039                 template<typename T> operator std::tr1::shared_ptr<T>( ) const { return std::tr1::shared_ptr<T>( ); }
00040                 template<typename T> bool check( const std::tr1::shared_ptr<T> &o ) const { return o == std::tr1::shared_ptr<T>( ); }
00041             private:
00042                 friend class nullptr_init_;
00043                 void do_init( ) { }
00044         };
00045 
00046         extern _nullptr_t_ nullptr;
00047 
00048         static class nullptr_init_ {
00049             public:
00050                 nullptr_init_( ) { if ( count++ == 0 ) do_init( ); }
00051                 ~nullptr_init_( ) { if ( --count == 0 ) { /* could destruct nullptr */ } }
00052             private:
00053                 static unsigned int count;
00054                 void do_init( );
00055         } _nullptr_init_object_;
00056 
00057     }
00058 }
00059 
00060 #endif