LCOV - code coverage report
Current view: top level - libreoffice/svl/source/misc - getstringresource.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 18 0.0 %
Date: 2012-12-27 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include <map>
      23             : 
      24             : #include "boost/noncopyable.hpp"
      25             : #include "boost/scoped_ptr.hpp"
      26             : #include "com/sun/star/lang/Locale.hpp"
      27             : #include "rtl/instance.hxx"
      28             : #include "rtl/ustrbuf.hxx"
      29             : #include "rtl/ustring.hxx"
      30             : #include "sal/types.h"
      31             : #include "tools/resmgr.hxx"
      32             : #include "tools/simplerm.hxx"
      33             : 
      34             : #include "getstringresource.hxx"
      35             : 
      36             : namespace {
      37             : 
      38           0 : class ResMgrMap: private boost::noncopyable {
      39             : public:
      40             :     ~ResMgrMap();
      41             : 
      42             :     SimpleResMgr * get(css::lang::Locale const & locale);
      43             : 
      44             : private:
      45             :     typedef std::map< rtl::OUString, SimpleResMgr * > Map;
      46             : 
      47             :     Map map_;
      48             :         // one SimpleResMgr for each language for which a resource was requested
      49             :         // (when using the "non-simple" resmgr, the first request for any
      50             :         // language wins, any further requests for any other languages supply
      51             :         // the resmgr of the first call; for the simple resmgr we have a mgr
      52             :         // for each language ever requested)
      53             : };
      54             : 
      55           0 : ResMgrMap::~ResMgrMap() {
      56           0 :     for (Map::iterator i(map_.begin()); i != map_.end(); ++i) {
      57           0 :         delete i->second;
      58             :     }
      59           0 : }
      60             : 
      61           0 : SimpleResMgr * ResMgrMap::get(css::lang::Locale const & locale) {
      62           0 :     rtl::OUStringBuffer buf(locale.Language);
      63           0 :     buf.append(sal_Unicode('-'));
      64           0 :     buf.append(locale.Country);
      65           0 :     rtl::OUString code(buf.makeStringAndClear());
      66           0 :     Map::iterator i(map_.find(code));
      67           0 :     if (i == map_.end()) {
      68             :         boost::scoped_ptr< SimpleResMgr > mgr(
      69           0 :             new SimpleResMgr("svl", locale));
      70           0 :         i = map_.insert(Map::value_type(code, mgr.get())).first;
      71           0 :         mgr.reset();
      72             :     }
      73           0 :     return i->second;
      74             : }
      75             : 
      76             : struct theResMgrMap: public rtl::Static< ResMgrMap, theResMgrMap > {};
      77             : 
      78             : }
      79             : 
      80             : namespace svl {
      81             : 
      82           0 : rtl::OUString getStringResource(sal_uInt16 id, css::lang::Locale const & locale)
      83             : {
      84           0 :     return theResMgrMap::get().get(locale)->ReadString(id);
      85             : }
      86             : 
      87             : }
      88             : 
      89             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10