libstdc++
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-2013 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file bits/time_members.h
00026  *  This is an internal header file, included by other library headers.
00027  *  Do not attempt to use it directly. @headername{locale}
00028  */
00029 
00030 //
00031 // ISO C++ 14882: 22.2.5.1.2 - time_get functions
00032 // ISO C++ 14882: 22.2.5.3.2 - time_put functions
00033 //
00034 
00035 // Written by Benjamin Kosnik <bkoz@redhat.com>
00036 
00037 namespace std _GLIBCXX_VISIBILITY(default)
00038 {
00039 _GLIBCXX_BEGIN_NAMESPACE_VERSION
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_VERSION
00089 } // namespace