B*Format: make immutable and remove locking

The language and formatting conventions can now only be set when
creating the objects. This removed the needs for locking them when
formatting to avoid some other thread changing the format while it's
being used.

Adjust tests and DeskBar TimeView to the API changes.
This commit is contained in:
Adrien Destugues
2014-10-27 14:08:42 +01:00
parent fa80e7b28f
commit 5d5ec05b1d
21 changed files with 217 additions and 382 deletions
+3 -4
View File
@@ -36,10 +36,9 @@ enum BWeekday {
class BDateFormat: public BFormat {
public:
BDateFormat(
const BLanguage* const language = NULL,
const BFormattingConventions* const
format = NULL);
BDateFormat(const BLocale* locale = NULL);
BDateFormat(const BLanguage& language,
const BFormattingConventions& format);
BDateFormat(const BDateFormat &other);
virtual ~BDateFormat();
+3 -4
View File
@@ -31,10 +31,9 @@ enum BDateElement {
class BDateTimeFormat : public BFormat {
public:
BDateTimeFormat(
const BLanguage* const language = NULL,
const BFormattingConventions* const format
= NULL);
BDateTimeFormat(const BLocale* locale = NULL);
BDateTimeFormat(const BLanguage& language,
const BFormattingConventions& conventions);
BDateTimeFormat(const BDateTimeFormat &other);
virtual ~BDateTimeFormat();
+3 -4
View File
@@ -23,16 +23,15 @@ class BDurationFormat : public BFormat {
typedef BFormat Inherited;
public:
BDurationFormat(const BLanguage& language,
const BFormattingConventions& conventions,
const BString& separator = ", ");
BDurationFormat(
const BString& separator = ", ");
BDurationFormat(const BDurationFormat& other);
virtual ~BDurationFormat();
BDurationFormat& operator=(const BDurationFormat& other);
void SetSeparator(const BString& separator);
virtual status_t SetLanguage(const BLanguage& language);
status_t SetTimeZone(const BTimeZone* timeZone);
status_t Format(BString& buffer,
+15 -14
View File
@@ -43,25 +43,26 @@ class BLocale;
class BFormat {
public:
status_t SetLocale(const BLocale& locale);
virtual status_t SetLanguage(const BLanguage& newLanguage);
virtual status_t SetFormattingConventions(
const BFormattingConventions&
conventions);
status_t InitCheck() const;
status_t InitCheck() const;
protected:
BFormat();
BFormat(const BFormat& other);
virtual ~BFormat();
BFormat(const BLocale* locale = NULL);
BFormat(const BLanguage& language,
const BFormattingConventions& conventions);
BFormat& operator=(const BFormat& other);
BFormat(const BFormat& other);
virtual ~BFormat();
private:
BFormat& operator=(const BFormat& other);
status_t _Initialize(const BLocale& locale);
status_t _Initialize(const BLanguage& language,
const BFormattingConventions& conventions);
protected:
mutable BLocker fLock;
BFormattingConventions fConventions;
BLanguage fLanguage;
status_t fInitStatus;
BLanguage fLanguage;
status_t fInitStatus;
};
+2 -6
View File
@@ -17,23 +17,19 @@ namespace icu {
class BMessageFormat: public BFormat {
public:
BMessageFormat(const BLanguage& language,
const BString pattern);
BMessageFormat(const BString pattern);
~BMessageFormat();
status_t InitCheck();
status_t SetLanguage(const BLanguage& newLanguage);
status_t SetFormattingConventions(
const BFormattingConventions&
conventions);
status_t Format(BString& buffer, const int32 arg) const;
private:
status_t _Initialize(const icu::UnicodeString&);
private:
status_t fInitStatus;
icu::MessageFormat* fFormatter;
};
-2
View File
@@ -23,8 +23,6 @@ public:
BNumberFormat(const BNumberFormat &other);
~BNumberFormat();
BNumberFormat& operator=(const BNumberFormat &other);
// formatting
ssize_t Format(char* string, size_t maxSize,
+3 -4
View File
@@ -18,10 +18,9 @@ namespace BPrivate {
class BTimeFormat : public BFormat {
public:
BTimeFormat(
const BLanguage* const language = NULL,
const BFormattingConventions* const
format = NULL);
BTimeFormat();
BTimeFormat(const BLanguage& language,
const BFormattingConventions& conventions);
BTimeFormat(const BTimeFormat &other);
virtual ~BTimeFormat();
+2 -3
View File
@@ -41,12 +41,11 @@ class BTimeUnitFormat : public BFormat {
public:
BTimeUnitFormat();
BTimeUnitFormat(const BLanguage& language,
const BFormattingConventions& conventions);
BTimeUnitFormat(const BTimeUnitFormat& other);
virtual ~BTimeUnitFormat();
BTimeUnitFormat& operator=(const BTimeUnitFormat& other);
virtual status_t SetLanguage(const BLanguage& locale);
status_t Format(BString& buffer,
const int32 value,
const time_unit_element unit,