$extrastylesheet
reference_counter.C
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 // C++ includes
00021 #include <iostream>
00022 #include <sstream>
00023 
00024 // Local includes
00025 #include "libmesh/reference_counter.h"
00026 
00027 namespace libMesh
00028 {
00029 
00030 
00031 
00032 // ------------------------------------------------------------
00033 // ReferenceCounter class static member initializations
00034 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
00035 
00036 ReferenceCounter::Counts ReferenceCounter::_counts;
00037 
00038 #endif
00039 
00040 bool ReferenceCounter::_enable_print_counter = true;
00041 Threads::atomic<unsigned int> ReferenceCounter::_n_objects;
00042 Threads::spin_mutex  ReferenceCounter::_mutex;
00043 
00044 
00045 // ------------------------------------------------------------
00046 // ReferenceCounter class members
00047 std::string ReferenceCounter::get_info ()
00048 {
00049 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
00050 
00051   std::ostringstream oss;
00052 
00053   oss << '\n'
00054       << " ---------------------------------------------------------------------------- \n"
00055       << "| Reference count information                                                |\n"
00056       << " ---------------------------------------------------------------------------- \n";
00057 
00058   for (Counts::iterator it = _counts.begin();
00059        it != _counts.end(); ++it)
00060     {
00061       const std::string name(it->first);
00062       const unsigned int creations    = it->second.first;
00063       const unsigned int destructions = it->second.second;
00064 
00065       oss << "| " << name << " reference count information:\n"
00066           << "|  Creations:    " << creations    << '\n'
00067           << "|  Destructions: " << destructions << '\n';
00068     }
00069 
00070   oss << " ---------------------------------------------------------------------------- \n";
00071 
00072   return oss.str();
00073 
00074 #else
00075 
00076   return "";
00077 
00078 #endif
00079 }
00080 
00081 
00082 
00083 
00084 
00085 // avoid unused variable warnings
00086 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
00087 
00088 void ReferenceCounter::print_info (std::ostream &out_stream)
00089 {
00090   if( _enable_print_counter ) out_stream << ReferenceCounter::get_info();
00091 }
00092 
00093 #else
00094 
00095 void ReferenceCounter::print_info (std::ostream & /* out_stream */)
00096 {}
00097 
00098 #endif
00099 
00100 void ReferenceCounter::enable_print_counter_info()
00101 {
00102   _enable_print_counter = true;
00103   return;
00104 }
00105 
00106 void ReferenceCounter::disable_print_counter_info()
00107 {
00108   _enable_print_counter = false;
00109   return;
00110 }
00111 
00112 } // namespace libMesh