Turned FontList into a singleton.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34374 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-11-30 12:48:35 +00:00
parent 17f68169f2
commit 0eb45760a7
1 changed files with 34 additions and 10 deletions

View File

@ -58,13 +58,15 @@ struct family {
BObjectList<style> styles; BObjectList<style> styles;
}; };
namespace BPrivate { namespace {
class FontList : public BLocker { class FontList : public BLocker {
public: public:
FontList(); FontList();
~FontList(); ~FontList();
static FontList* Default();
bool UpdatedOnServer(); bool UpdatedOnServer();
status_t FamilyAt(int32 index, font_family *_family, uint32 *_flags); status_t FamilyAt(int32 index, font_family *_family, uint32 *_flags);
@ -79,16 +81,21 @@ class FontList : public BLocker {
status_t _Update(); status_t _Update();
int32 _RevisionOnServer(); int32 _RevisionOnServer();
family* _FindFamily(font_family name); family* _FindFamily(font_family name);
static void _InitSingleton();
BObjectList<family> fFamilies; BObjectList<family> fFamilies;
family* fLastFamily; family* fLastFamily;
bigtime_t fLastUpdate; bigtime_t fLastUpdate;
int32 fRevision; int32 fRevision;
static pthread_once_t sDefaultInitOnce;
static FontList* sDefaultInstance;
}; };
} // namespace BPrivate pthread_once_t FontList::sDefaultInitOnce = PTHREAD_ONCE_INIT;
FontList* FontList::sDefaultInstance = NULL;
static BPrivate::FontList sFontList; } // unnamed namespace
// #pragma mark - // #pragma mark -
@ -102,7 +109,7 @@ compare_families(const family* a, const family* b)
} }
namespace BPrivate { namespace {
FontList::FontList() FontList::FontList()
: BLocker("font list"), : BLocker("font list"),
@ -118,6 +125,16 @@ FontList::~FontList()
} }
/*static*/ FontList*
FontList::Default()
{
if (sDefaultInstance == NULL)
pthread_once(&sDefaultInitOnce, &_InitSingleton);
return sDefaultInstance;
}
bool bool
FontList::UpdatedOnServer() FontList::UpdatedOnServer()
{ {
@ -301,7 +318,14 @@ FontList::CountStyles(font_family familyName)
return family->styles.CountItems(); return family->styles.CountItems();
} }
} // namespace BPrivate
/*static*/ void
FontList::_InitSingleton()
{
sDefaultInstance = new FontList;
}
} // unnamed namespace
// #pragma mark - // #pragma mark -
@ -413,7 +437,7 @@ _get_system_default_font_(const char* which, font_family family,
int32 int32
count_font_families() count_font_families()
{ {
return sFontList.CountFamilies(); return FontList::Default()->CountFamilies();
} }
@ -424,7 +448,7 @@ count_font_families()
int32 int32
count_font_styles(font_family family) count_font_styles(font_family family)
{ {
return sFontList.CountStyles(family); return FontList::Default()->CountStyles(family);
} }
@ -442,7 +466,7 @@ get_font_family(int32 index, font_family *_name, uint32 *_flags)
if (_name == NULL) if (_name == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
return sFontList.FamilyAt(index, _name, _flags); return FontList::Default()->FamilyAt(index, _name, _flags);
} }
@ -482,7 +506,7 @@ get_font_style(font_family family, int32 index, font_style *_name,
if (_name == NULL) if (_name == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
return sFontList.StyleAt(family, index, _name, _face, _flags); return FontList::Default()->StyleAt(family, index, _name, _face, _flags);
} }
@ -494,7 +518,7 @@ get_font_style(font_family family, int32 index, font_style *_name,
bool bool
update_font_families(bool /*checkOnly*/) update_font_families(bool /*checkOnly*/)
{ {
return sFontList.UpdatedOnServer(); return FontList::Default()->UpdatedOnServer();
} }