1 /***************************************************************************
2 * Copyright (C) 2003 by Hideki Ikemoto *
3 * ikemo@users.sourceforge.jp *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
11 #include "threadinfo.h"
13 #include <QtCore/QDataStream>
14 #include <QtCore/QMap>
18 ThreadInfo* ThreadInfo::instance = 0;
20 ThreadInfo::ThreadInfo() : m_readDict()
23 ThreadInfo::~ThreadInfo()
26 ThreadInfo* ThreadInfo::getInstance()
29 instance = new ThreadInfo();
34 int ThreadInfo::readNum(const QString& url)
36 ThreadInfo * instance = ThreadInfo::getInstance();
37 if (instance->m_readDict.contains(url)) {
38 return instance->m_readDict[ url ];
44 void ThreadInfo::setReadNum(const QString& url, int num)
46 ThreadInfo * instance = ThreadInfo::getInstance();
47 instance->m_readDict.insert(url, num);
50 void ThreadInfo::replace(const QString& fromUrl, const QString& toUrl)
52 QMap<QString, int>::Iterator it;
53 ThreadInfo* instance = ThreadInfo::getInstance();
54 if (instance == 0) return ;
56 for (it = instance->m_readDict.begin(); it != instance->m_readDict.end(); ++it) {
57 QString url = it.key();
59 if (url.indexOf(fromUrl) == 0) {
60 url = url.replace(0, fromUrl.length(), toUrl);
61 instance->m_readDict.erase(it);
62 instance->m_readDict.insert(url, num);
63 it = instance->m_readDict.begin(); // TODO もっと早い方法は?
68 void ThreadInfo::removeThreadInfo(const QString& url)
70 ThreadInfo * instance = ThreadInfo::getInstance();
71 instance->m_readDict.remove(url);
74 QDataStream& operator<<(QDataStream& s, ThreadInfo& c)
80 QDataStream& operator>>(QDataStream& s, ThreadInfo& c)