casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
State.h
Go to the documentation of this file.
00001 //# State.h: global display state
00002 //# Copyright (C) 2009
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 
00027 #ifndef CASA_DISPLAY_STATE_H_
00028 #define CASA_DISPLAY_STATE_H_
00029 
00030 namespace casa { //# NAMESPACE CASA - BEGIN
00031 
00032     namespace display { //# NAMESPACE DISPLAY - BEGIN
00033         class state {
00034             friend class stateCleanup;
00035         public:
00036 
00037             static state &instance( ) { return initialized == false ? startup( ) : *singleton; }
00038 
00039             // allows classes (primarily in the redisplay chain) to tell if we
00040             // are currently outputing to a file...
00041             bool fileOutputMode( );
00042             // begin file output
00043             void beginFileOutputMode( );
00044             // end file output
00045             void endFileOutputMode( );
00046             
00047         private:
00048 
00049             static state *singleton;
00050 
00051             state( ) : file_output_mode_count_(0) { }
00052             ~state( ) { }
00053 
00054             static state &startup( );
00055             static void shutdown( );
00056 
00057             int file_output_mode_count_;
00058             static bool initialized;
00059 
00060         };
00061 
00062         static class stateCleanup {
00063         public:
00064             stateCleanup( ) { creation_count += 1; }
00065             ~stateCleanup( ) { if ( --creation_count == 0 ) { state::shutdown( ); } }
00066         private:
00067             static unsigned int creation_count;
00068         } local_state_cleanup_object;
00069     }
00070 
00071 }
00072 
00073 #endif