Make BDateFormat inherit from BFormat again
* Move relevant parts up into BFormat so other format classes can use those * Adjust BDurationFormat and BTimeUnitFormat for the changes * Remove the "default" date format, it is better to keep only a default locale and let applications create B*Formats from it as needed. * Creating a B*Format without arguments to the constructor now configures it for the default locale, which allows for easy use in standard cases (formatting something with the current language and format) * Creating a B*Format is potentially an expansive operation, it is advised to keep the instance around and reuse it whenever possible. However it must be "refreshed" when the locale changes, for apps which supports that, since it keeps a copy of the language and formatting convention, rather than a pointer to the locale as it did before.
This commit is contained in:
@@ -28,18 +28,15 @@ enum BWeekday {
|
||||
};
|
||||
|
||||
|
||||
class BDateFormat {
|
||||
class BDateFormat: public BFormat {
|
||||
public:
|
||||
BDateFormat(const BLanguage* const,
|
||||
const BFormattingConventions* const);
|
||||
BDateFormat(
|
||||
const BLanguage* const language = NULL,
|
||||
const BFormattingConventions* const
|
||||
format = NULL);
|
||||
BDateFormat(const BDateFormat &other);
|
||||
virtual ~BDateFormat();
|
||||
|
||||
static const BDateFormat* Default();
|
||||
|
||||
void SetLanguage(const BLanguage& newLanguage);
|
||||
void SetFormattingConventions(
|
||||
const BFormattingConventions& conventions);
|
||||
status_t GetDateFormat(BDateFormatStyle style,
|
||||
BString& outFormat) const;
|
||||
void SetDateFormat(BDateFormatStyle style,
|
||||
@@ -73,9 +70,6 @@ private:
|
||||
icu::DateFormat* _CreateDateFormatter(
|
||||
const BString& format) const;
|
||||
|
||||
mutable BLocker fLock;
|
||||
BFormattingConventions fConventions;
|
||||
BLanguage fLanguage;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include <Format.h>
|
||||
#include <Locale.h>
|
||||
#include <String.h>
|
||||
#include <TimeUnitFormat.h>
|
||||
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
|
||||
void SetSeparator(const BString& separator);
|
||||
|
||||
virtual status_t SetLocale(const BLocale* locale);
|
||||
virtual status_t SetLanguage(const BLanguage& language);
|
||||
status_t SetTimeZone(const BTimeZone* timeZone);
|
||||
|
||||
status_t Format(bigtime_t startValue,
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#define _B_FORMAT_H_
|
||||
|
||||
#include <FormatParameters.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <Locker.h>
|
||||
#include <Language.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
@@ -40,18 +43,25 @@ class BLocale;
|
||||
|
||||
class BFormat {
|
||||
public:
|
||||
status_t InitCheck() const;
|
||||
status_t SetLocale(const BLocale& locale);
|
||||
virtual status_t SetLanguage(const BLanguage& newLanguage);
|
||||
virtual status_t SetFormattingConventions(
|
||||
const BFormattingConventions&
|
||||
conventions);
|
||||
|
||||
virtual status_t SetLocale(const BLocale* locale);
|
||||
status_t InitCheck() const;
|
||||
protected:
|
||||
BFormat();
|
||||
BFormat(const BFormat& other);
|
||||
virtual ~BFormat();
|
||||
BFormat();
|
||||
BFormat(const BFormat& other);
|
||||
virtual ~BFormat();
|
||||
|
||||
BFormat& operator=(const BFormat& other);
|
||||
BFormat& operator=(const BFormat& other);
|
||||
|
||||
status_t fInitStatus;
|
||||
BLocale* fLocale;
|
||||
protected:
|
||||
mutable BLocker fLock;
|
||||
BFormattingConventions fConventions;
|
||||
BLanguage fLanguage;
|
||||
status_t fInitStatus;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@ public:
|
||||
// (that needs to link with liblocalestub.a)
|
||||
|
||||
const BLocale* GetDefaultLocale() const;
|
||||
const BDateFormat* GetDefaultDateFormat() const;
|
||||
|
||||
bool IsFilesystemTranslationPreferred() const;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
BTimeUnitFormat& operator=(const BTimeUnitFormat& other);
|
||||
|
||||
virtual status_t SetLocale(const BLocale* locale);
|
||||
virtual status_t SetLanguage(const BLanguage& locale);
|
||||
status_t Format(int32 value, time_unit_element unit,
|
||||
BString* buffer,
|
||||
time_unit_style style = B_TIME_UNIT_FULL
|
||||
|
||||
@@ -38,7 +38,6 @@ struct LocaleRosterData {
|
||||
|
||||
BLocale fDefaultLocale;
|
||||
BTimeZone fDefaultTimeZone;
|
||||
BDateFormat fDefaultDateFormat;
|
||||
|
||||
bool fIsFilesystemTranslationPreferred;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user