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( ) { 00038 return initialized == false ? startup( ) : *singleton; 00039 } 00040 00041 // allows classes (primarily in the redisplay chain) to tell if we 00042 // are currently outputing to a file... 00043 bool fileOutputMode( ); 00044 // begin file output 00045 void beginFileOutputMode( ); 00046 // end file output 00047 void endFileOutputMode( ); 00048 00049 private: 00050 00051 static state *singleton; 00052 00053 state( ) : file_output_mode_count_(0) { } 00054 ~state( ) { } 00055 00056 static state &startup( ); 00057 static void shutdown( ); 00058 00059 int file_output_mode_count_; 00060 static bool initialized; 00061 00062 }; 00063 00064 static class stateCleanup { 00065 public: 00066 stateCleanup( ) { 00067 creation_count += 1; 00068 } 00069 ~stateCleanup( ) { 00070 if ( --creation_count == 0 ) { 00071 state::shutdown( ); 00072 } 00073 } 00074 private: 00075 static unsigned int creation_count; 00076 } local_state_cleanup_object; 00077 } 00078 00079 } 00080 00081 #endif