From 5ac65b7f11e3cec39f7f1540558884427fec935d Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 14 Apr 2012 20:38:05 +0200 Subject: [PATCH] More cleanup in locale kit, this time regarding namespaces. * it's bad practice to do a 'using ' in a header, as that is very likely to have unintended effects, so drop those from a couple of private Locale headers * adjust files all over the locale kit in order to fix the problems (by explicitly importing the required classes in the implementation files) --- headers/private/locale/DefaultCatalog.h | 6 ++--- headers/private/locale/HashMapCatalog.h | 20 ++++++++--------- headers/private/locale/PlainTextCatalog.h | 7 +++--- .../locale/catalogs/plaintext/Catalog.cpp | 6 +++-- src/bin/locale/dumpcatalog.cpp | 3 +++ src/bin/locale/linkcatkeys.cpp | 11 ++++++---- src/kits/locale/DefaultCatalog.cpp | 17 +++++++++----- src/kits/locale/HashMapCatalog.cpp | 22 +++++++++---------- src/kits/locale/InitLocaleKit.cpp | 8 +++++-- src/kits/locale/LocaleRoster.cpp | 2 ++ src/tools/locale/DefaultCatalog.cpp | 13 ++++++++--- src/tools/locale/PlainTextCatalog.cpp | 11 ++++++++-- src/tools/locale/collectcatkeys.cpp | 3 +++ src/tools/locale/linkcatkeys.cpp | 7 +++++- 14 files changed, 89 insertions(+), 47 deletions(-) diff --git a/headers/private/locale/DefaultCatalog.h b/headers/private/locale/DefaultCatalog.h index be519d3780..5afb733f31 100644 --- a/headers/private/locale/DefaultCatalog.h +++ b/headers/private/locale/DefaultCatalog.h @@ -22,7 +22,7 @@ namespace BPrivate { * but the value-type might change to add support for shortcuts and/or * graphical data (button-images and the like). */ -class DefaultCatalog : public BHashMapCatalog { +class DefaultCatalog : public HashMapCatalog { public: DefaultCatalog(const entry_ref &catalogOwner, const char *language, uint32 fingerprint); @@ -35,7 +35,6 @@ class DefaultCatalog : public BHashMapCatalog { ~DefaultCatalog(); - // implementation for editor-interface: status_t ReadFromFile(const char *path = NULL); status_t ReadFromAttribute(const entry_ref &appOrAddOnRef); @@ -63,13 +62,14 @@ class DefaultCatalog : public BHashMapCatalog { mutable BString fPath; }; + extern "C" status_t default_catalog_get_available_languages(BMessage* availableLanguages, const char* sigPattern, const char* langPattern = NULL, int32 fingerprint = 0); + } // namespace BPrivate -using namespace BPrivate; #endif /* _DEFAULT_CATALOG_H_ */ diff --git a/headers/private/locale/HashMapCatalog.h b/headers/private/locale/HashMapCatalog.h index 9ddc8d5178..a189f35440 100644 --- a/headers/private/locale/HashMapCatalog.h +++ b/headers/private/locale/HashMapCatalog.h @@ -61,14 +61,14 @@ class CatKey { }; -class BHashMapCatalog: public BCatalogAddOn { +class HashMapCatalog: public BCatalogAddOn { protected: uint32 ComputeFingerprint() const; typedef HashMap CatMap; CatMap fCatMap; public: - BHashMapCatalog(const char* signature, const char* language, + HashMapCatalog(const char* signature, const char* language, uint32 fingerprint); // Constructor for normal use // @@ -112,7 +112,7 @@ class BHashMapCatalog: public BCatalogAddOn { public: //CatWalker() {}; // if you use this there is no way to set fPos // properly. - CatWalker(BHashMapCatalog* catalog); + CatWalker(HashMapCatalog* catalog); bool AtEnd() const; const CatKey& GetKey() const; const char *GetValue() const; @@ -129,7 +129,7 @@ class BHashMapCatalog: public BCatalogAddOn { }; -inline BHashMapCatalog::BHashMapCatalog(const char* signature, +inline HashMapCatalog::HashMapCatalog(const char* signature, const char* language, uint32 fingerprint) : BCatalogAddOn(signature, language, fingerprint) @@ -138,7 +138,7 @@ inline BHashMapCatalog::BHashMapCatalog(const char* signature, inline -BHashMapCatalog::CatWalker::CatWalker(BHashMapCatalog* catalog) +HashMapCatalog::CatWalker::CatWalker(HashMapCatalog* catalog) : fPos(catalog->fCatMap.GetIterator()) { @@ -151,14 +151,14 @@ BHashMapCatalog::CatWalker::CatWalker(BHashMapCatalog* catalog) inline bool -BHashMapCatalog::CatWalker::AtEnd() const +HashMapCatalog::CatWalker::AtEnd() const { return atEnd; } inline const CatKey & -BHashMapCatalog::CatWalker::GetKey() const +HashMapCatalog::CatWalker::GetKey() const { assert(!atEnd); return current.key; @@ -166,7 +166,7 @@ BHashMapCatalog::CatWalker::GetKey() const inline const char * -BHashMapCatalog::CatWalker::GetValue() const +HashMapCatalog::CatWalker::GetValue() const { assert(!atEnd); return current.value.String(); @@ -174,7 +174,7 @@ BHashMapCatalog::CatWalker::GetValue() const inline void -BHashMapCatalog::CatWalker::Next() +HashMapCatalog::CatWalker::Next() { if (fPos.HasNext()) { current = fPos.Next(); @@ -185,7 +185,7 @@ BHashMapCatalog::CatWalker::Next() inline status_t -BHashMapCatalog::GetWalker(CatWalker *walker) +HashMapCatalog::GetWalker(CatWalker *walker) { if (!walker) return B_BAD_VALUE; diff --git a/headers/private/locale/PlainTextCatalog.h b/headers/private/locale/PlainTextCatalog.h index 030ee5da3c..154e79fb66 100644 --- a/headers/private/locale/PlainTextCatalog.h +++ b/headers/private/locale/PlainTextCatalog.h @@ -15,7 +15,8 @@ class BFile; namespace BPrivate { -class PlainTextCatalog : public BHashMapCatalog { + +class PlainTextCatalog : public HashMapCatalog { public: PlainTextCatalog(const char *signature, const char *language, uint32 fingerprint); @@ -28,7 +29,6 @@ class PlainTextCatalog : public BHashMapCatalog { ~PlainTextCatalog(); - // implementation for editor-interface: status_t ReadFromFile(const char *path = NULL); status_t WriteToFile(const char *path = NULL); @@ -45,9 +45,8 @@ class PlainTextCatalog : public BHashMapCatalog { mutable BString fPath; }; -} // namespace BPrivate -using BPrivate::PlainTextCatalog; +} // namespace BPrivate #endif /* _PLAINTEXT_CATALOG_H_ */ diff --git a/src/add-ons/locale/catalogs/plaintext/Catalog.cpp b/src/add-ons/locale/catalogs/plaintext/Catalog.cpp index 646ff354af..e2dedb0d82 100644 --- a/src/add-ons/locale/catalogs/plaintext/Catalog.cpp +++ b/src/add-ons/locale/catalogs/plaintext/Catalog.cpp @@ -32,6 +32,8 @@ #include +using BPrivate::HashMapCatalog; +using BPrivate::PlainTextCatalog; using std::auto_ptr; using std::min; using std::max; @@ -77,7 +79,7 @@ escapeQuotedChars(BString& stringToEscape) PlainTextCatalog::PlainTextCatalog(const char *signature, const char *language, uint32 fingerprint) : - BHashMapCatalog(signature, language, fingerprint) + HashMapCatalog(signature, language, fingerprint) { // give highest priority to catalog living in sub-folder of app's folder: app_info appInfo; @@ -137,7 +139,7 @@ PlainTextCatalog::PlainTextCatalog(const char *signature, const char *language, PlainTextCatalog::PlainTextCatalog(const char *path, const char *signature, const char *language) : - BHashMapCatalog(signature, language, 0), + HashMapCatalog(signature, language, 0), fPath(path) { fInitCheck = B_OK; diff --git a/src/bin/locale/dumpcatalog.cpp b/src/bin/locale/dumpcatalog.cpp index 6ba9bf8a8b..c771940c8d 100644 --- a/src/bin/locale/dumpcatalog.cpp +++ b/src/bin/locale/dumpcatalog.cpp @@ -12,6 +12,9 @@ #include #include + +using BPrivate::CatKey; +using BPrivate::DefaultCatalog; using BPrivate::EditableCatalog; diff --git a/src/bin/locale/linkcatkeys.cpp b/src/bin/locale/linkcatkeys.cpp index 2b222c2f25..a9987a570f 100644 --- a/src/bin/locale/linkcatkeys.cpp +++ b/src/bin/locale/linkcatkeys.cpp @@ -14,9 +14,12 @@ #include #include #include -#include + +using BPrivate::CatKey; +using BPrivate::DefaultCatalog; using BPrivate::EditableCatalog; +using BPrivate::HashMapCatalog; using std::vector; @@ -112,8 +115,8 @@ main(int argc, char **argv) inputFiles[i], strerror(res)); exit(-1); } - BHashMapCatalog* inputCatImpl - = dynamic_cast(inputCatalog.CatalogAddOn()); + HashMapCatalog* inputCatImpl + = dynamic_cast(inputCatalog.CatalogAddOn()); if (!inputCatImpl) { fprintf(stderr, "couldn't access impl of input-catalog %s\n", inputFiles[i]); @@ -122,7 +125,7 @@ main(int argc, char **argv) // now walk over all entries in input-catalog and add them to // target catalog, unless they already exist there. - BHashMapCatalog::CatWalker walker(inputCatImpl); + HashMapCatalog::CatWalker walker(inputCatImpl); while (!walker.AtEnd()) { const CatKey &plainTextKey(walker.GetKey()); BString keyString, keyComment, keyContext; diff --git a/src/kits/locale/DefaultCatalog.cpp b/src/kits/locale/DefaultCatalog.cpp index a7acc96aa0..8f332eeeff 100644 --- a/src/kits/locale/DefaultCatalog.cpp +++ b/src/kits/locale/DefaultCatalog.cpp @@ -46,6 +46,10 @@ using std::pair; static const char *kCatFolder = "catalogs"; static const char *kCatExtension = ".catalog"; + +namespace BPrivate { + + const char *DefaultCatalog::kCatMimeType = "locale/x-vnd.Be.locale-catalog.default"; @@ -64,7 +68,7 @@ const uint8 DefaultCatalog::kDefaultCatalogAddOnPriority = 1; DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *language, uint32 fingerprint) : - BHashMapCatalog("", language, fingerprint) + HashMapCatalog("", language, fingerprint) { // We created the catalog with an invalid signature, but we fix that now. SetSignature(catalogOwner); @@ -127,7 +131,7 @@ DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *langua */ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef) : - BHashMapCatalog("", "", 0) + HashMapCatalog("", "", 0) { fInitCheck = ReadFromResource(*appOrAddOnRef); log_team(LOG_DEBUG, @@ -143,7 +147,7 @@ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef) DefaultCatalog::DefaultCatalog(const char *path, const char *signature, const char *language) : - BHashMapCatalog(signature, language, 0), + HashMapCatalog(signature, language, 0), fPath(path) { fInitCheck = B_OK; @@ -615,10 +619,13 @@ DefaultCatalog::Create(const char *signature, const char *language) return catalog; } + +} // namespace BPrivate + + extern "C" status_t default_catalog_get_available_languages(BMessage* availableLanguages, - const char* sigPattern, const char* langPattern = NULL, - int32 fingerprint = 0) + const char* sigPattern, const char* langPattern, int32 fingerprint) { if (availableLanguages == NULL || sigPattern == NULL) return B_BAD_DATA; diff --git a/src/kits/locale/HashMapCatalog.cpp b/src/kits/locale/HashMapCatalog.cpp index 70f0fc0dec..6ae6bd1be2 100644 --- a/src/kits/locale/HashMapCatalog.cpp +++ b/src/kits/locale/HashMapCatalog.cpp @@ -102,25 +102,25 @@ CatKey::HashFun(const char* s, int startValue) { } -// BHashMapCatalog +// HashMapCatalog void -BHashMapCatalog::MakeEmpty() +HashMapCatalog::MakeEmpty() { fCatMap.Clear(); } int32 -BHashMapCatalog::CountItems() const +HashMapCatalog::CountItems() const { return fCatMap.Size(); } const char * -BHashMapCatalog::GetString(const char *string, const char *context, +HashMapCatalog::GetString(const char *string, const char *context, const char *comment) { CatKey key(string, context, comment); @@ -129,7 +129,7 @@ BHashMapCatalog::GetString(const char *string, const char *context, const char * -BHashMapCatalog::GetString(uint32 id) +HashMapCatalog::GetString(uint32 id) { CatKey key(id); return GetString(key); @@ -137,7 +137,7 @@ BHashMapCatalog::GetString(uint32 id) const char * -BHashMapCatalog::GetString(const CatKey& key) +HashMapCatalog::GetString(const CatKey& key) { BString value = fCatMap.Get(key); if (value.Length() == 0) @@ -202,7 +202,7 @@ parseQuotedChars(BString& stringToParse) status_t -BHashMapCatalog::SetString(const char *string, const char *translated, +HashMapCatalog::SetString(const char *string, const char *translated, const char *context, const char *comment) { BString stringCopy(string); @@ -225,7 +225,7 @@ BHashMapCatalog::SetString(const char *string, const char *translated, status_t -BHashMapCatalog::SetString(int32 id, const char *translated) +HashMapCatalog::SetString(int32 id, const char *translated) { BString translatedCopy(translated); status_t result = parseQuotedChars(translatedCopy); @@ -238,7 +238,7 @@ BHashMapCatalog::SetString(int32 id, const char *translated) status_t -BHashMapCatalog::SetString(const CatKey& key, const char *translated) +HashMapCatalog::SetString(const CatKey& key, const char *translated) { BString translatedCopy(translated); status_t result = parseQuotedChars(translatedCopy); @@ -258,7 +258,7 @@ BHashMapCatalog::SetString(const CatKey& key, const char *translated) * wrong order, and this does happen, as an hash map is an unsorted container. */ uint32 -BHashMapCatalog::ComputeFingerprint() const +HashMapCatalog::ComputeFingerprint() const { uint32 checksum = 0; @@ -276,7 +276,7 @@ BHashMapCatalog::ComputeFingerprint() const void -BHashMapCatalog::UpdateFingerprint() +HashMapCatalog::UpdateFingerprint() { fFingerprint = ComputeFingerprint(); } diff --git a/src/kits/locale/InitLocaleKit.cpp b/src/kits/locale/InitLocaleKit.cpp index 3092092f4c..96f281a8f7 100644 --- a/src/kits/locale/InitLocaleKit.cpp +++ b/src/kits/locale/InitLocaleKit.cpp @@ -22,6 +22,11 @@ BCatalog gSystemCatalog; } +using BPrivate::DefaultCatalog; +using BPrivate::MutableLocaleRoster; +using BPrivate::gSystemCatalog; + + // helper function that makes sure an attribute-index exists: static void EnsureIndexExists(const char *attrName) { @@ -129,6 +134,5 @@ __initialize_locale_kit() { SetupCatalogBasics(); - MutableLocaleRoster::Default()->LoadSystemCatalog( - &BPrivate::gSystemCatalog); + MutableLocaleRoster::Default()->LoadSystemCatalog(&gSystemCatalog); } diff --git a/src/kits/locale/LocaleRoster.cpp b/src/kits/locale/LocaleRoster.cpp index 2631f93bd8..c681f68b5f 100644 --- a/src/kits/locale/LocaleRoster.cpp +++ b/src/kits/locale/LocaleRoster.cpp @@ -44,6 +44,8 @@ using BPrivate::CatalogAddOnInfo; +using BPrivate::MutableLocaleRoster; +using BPrivate::RosterData; /* diff --git a/src/tools/locale/DefaultCatalog.cpp b/src/tools/locale/DefaultCatalog.cpp index e8fc2e0b10..4352a81353 100644 --- a/src/tools/locale/DefaultCatalog.cpp +++ b/src/tools/locale/DefaultCatalog.cpp @@ -31,6 +31,7 @@ #include +using BPrivate::DefaultCatalog; using std::auto_ptr; @@ -40,6 +41,9 @@ using std::auto_ptr; */ +namespace BPrivate { + + // several attributes/resource-IDs used within the Locale Kit: const char *kCatLangAttr = "BEOS:LOCALE_LANGUAGE"; @@ -64,7 +68,7 @@ static int16 kCatArchiveVersion = 1; DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *language, uint32 fingerprint) : - BHashMapCatalog("", language, fingerprint) + HashMapCatalog("", language, fingerprint) { fInitCheck = B_NOT_SUPPORTED; fprintf(stderr, @@ -80,7 +84,7 @@ DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, */ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef) : - BHashMapCatalog("", "", 0) + HashMapCatalog("", "", 0) { fInitCheck = ReadFromResource(*appOrAddOnRef); // fprintf(stderr, @@ -96,7 +100,7 @@ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef) DefaultCatalog::DefaultCatalog(const char *path, const char *signature, const char *language) : - BHashMapCatalog(signature, language, 0), + HashMapCatalog(signature, language, 0), fPath(path) { fInitCheck = B_OK; @@ -426,3 +430,6 @@ DefaultCatalog::Create(const char *signature, const char *language) const uint8 DefaultCatalog::kDefaultCatalogAddOnPriority = 1; // give highest priority to our embedded catalog-add-on + + +} // namespace BPrivate diff --git a/src/tools/locale/PlainTextCatalog.cpp b/src/tools/locale/PlainTextCatalog.cpp index 71e35bb3f9..3cdd94f5c2 100644 --- a/src/tools/locale/PlainTextCatalog.cpp +++ b/src/tools/locale/PlainTextCatalog.cpp @@ -31,6 +31,7 @@ #include +using BPrivate::PlainTextCatalog; using std::auto_ptr; using std::min; using std::max; @@ -44,6 +45,9 @@ using std::pair; */ +namespace BPrivate { + + const char *PlainTextCatalog::kCatMimeType = "locale/x-vnd.Be.locale-catalog.plaintext"; @@ -73,7 +77,7 @@ escapeQuotedChars(BString& stringToEscape) PlainTextCatalog::PlainTextCatalog(const char *signature, const char *language, uint32 fingerprint) : - BHashMapCatalog(signature, language, fingerprint) + HashMapCatalog(signature, language, fingerprint) { // Look for the catalog in the directory we are going to use // This constructor is not used so lets disable that... @@ -93,7 +97,7 @@ PlainTextCatalog::PlainTextCatalog(const char *signature, const char *language, PlainTextCatalog::PlainTextCatalog(const char *path, const char *signature, const char *language) : - BHashMapCatalog(signature, language, 0), + HashMapCatalog(signature, language, 0), fPath(path) { fInitCheck = B_OK; @@ -339,6 +343,9 @@ PlainTextCatalog::Instantiate(const char *signature, const char *language, } +} // namespace BPrivate + + extern "C" BCatalogAddOn * instantiate_catalog(const char *signature, const char *language, uint32 fingerprint) diff --git a/src/tools/locale/collectcatkeys.cpp b/src/tools/locale/collectcatkeys.cpp index 87356c5399..6430c307b3 100644 --- a/src/tools/locale/collectcatkeys.cpp +++ b/src/tools/locale/collectcatkeys.cpp @@ -21,6 +21,9 @@ #include +using BPrivate::PlainTextCatalog; + + bool showKeys = false; bool showSummary = false; bool showWarnings = false; diff --git a/src/tools/locale/linkcatkeys.cpp b/src/tools/locale/linkcatkeys.cpp index 41aaff0837..072a022024 100644 --- a/src/tools/locale/linkcatkeys.cpp +++ b/src/tools/locale/linkcatkeys.cpp @@ -16,8 +16,13 @@ #include #include +using BPrivate::CatKey; +using BPrivate::DefaultCatalog; +using BPrivate::HashMapCatalog; +using BPrivate::PlainTextCatalog; using std::vector; + void usage() { @@ -108,7 +113,7 @@ main(int argc, char **argv) // now walk over all entries in input-catalog and add them to // target catalog, unless they already exist there. - BHashMapCatalog::CatWalker walker(&inputCatalog); + HashMapCatalog::CatWalker walker(&inputCatalog); while (!walker.AtEnd()) { const CatKey &key(walker.GetKey());