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 :
10 : #ifndef INCLUDED_SVL_SHAREDSTRINGPOOL_HXX
11 : #define INCLUDED_SVL_SHAREDSTRINGPOOL_HXX
12 :
13 : #include <svl/sharedstring.hxx>
14 : #include <osl/mutex.hxx>
15 :
16 : #include <boost/unordered_map.hpp>
17 : #include <boost/unordered_set.hpp>
18 :
19 : class CharClass;
20 :
21 : namespace svl {
22 :
23 : /**
24 : * Storage for pool of shared strings. It also provides mapping from
25 : * original-cased strings to upper-cased strings for case insensitive
26 : * operations.
27 : */
28 4196 : class SVL_DLLPUBLIC SharedStringPool
29 : {
30 : typedef boost::unordered_set<OUString, OUStringHash> StrHashType;
31 : typedef std::pair<StrHashType::iterator, bool> InsertResultType;
32 : typedef boost::unordered_map<const rtl_uString*, OUString> StrStoreType;
33 :
34 : mutable osl::Mutex maMutex;
35 : StrHashType maStrPool;
36 : StrHashType maStrPoolUpper;
37 : StrStoreType maStrStore;
38 : const CharClass* mpCharClass;
39 :
40 : public:
41 :
42 : SharedStringPool( const CharClass* pCharClass );
43 :
44 : /**
45 : * Intern a string object into the shared string pool.
46 : *
47 : * @param rStr string object to intern.
48 : *
49 : * @return a pointer to the string object stored inside the pool, or NULL
50 : * if the insertion fails.
51 : */
52 : SharedString intern( const OUString& rStr );
53 :
54 : /**
55 : * Go through all string objects in the pool, and clear those that are no
56 : * longer used outside of the pool.
57 : */
58 : void purge();
59 :
60 : size_t getCount() const;
61 :
62 : size_t getCountIgnoreCase() const;
63 :
64 : private:
65 : InsertResultType findOrInsert( StrHashType& rPool, const OUString& rStr ) const;
66 : };
67 :
68 : }
69 :
70 : #endif
71 :
72 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|