Advertisement
Guest User

Untitled

a guest
Jan 30th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include "profilepagecache.h"
  2. #include "profilepage.h"
  3.  
  4. ProfilePageCache* ProfilePageCache::m_instance = NULL;
  5.  
  6. ProfilePageCache::ProfilePageCache(QObject *parent) :
  7.     QObject(parent)
  8. {
  9. }
  10.  
  11. ProfilePage* ProfilePageCache::getProfilePage(QString profileId)
  12. {
  13.     if (m_cachedProfilePages.contains(profileId)) {
  14.         return m_cachedProfilePages.value(profileId);
  15.     } else {
  16.         ProfilePage *profilePage = new ProfilePage(NULL, profileId);
  17.         m_cachedProfilePages.insert(profileId, profilePage);
  18.         return profilePage;
  19.     }
  20. }
  21.  
  22. ProfilePageCache* ProfilePageCache::instance()
  23. {
  24.     if (m_instance == NULL)
  25.         m_instance = new ProfilePageCache;
  26.     return m_instance;
  27. }
  28.  
  29. /////////////////////////
  30.  
  31. #ifndef PROFILEPAGECACHE_H
  32. #define PROFILEPAGECACHE_H
  33.  
  34. #include <QObject>
  35. #include <QMap>
  36.  
  37. class ProfilePage;
  38.  
  39. class ProfilePageCache : public QObject
  40. {
  41.     Q_OBJECT
  42. public:
  43.     explicit ProfilePageCache(QObject *parent = 0);
  44.     static ProfilePageCache* instance();
  45.     ProfilePage *getProfilePage(QString profileId);
  46.  
  47. signals:
  48.  
  49. public slots:
  50.  
  51. private:
  52.     QMap<QString,ProfilePage*> m_cachedProfilePages;
  53.     static ProfilePageCache *m_instance;
  54. };
  55.  
  56. #endif // PROFILEPAGECACHE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement