/src/mozilla-central/intl/strres/nsStringBundle.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef nsStringBundle_h__ |
7 | | #define nsStringBundle_h__ |
8 | | |
9 | | #include "mozilla/Mutex.h" |
10 | | #include "nsIStringBundle.h" |
11 | | #include "nsIMemoryReporter.h" |
12 | | #include "nsCOMPtr.h" |
13 | | #include "nsString.h" |
14 | | #include "nsCOMArray.h" |
15 | | |
16 | | class nsIPersistentProperties; |
17 | | |
18 | | |
19 | | class nsStringBundleBase : public nsIStringBundle |
20 | | , public nsIMemoryReporter |
21 | | { |
22 | | public: |
23 | | MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf) |
24 | | |
25 | | nsresult ParseProperties(nsIPersistentProperties**); |
26 | | |
27 | | NS_DECL_THREADSAFE_ISUPPORTS |
28 | | NS_DECL_NSISTRINGBUNDLE |
29 | | NS_DECL_NSIMEMORYREPORTER |
30 | | |
31 | | virtual nsresult LoadProperties() = 0; |
32 | | |
33 | 0 | const nsCString& BundleURL() const { return mPropertiesURL; } |
34 | | |
35 | | // Returns true if this bundle has more than one reference. If it has only |
36 | | // a single reference, it is assumed to be held alive by the bundle cache. |
37 | 0 | bool IsShared() const { return mRefCnt > 1; } |
38 | | |
39 | | static nsStringBundleBase* Cast(nsIStringBundle* aBundle) |
40 | 0 | { |
41 | 0 | return static_cast<nsStringBundleBase*>(aBundle); |
42 | 0 | } |
43 | | |
44 | | template <typename T, typename... Args> |
45 | | static already_AddRefed<T> Create(Args... args); |
46 | | |
47 | | protected: |
48 | | nsStringBundleBase(const char* aURLSpec); |
49 | | |
50 | | virtual ~nsStringBundleBase(); |
51 | | |
52 | | virtual nsresult GetStringImpl(const nsACString& aName, nsAString& aResult) = 0; |
53 | | |
54 | | virtual nsresult GetSimpleEnumerationImpl(nsISimpleEnumerator** elements) = 0; |
55 | | |
56 | | void RegisterMemoryReporter(); |
57 | | |
58 | | nsCString mPropertiesURL; |
59 | | mozilla::Mutex mMutex; |
60 | | bool mAttemptedLoad; |
61 | | bool mLoaded; |
62 | | |
63 | | size_t SizeOfIncludingThisIfUnshared(mozilla::MallocSizeOf aMallocSizeOf) const override; |
64 | | |
65 | | public: |
66 | | static nsresult FormatString(const char16_t *formatStr, |
67 | | const char16_t **aParams, uint32_t aLength, |
68 | | nsAString& aResult); |
69 | | }; |
70 | | |
71 | | class nsStringBundle : public nsStringBundleBase |
72 | | { |
73 | | public: |
74 | | NS_DECL_ISUPPORTS_INHERITED |
75 | | |
76 | | nsCOMPtr<nsIPersistentProperties> mProps; |
77 | | |
78 | | nsresult LoadProperties() override; |
79 | | |
80 | | size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; |
81 | | |
82 | | protected: |
83 | | friend class nsStringBundleBase; |
84 | | |
85 | | explicit nsStringBundle(const char* aURLSpec); |
86 | | |
87 | | virtual ~nsStringBundle(); |
88 | | |
89 | | nsresult GetStringImpl(const nsACString& aName, nsAString& aResult) override; |
90 | | |
91 | | nsresult GetSimpleEnumerationImpl(nsISimpleEnumerator** elements) override; |
92 | | }; |
93 | | |
94 | | #endif |