LCOV - code coverage report
Current view: top level - svl/source/misc - getstringresource.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 15 0.0 %
Date: 2014-11-03 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 <i18nlangtag/languagetag.hxx>
      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(LanguageTag const & locale);
      43             : 
      44             : private:
      45             :     typedef std::map< 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(LanguageTag const & locale) {
      62           0 :     OUString code( locale.getBcp47());
      63           0 :     Map::iterator i(map_.find(code));
      64           0 :     if (i == map_.end()) {
      65             :         boost::scoped_ptr< SimpleResMgr > mgr(
      66           0 :             new SimpleResMgr("svl", locale));
      67           0 :         i = map_.insert(Map::value_type(code, mgr.get())).first;
      68           0 :         mgr.reset();
      69             :     }
      70           0 :     return i->second;
      71             : }
      72             : 
      73             : struct theResMgrMap: public rtl::Static< ResMgrMap, theResMgrMap > {};
      74             : 
      75             : }
      76             : 
      77             : namespace svl {
      78             : 
      79           0 : OUString getStringResource(sal_uInt16 id, LanguageTag const & locale)
      80             : {
      81           0 :     return theResMgrMap::get().get(locale)->ReadString(id);
      82             : }
      83             : 
      84             : }
      85             : 
      86             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10