libstdc++
time_members.h
Go to the documentation of this file.
1 // std::time_get, std::time_put implementation, GNU version -*- C++ -*-
2 
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11 
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20 
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
25 
26 /** @file time_members.h
27  * This is an internal header file, included by other library headers.
28  * You should not attempt to use it directly.
29  */
30 
31 //
32 // ISO C++ 14882: 22.2.5.1.2 - time_get functions
33 // ISO C++ 14882: 22.2.5.3.2 - time_put functions
34 //
35 
36 // Written by Benjamin Kosnik <bkoz@redhat.com>
37 
38 _GLIBCXX_BEGIN_NAMESPACE(std)
39 
40  template<typename _CharT>
41  __timepunct<_CharT>::__timepunct(size_t __refs)
42  : facet(__refs), _M_data(NULL), _M_c_locale_timepunct(NULL),
43  _M_name_timepunct(_S_get_c_name())
44  { _M_initialize_timepunct(); }
45 
46  template<typename _CharT>
47  __timepunct<_CharT>::__timepunct(__cache_type* __cache, size_t __refs)
48  : facet(__refs), _M_data(__cache), _M_c_locale_timepunct(NULL),
49  _M_name_timepunct(_S_get_c_name())
50  { _M_initialize_timepunct(); }
51 
52  template<typename _CharT>
53  __timepunct<_CharT>::__timepunct(__c_locale __cloc, const char* __s,
54  size_t __refs)
55  : facet(__refs), _M_data(NULL), _M_c_locale_timepunct(NULL),
56  _M_name_timepunct(NULL)
57  {
58  if (__builtin_strcmp(__s, _S_get_c_name()) != 0)
59  {
60  const size_t __len = __builtin_strlen(__s) + 1;
61  char* __tmp = new char[__len];
62  __builtin_memcpy(__tmp, __s, __len);
63  _M_name_timepunct = __tmp;
64  }
65  else
66  _M_name_timepunct = _S_get_c_name();
67 
68  __try
69  { _M_initialize_timepunct(__cloc); }
70  __catch(...)
71  {
72  if (_M_name_timepunct != _S_get_c_name())
73  delete [] _M_name_timepunct;
74  __throw_exception_again;
75  }
76  }
77 
78  template<typename _CharT>
79  __timepunct<_CharT>::~__timepunct()
80  {
81  if (_M_name_timepunct != _S_get_c_name())
82  delete [] _M_name_timepunct;
83  delete _M_data;
84  _S_destroy_c_locale(_M_c_locale_timepunct);
85  }
86 
87 _GLIBCXX_END_NAMESPACE
ISO C++ entities toplevel namespace is std.