Extract EditableCatalog from Catalog.{h,cpp}.
* move EditableCatalog to its own header and implementation file * move problematic BCatalog::CatalogAddOn() to EditableCatalog * adjust Locale tools accordingly
This commit is contained in:
@@ -50,10 +50,6 @@ public:
|
||||
status_t InitCheck() const;
|
||||
int32 CountItems() const;
|
||||
|
||||
// TODO: drop this, as the lifetime of the returned object
|
||||
// is indeterminate
|
||||
BCatalogAddOn* CatalogAddOn();
|
||||
|
||||
protected:
|
||||
BCatalog(const BCatalog&);
|
||||
const BCatalog& operator= (const BCatalog&);
|
||||
@@ -378,13 +374,6 @@ BCatalog::GetNoAutoCollectString(uint32 id)
|
||||
}
|
||||
|
||||
|
||||
inline BCatalogAddOn*
|
||||
BCatalog::CatalogAddOn()
|
||||
{
|
||||
return fCatalog;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* BCatalogAddOn - inlines for trivial accessors:
|
||||
*/
|
||||
@@ -409,50 +398,4 @@ BCatalogAddOn::MarkForTranslation(int32 id)
|
||||
}
|
||||
|
||||
|
||||
// TODO: does not belong here, either
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class EditableCatalog : public BCatalog {
|
||||
public:
|
||||
EditableCatalog(const char* type,
|
||||
const char* signature,
|
||||
const char* language);
|
||||
virtual ~EditableCatalog();
|
||||
|
||||
status_t SetString(const char* string,
|
||||
const char* translated,
|
||||
const char* context = NULL,
|
||||
const char* comment = NULL);
|
||||
status_t SetString(int32 id, const char* translated);
|
||||
|
||||
bool CanWriteData() const;
|
||||
status_t SetData(const char* name, BMessage* msg);
|
||||
status_t SetData(uint32 id, BMessage* msg);
|
||||
|
||||
status_t ReadFromFile(const char* path = NULL);
|
||||
status_t ReadFromAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t ReadFromResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t WriteToFile(const char* path = NULL);
|
||||
status_t WriteToAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t WriteToResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
|
||||
void MakeEmpty();
|
||||
|
||||
private:
|
||||
EditableCatalog();
|
||||
EditableCatalog(const EditableCatalog& other);
|
||||
const EditableCatalog& operator=(const EditableCatalog& other);
|
||||
// hide assignment, default-, and
|
||||
// copy-constructor
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif /* _CATALOG_H_ */
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2003-2012, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _EDITABLE_CATALOG_H_
|
||||
#define _EDITABLE_CATALOG_H_
|
||||
|
||||
|
||||
#include <Catalog.h>
|
||||
|
||||
|
||||
class BMessage;
|
||||
struct entry_ref;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class EditableCatalog : public BCatalog {
|
||||
public:
|
||||
EditableCatalog(const char* type,
|
||||
const char* signature,
|
||||
const char* language);
|
||||
virtual ~EditableCatalog();
|
||||
|
||||
status_t SetString(const char* string,
|
||||
const char* translated,
|
||||
const char* context = NULL,
|
||||
const char* comment = NULL);
|
||||
status_t SetString(int32 id, const char* translated);
|
||||
|
||||
bool CanWriteData() const;
|
||||
status_t SetData(const char* name, BMessage* msg);
|
||||
status_t SetData(uint32 id, BMessage* msg);
|
||||
|
||||
status_t ReadFromFile(const char* path = NULL);
|
||||
status_t ReadFromAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t ReadFromResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t WriteToFile(const char* path = NULL);
|
||||
status_t WriteToAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t WriteToResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
|
||||
void MakeEmpty();
|
||||
|
||||
BCatalogAddOn* CatalogAddOn();
|
||||
|
||||
private:
|
||||
EditableCatalog();
|
||||
EditableCatalog(const EditableCatalog& other);
|
||||
const EditableCatalog& operator=(const EditableCatalog& other);
|
||||
// hide assignment, default-, and
|
||||
// copy-constructor
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif /* _EDITABLE_CATALOG_H_ */
|
||||
@@ -60,10 +60,6 @@ class CatKey {
|
||||
uint32 GetHashCode() const { return fHashVal; }
|
||||
};
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
class BHashMapCatalog: public BCatalogAddOn {
|
||||
protected:
|
||||
@@ -200,6 +196,4 @@ BHashMapCatalog::GetWalker(CatWalker *walker)
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using namespace BPrivate;
|
||||
|
||||
#endif // _HASH_MAP_CATALOG_H_
|
||||
|
||||
@@ -13,14 +13,16 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <Catalog.h>
|
||||
using namespace BPrivate;
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include "RegExp.h"
|
||||
#include <StorageDefs.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <EditableCatalog.h>
|
||||
|
||||
using BPrivate::EditableCatalog;
|
||||
|
||||
|
||||
bool showKeys = false;
|
||||
bool showSummary = false;
|
||||
@@ -31,8 +33,6 @@ const char *catalogSig = NULL;
|
||||
const char *catalogLang = "English";
|
||||
BString rxString("B_CATKEY\\s*");
|
||||
|
||||
|
||||
|
||||
BString str, ctx, cmt;
|
||||
bool haveID;
|
||||
int32 id;
|
||||
|
||||
@@ -6,11 +6,15 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <DefaultCatalog.h>
|
||||
#include <File.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <DefaultCatalog.h>
|
||||
#include <EditableCatalog.h>
|
||||
|
||||
using BPrivate::EditableCatalog;
|
||||
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
@@ -57,8 +61,8 @@ main(int argc, char **argv)
|
||||
while (!walker.AtEnd()) {
|
||||
const CatKey &key(walker.GetKey());
|
||||
key.GetStringParts(&str, &ctx, &cmt);
|
||||
printf("Hash:\t\t%lu\nKey:\t\t<%s:%s:%s>\nTranslation:\t%s\n-----\n",
|
||||
key.fHashVal, str.String(), ctx.String(), cmt.String(),
|
||||
printf("Hash:\t\t%lu\nKey:\t\t<%s:%s:%s>\nTranslation:\t%s\n-----\n",
|
||||
key.fHashVal, str.String(), ctx.String(), cmt.String(),
|
||||
walker.GetValue());
|
||||
walker.Next();
|
||||
}
|
||||
|
||||
@@ -7,17 +7,19 @@
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <EditableCatalog.h>
|
||||
#include <DefaultCatalog.h>
|
||||
#include <HashMapCatalog.h>
|
||||
#include <PlainTextCatalog.h>
|
||||
|
||||
using BPrivate::EditableCatalog;
|
||||
using std::vector;
|
||||
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
|
||||
@@ -370,139 +370,3 @@ BCatalogAddOn::SetNext(BCatalogAddOn* next)
|
||||
{
|
||||
fNext = next;
|
||||
}
|
||||
|
||||
|
||||
//#pragma mark - EditableCatalog
|
||||
namespace BPrivate {
|
||||
EditableCatalog::EditableCatalog(const char* type, const char* signature,
|
||||
const char* language)
|
||||
{
|
||||
fCatalog = MutableLocaleRoster::Default()->CreateCatalog(type, signature,
|
||||
language);
|
||||
}
|
||||
|
||||
|
||||
EditableCatalog::~EditableCatalog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetString(const char* string, const char* translated,
|
||||
const char* context, const char* comment)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetString(string, translated, context, comment);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetString(int32 id, const char* translated)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetString(id, translated);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
EditableCatalog::CanWriteData() const
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return false;
|
||||
|
||||
return fCatalog->CanWriteData();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetData(const char* name, BMessage* msg)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetData(name, msg);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetData(uint32 id, BMessage* msg)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetData(id, msg);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromFile(const char* path)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->ReadFromFile(path);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromAttribute(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->ReadFromAttribute(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromResource(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->ReadFromResource(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToFile(const char* path)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->WriteToFile(path);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToAttribute(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->WriteToAttribute(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToResource(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->WriteToResource(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
void EditableCatalog::MakeEmpty()
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
fCatalog->MakeEmpty();
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de
|
||||
* Copyright 2003-2004,2012, Oliver Tappe, zooey@hirschkaefer.de
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <EditableCatalog.h>
|
||||
|
||||
#include <MutableLocaleRoster.h>
|
||||
|
||||
|
||||
using BPrivate::MutableLocaleRoster;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
EditableCatalog::EditableCatalog(const char* type, const char* signature,
|
||||
const char* language)
|
||||
{
|
||||
fCatalog = MutableLocaleRoster::Default()->CreateCatalog(type, signature,
|
||||
language);
|
||||
}
|
||||
|
||||
|
||||
EditableCatalog::~EditableCatalog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetString(const char* string, const char* translated,
|
||||
const char* context, const char* comment)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetString(string, translated, context, comment);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetString(int32 id, const char* translated)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetString(id, translated);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
EditableCatalog::CanWriteData() const
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return false;
|
||||
|
||||
return fCatalog->CanWriteData();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetData(const char* name, BMessage* msg)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetData(name, msg);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::SetData(uint32 id, BMessage* msg)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->SetData(id, msg);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromFile(const char* path)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->ReadFromFile(path);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromAttribute(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->ReadFromAttribute(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromResource(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->ReadFromResource(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToFile(const char* path)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->WriteToFile(path);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToAttribute(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->WriteToAttribute(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToResource(const entry_ref& appOrAddOnRef)
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
return fCatalog->WriteToResource(appOrAddOnRef);
|
||||
}
|
||||
|
||||
|
||||
void EditableCatalog::MakeEmpty()
|
||||
{
|
||||
if (fCatalog == NULL)
|
||||
fCatalog->MakeEmpty();
|
||||
}
|
||||
|
||||
|
||||
BCatalogAddOn*
|
||||
EditableCatalog::CatalogAddOn()
|
||||
{
|
||||
return fCatalog;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
@@ -11,6 +11,7 @@ local sources =
|
||||
Collator.cpp
|
||||
Country.cpp
|
||||
DefaultCatalog.cpp
|
||||
EditableCatalog.cpp
|
||||
FormattingConventions.cpp
|
||||
HashMapCatalog.cpp
|
||||
InitLocaleKit.cpp
|
||||
|
||||
Reference in New Issue
Block a user