More cleanup in locale kit, this time regarding namespaces.

* it's bad practice to do a 'using <namespace>' 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)
This commit is contained in:
Oliver Tappe 2012-04-14 20:38:05 +02:00
parent 7ae67a9920
commit 5ac65b7f11
14 changed files with 89 additions and 47 deletions

View File

@ -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_ */

View File

@ -61,14 +61,14 @@ class CatKey {
};
class BHashMapCatalog: public BCatalogAddOn {
class HashMapCatalog: public BCatalogAddOn {
protected:
uint32 ComputeFingerprint() const;
typedef HashMap<CatKey, BString> 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;

View File

@ -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_ */

View File

@ -32,6 +32,8 @@
#include <Catalog.h>
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;

View File

@ -12,6 +12,9 @@
#include <DefaultCatalog.h>
#include <EditableCatalog.h>
using BPrivate::CatKey;
using BPrivate::DefaultCatalog;
using BPrivate::EditableCatalog;

View File

@ -14,9 +14,12 @@
#include <EditableCatalog.h>
#include <DefaultCatalog.h>
#include <HashMapCatalog.h>
#include <PlainTextCatalog.h>
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<BHashMapCatalog*>(inputCatalog.CatalogAddOn());
HashMapCatalog* inputCatImpl
= dynamic_cast<HashMapCatalog*>(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;

View File

@ -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;

View File

@ -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();
}

View File

@ -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);
}

View File

@ -44,6 +44,8 @@
using BPrivate::CatalogAddOnInfo;
using BPrivate::MutableLocaleRoster;
using BPrivate::RosterData;
/*

View File

@ -31,6 +31,7 @@
#include <cstdio>
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

View File

@ -31,6 +31,7 @@
#include <Catalog.h>
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)

View File

@ -21,6 +21,9 @@
#include <String.h>
using BPrivate::PlainTextCatalog;
bool showKeys = false;
bool showSummary = false;
bool showWarnings = false;

View File

@ -16,8 +16,13 @@
#include <HashMapCatalog.h>
#include <PlainTextCatalog.h>
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());