genericopenlibs/cppstdlib/stl/src/libstdcppwsd.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : libstdcppwsd.cpp
       
    15 // Part of     : standard c++ library.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "stlport_prefix.h"
       
    20 #include "stl/_threads.h"
       
    21 #include <locale>
       
    22 #include <libstdcppwsd.h>
       
    23 #include "locale_impl.h"
       
    24 
       
    25 #ifdef __SYMBIAN32__WSD__   //stuff for WSD
       
    26 
       
    27 //constructor
       
    28 EXPORT_C _Libcpp_wsd::_Libcpp_wsd()
       
    29 	 : ios_base_Init_S_count(0), 
       
    30 	    _IosInit(NULL),
       
    31 		wsd_cin(NULL),
       
    32 		wsd_cout(NULL),
       
    33 		wsd_cerr(NULL),
       
    34 		wsd_clog(NULL),
       
    35 #ifndef _STLP_NO_WCHAR_T
       
    36 		wsd_wcin(NULL),
       
    37 		wsd_wcout(NULL),
       
    38 		wsd_wcerr(NULL),
       
    39 		wsd_wclog(NULL),
       
    40 #endif	
       
    41 		is_Initialized(false),
       
    42 		_Stl_classic_locale(NULL),
       
    43 		_Stl_global_locale(NULL)
       
    44 		{ /* do nothing */ }
       
    45 	
       
    46 //destructor	
       
    47 EXPORT_C _Libcpp_wsd::~_Libcpp_wsd()
       
    48 		{
       
    49 		//Free the internal allocations
       
    50 		if( _IosInit != NULL )
       
    51 			{
       
    52 			_IosInit->~Init();
       
    53 			WSDFree(_IosInit);
       
    54 			}
       
    55 		if( wsd_cin != NULL )
       
    56 			{
       
    57 			wsd_cin->~basic_istream();
       
    58 			WSDFree(wsd_cin);
       
    59 			}
       
    60 		if( wsd_cout != NULL )
       
    61 			{
       
    62 			wsd_cout->~basic_ostream();
       
    63 			WSDFree(wsd_cout);
       
    64 			}
       
    65 		if( wsd_cerr != NULL )
       
    66 			{
       
    67 			wsd_cerr->~basic_ostream();
       
    68 			WSDFree(wsd_cerr);
       
    69 			}
       
    70 		if( wsd_clog != NULL )
       
    71 			{
       
    72 			wsd_clog->~basic_ostream();
       
    73 			WSDFree(wsd_clog);
       
    74 			}
       
    75 		if( wsd_wcin != NULL )
       
    76 			{
       
    77 			wsd_wcin->~basic_istream();
       
    78 			WSDFree(wsd_wcin);
       
    79 			}
       
    80 		if( wsd_wcout != NULL )
       
    81 			{
       
    82 			wsd_wcout->~basic_ostream();
       
    83 			WSDFree(wsd_wcout);
       
    84 			}
       
    85 		if( wsd_wcerr != NULL )
       
    86 			{
       
    87 			wsd_wcerr->~basic_ostream();
       
    88 			WSDFree(wsd_wcerr);
       
    89 			}
       
    90 		if( wsd_wclog != NULL )
       
    91 			{
       
    92 			wsd_wclog->~basic_ostream();
       
    93 			WSDFree(wsd_wclog);
       
    94 			}
       
    95 		if( _Stl_global_locale != NULL )
       
    96 			{
       
    97 			_Stl_global_locale->~locale();
       
    98 			WSDFree(_Stl_global_locale);
       
    99 			}
       
   100 		if( _Stl_classic_locale != NULL )
       
   101 			{
       
   102 			_Stl_classic_locale->~locale();
       
   103 			WSDFree(_Stl_classic_locale);
       
   104 			}
       
   105 			
       
   106 		if( _Loc_init_S_count != NULL )
       
   107 			WSDFree(_Loc_init_S_count);	
       
   108 		}
       
   109 
       
   110 EXPORT_C void CleanupWSD() 
       
   111 	{
       
   112 	_Libcpp_wsd* wsdPtr = Pls<_Libcpp_wsd>(KLibstdcppUID, NULL);
       
   113 	wsdPtr->~_Libcpp_wsd();
       
   114 	}
       
   115 
       
   116 EXPORT_C _Libcpp_wsd& get_libcpp_wsd()
       
   117 	{
       
   118 	//get the TLS pointer
       
   119 	_Libcpp_wsd* g_libcpp_wsd = Pls<_Libcpp_wsd>(KLibstdcppUID, NULL);
       
   120 	if(g_libcpp_wsd->is_Initialized != true)
       
   121 		{
       
   122 		//this has to be here to avoid infinite recursion
       
   123 		g_libcpp_wsd->is_Initialized = true;
       
   124 
       
   125 #ifdef _STLP_DEBUG
       
   126 		get_Nameless() = new std::string("*");
       
   127 #endif
       
   128 		//initialize allocator static data
       
   129 		stdcpp_allocators_init();
       
   130 
       
   131 		//initialize the page size
       
   132 		filebuf_page_size_init();
       
   133 
       
   134 		//initialize _S_count of _Loc_init
       
   135 		// Calling placement new on internally alloc'ed memory.
       
   136 		g_libcpp_wsd->_Loc_init_S_count = new (WSDAlloc(sizeof(std::_Refcount_Base))) std::_Refcount_Base(0);
       
   137 
       
   138 		std::_Locale_impl::Init::Init();
       
   139 		// Calling placement new on internally alloc'ed memory.
       
   140 		g_libcpp_wsd->_IosInit = new (WSDAlloc(sizeof(std::ios_base::Init))) std::ios_base::Init();
       
   141 		}
       
   142 	return (*g_libcpp_wsd);
       
   143 	}
       
   144 
       
   145 
       
   146 /******************** threads related *****************/
       
   147 //
       
   148 _STLP_DECLSPEC std::_STLP_STATIC_MUTEX& exp_get_threads_S_swap_lock() 
       
   149 	{
       
   150 	return get_libcpp_wsd()._threads_S_swap_lock;
       
   151 	}
       
   152 
       
   153 _STLP_DECLSPEC std::_STLP_STATIC_MUTEX& exp_get_threads_0_S_swap_lock() 
       
   154 	{
       
   155   	return get_libcpp_wsd()._threads_0_S_swap_lock;
       
   156 	}
       
   157 
       
   158 
       
   159 
       
   160 // locale::id
       
   161 //ACCESS FUNCTIONS
       
   162 _STLP_DECLSPEC std::locale::id&
       
   163 std::codecvt<char, char, mbstate_t>::GetFacetLocaleId()
       
   164     {
       
   165     	return get_libcpp_wsd().codecvt_char_char_mbstate_id;
       
   166     }
       
   167 
       
   168 
       
   169 _STLP_DECLSPEC std::locale::id&
       
   170 std::codecvt<wchar_t, char, mbstate_t>::GetFacetLocaleId()
       
   171     {
       
   172    	 	return get_libcpp_wsd().codecvt_wchar_char_mbstate_id;
       
   173     }
       
   174 
       
   175 _STLP_DECLSPEC std::locale::id&
       
   176 std::collate<char>::GetFacetLocaleId()
       
   177     {
       
   178    		return get_libcpp_wsd().collate_char_id;
       
   179     }
       
   180 
       
   181 _STLP_DECLSPEC std::locale::id&
       
   182 std::ctype<char>::GetFacetLocaleId()
       
   183     {
       
   184     	return get_libcpp_wsd().ctype_char_id;
       
   185     }
       
   186 
       
   187 _STLP_DECLSPEC std::locale::id&
       
   188 std::moneypunct<char, true>::GetFacetLocaleId()
       
   189 	{
       
   190 		return get_libcpp_wsd().moneypunct_char_true_id;
       
   191 	}
       
   192 
       
   193 _STLP_DECLSPEC std::locale::id&
       
   194 std::moneypunct<char, false>::GetFacetLocaleId()
       
   195     {
       
   196     	return get_libcpp_wsd().moneypunct_char_false_id;
       
   197     }
       
   198 
       
   199 _STLP_DECLSPEC std::locale::id&
       
   200 std::messages<char>::GetFacetLocaleId()
       
   201     {
       
   202     	return get_libcpp_wsd().messages_char_id;
       
   203     }
       
   204 
       
   205 _STLP_DECLSPEC std::locale::id&
       
   206 std::numpunct<char>::GetFacetLocaleId()
       
   207     {
       
   208     	return get_libcpp_wsd().numpunct_char_id;
       
   209     }
       
   210 
       
   211 _STLP_DECLSPEC std::locale::id&
       
   212 std::collate<wchar_t>::GetFacetLocaleId()
       
   213 	{
       
   214 		return get_libcpp_wsd().collate_wchar_id;
       
   215 	}
       
   216 
       
   217 _STLP_DECLSPEC std::locale::id&
       
   218 std::ctype<wchar_t>::GetFacetLocaleId()
       
   219 	{
       
   220 		return get_libcpp_wsd().ctype_wchar_id;
       
   221 	}
       
   222 
       
   223 _STLP_DECLSPEC std::locale::id&
       
   224 std::moneypunct<wchar_t, true>::GetFacetLocaleId()
       
   225 	{
       
   226 		return get_libcpp_wsd().moneypunct_wchar_true_id;
       
   227 	}
       
   228 
       
   229 _STLP_DECLSPEC std::locale::id&
       
   230 std::moneypunct<wchar_t, false>::GetFacetLocaleId()
       
   231 	{
       
   232 		return get_libcpp_wsd().moneypunct_wchar_false_id;
       
   233 	}
       
   234 
       
   235 _STLP_DECLSPEC std::locale::id&
       
   236 std::numpunct<wchar_t>::GetFacetLocaleId()
       
   237 	{
       
   238 		return get_libcpp_wsd().numpunct_wchar_id;
       
   239 	}
       
   240 
       
   241 _STLP_DECLSPEC std::locale::id&
       
   242 std::messages<wchar_t>::GetFacetLocaleId()
       
   243 	{
       
   244 		return get_libcpp_wsd().messages_wchar_id;
       
   245 	}
       
   246 
       
   247 #endif  /* __SYMBIAN32__WSD__ */