time_members.h

Go to the documentation of this file.
00001 // std::time_get, std::time_put implementation, GNU version -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
00004 // 2009, 2010
00005 // Free Software Foundation, Inc.
00006 //
00007 // This file is part of the GNU ISO C++ Library.  This library is free
00008 // software; you can redistribute it and/or modify it under the
00009 // terms of the GNU General Public License as published by the
00010 // Free Software Foundation; either version 3, or (at your option)
00011 // any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 // Under Section 7 of GPL version 3, you are granted additional
00019 // permissions described in the GCC Runtime Library Exception, version
00020 // 3.1, as published by the Free Software Foundation.
00021 
00022 // You should have received a copy of the GNU General Public License and
00023 // a copy of the GCC Runtime Library Exception along with this program;
00024 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00025 // <http://www.gnu.org/licenses/>.
00026 
00027 /** @file time_members.h
00028  *  This is an internal header file, included by other library headers.
00029  *  You should not attempt to use it directly.
00030  */
00031 
00032 //
00033 // ISO C++ 14882: 22.2.5.1.2 - time_get functions
00034 // ISO C++ 14882: 22.2.5.3.2 - time_put functions
00035 //
00036 
00037 // Written by Benjamin Kosnik <bkoz@redhat.com>
00038 
00039 _GLIBCXX_BEGIN_NAMESPACE(std)
00040 
00041   template<typename _CharT>
00042     __timepunct<_CharT>::__timepunct(size_t __refs) 
00043     : facet(__refs), _M_data(0), _M_c_locale_timepunct(0), 
00044       _M_name_timepunct(_S_get_c_name())
00045     { _M_initialize_timepunct(); }
00046 
00047   template<typename _CharT>
00048     __timepunct<_CharT>::__timepunct(__cache_type* __cache, size_t __refs) 
00049     : facet(__refs), _M_data(__cache), _M_c_locale_timepunct(0), 
00050       _M_name_timepunct(_S_get_c_name())
00051     { _M_initialize_timepunct(); }
00052 
00053   template<typename _CharT>
00054     __timepunct<_CharT>::__timepunct(__c_locale __cloc, const char* __s,
00055                      size_t __refs) 
00056     : facet(__refs), _M_data(0), _M_c_locale_timepunct(0), 
00057       _M_name_timepunct(0)
00058     {
00059       if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
00060     {
00061       const size_t __len = __builtin_strlen(__s) + 1;
00062       char* __tmp = new char[__len];
00063       __builtin_memcpy(__tmp, __s, __len);
00064       _M_name_timepunct = __tmp;
00065     }
00066       else
00067     _M_name_timepunct = _S_get_c_name();
00068 
00069       __try
00070     { _M_initialize_timepunct(__cloc); }
00071       __catch(...)
00072     {
00073       if (_M_name_timepunct != _S_get_c_name())
00074         delete [] _M_name_timepunct;
00075       __throw_exception_again;
00076     }
00077     }
00078 
00079   template<typename _CharT>
00080     __timepunct<_CharT>::~__timepunct()
00081     { 
00082       if (_M_name_timepunct != _S_get_c_name())
00083     delete [] _M_name_timepunct;
00084       delete _M_data; 
00085       _S_destroy_c_locale(_M_c_locale_timepunct); 
00086     }
00087 
00088 _GLIBCXX_END_NAMESPACE