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;
|
status_t InitCheck() const;
|
||||||
int32 CountItems() const;
|
int32 CountItems() const;
|
||||||
|
|
||||||
// TODO: drop this, as the lifetime of the returned object
|
|
||||||
// is indeterminate
|
|
||||||
BCatalogAddOn* CatalogAddOn();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BCatalog(const BCatalog&);
|
BCatalog(const BCatalog&);
|
||||||
const BCatalog& operator= (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:
|
* 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_ */
|
#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; }
|
uint32 GetHashCode() const { return fHashVal; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BPrivate
|
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
|
||||||
|
|
||||||
class BHashMapCatalog: public BCatalogAddOn {
|
class BHashMapCatalog: public BCatalogAddOn {
|
||||||
protected:
|
protected:
|
||||||
@@ -200,6 +196,4 @@ BHashMapCatalog::GetWalker(CatWalker *walker)
|
|||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
using namespace BPrivate;
|
|
||||||
|
|
||||||
#endif // _HASH_MAP_CATALOG_H_
|
#endif // _HASH_MAP_CATALOG_H_
|
||||||
|
|||||||
@@ -13,14 +13,16 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <Catalog.h>
|
|
||||||
using namespace BPrivate;
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include "RegExp.h"
|
#include "RegExp.h"
|
||||||
#include <StorageDefs.h>
|
#include <StorageDefs.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <EditableCatalog.h>
|
||||||
|
|
||||||
|
using BPrivate::EditableCatalog;
|
||||||
|
|
||||||
|
|
||||||
bool showKeys = false;
|
bool showKeys = false;
|
||||||
bool showSummary = false;
|
bool showSummary = false;
|
||||||
@@ -31,8 +33,6 @@ const char *catalogSig = NULL;
|
|||||||
const char *catalogLang = "English";
|
const char *catalogLang = "English";
|
||||||
BString rxString("B_CATKEY\\s*");
|
BString rxString("B_CATKEY\\s*");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BString str, ctx, cmt;
|
BString str, ctx, cmt;
|
||||||
bool haveID;
|
bool haveID;
|
||||||
int32 id;
|
int32 id;
|
||||||
|
|||||||
@@ -6,11 +6,15 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <Catalog.h>
|
|
||||||
#include <DefaultCatalog.h>
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <DefaultCatalog.h>
|
||||||
|
#include <EditableCatalog.h>
|
||||||
|
|
||||||
|
using BPrivate::EditableCatalog;
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
@@ -57,8 +61,8 @@ main(int argc, char **argv)
|
|||||||
while (!walker.AtEnd()) {
|
while (!walker.AtEnd()) {
|
||||||
const CatKey &key(walker.GetKey());
|
const CatKey &key(walker.GetKey());
|
||||||
key.GetStringParts(&str, &ctx, &cmt);
|
key.GetStringParts(&str, &ctx, &cmt);
|
||||||
printf("Hash:\t\t%lu\nKey:\t\t<%s:%s:%s>\nTranslation:\t%s\n-----\n",
|
printf("Hash:\t\t%lu\nKey:\t\t<%s:%s:%s>\nTranslation:\t%s\n-----\n",
|
||||||
key.fHashVal, str.String(), ctx.String(), cmt.String(),
|
key.fHashVal, str.String(), ctx.String(), cmt.String(),
|
||||||
walker.GetValue());
|
walker.GetValue());
|
||||||
walker.Next();
|
walker.Next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,19 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <Catalog.h>
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <EditableCatalog.h>
|
||||||
#include <DefaultCatalog.h>
|
#include <DefaultCatalog.h>
|
||||||
#include <HashMapCatalog.h>
|
#include <HashMapCatalog.h>
|
||||||
#include <PlainTextCatalog.h>
|
#include <PlainTextCatalog.h>
|
||||||
|
|
||||||
|
using BPrivate::EditableCatalog;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -370,139 +370,3 @@ BCatalogAddOn::SetNext(BCatalogAddOn* next)
|
|||||||
{
|
{
|
||||||
fNext = 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, [email protected]
|
||||||
|
* Copyright 2003-2004,2012, Oliver Tappe, [email protected]
|
||||||
|
* 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
|
Collator.cpp
|
||||||
Country.cpp
|
Country.cpp
|
||||||
DefaultCatalog.cpp
|
DefaultCatalog.cpp
|
||||||
|
EditableCatalog.cpp
|
||||||
FormattingConventions.cpp
|
FormattingConventions.cpp
|
||||||
HashMapCatalog.cpp
|
HashMapCatalog.cpp
|
||||||
InitLocaleKit.cpp
|
InitLocaleKit.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user