finally implement proper clipping for texts
[enigma2.git] / lib / dvb / db.cpp
index 22b6267b9b0c7ca428a8ff2aa97f868d8f7751e4..eb0721b65b2349cc9769fb20f785e85157379937 100644 (file)
@@ -114,12 +114,13 @@ RESULT eBouquet::setListName(const std::string &name)
 }
 
 eDVBService::eDVBService()
-       :m_flags(0)
+       :m_cache(0), m_flags(0)
 {
 }
 
 eDVBService::~eDVBService()
 {
+       delete [] m_cache;
 }
 
 eDVBService &eDVBService::operator=(const eDVBService &s)
@@ -129,7 +130,7 @@ eDVBService &eDVBService::operator=(const eDVBService &s)
        m_provider_name = s.m_provider_name;
        m_flags = s.m_flags;
        m_ca = s.m_ca;
-       m_cache = s.m_cache;
+       copyCache(s.m_cache);
        return *this;
 }
 
@@ -223,19 +224,48 @@ int eDVBService::checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQ
                return res;
 }
 
-int eDVBService::getCachePID(cacheID id)
+bool eDVBService::cacheEmpty()
 {
-       std::map<int, int>::iterator it = m_cache.find(id);
-       if ( it != m_cache.end() )
-               return it->second;
-       return -1;
+       if (m_cache)
+               for (int i=0; i < cacheMax; ++i)
+                       if (m_cache[i] != -1)
+                               return false;
+       return true;
 }
 
-void eDVBService::setCachePID(cacheID id, int pid)
+void eDVBService::initCache()
 {
-       if (pid == -1)
-               m_cache.erase(id);
+       m_cache = new int[cacheMax];
+       memset(m_cache, -1, sizeof(int) * cacheMax);
+}
+
+void eDVBService::copyCache(int *source)
+{
+       if (source)
+       {
+               if (!m_cache)
+                       m_cache = new int[cacheMax];
+               memcpy(m_cache, source, cacheMax * sizeof(int));
+       }
        else
+       {
+               delete [] m_cache;
+               m_cache = 0;
+       }
+}
+
+int eDVBService::getCacheEntry(cacheID id)
+{
+       if (id >= cacheMax || !m_cache)
+               return -1;
+       return m_cache[id];
+}
+
+void eDVBService::setCacheEntry(cacheID id, int pid)
+{
+       if (!m_cache)
+               initCache();
+       if (id < cacheMax)
                m_cache[id] = pid;
 }
 
@@ -420,12 +450,12 @@ void eDVBDB::reloadServicelist()
                                {
                                        int cid, val;
                                        sscanf(v.c_str(), "%02d%04x", &cid, &val);
-                                       s->m_cache[cid]=val;
+                                       s->setCacheEntry((eDVBService::cacheID)cid,val);
                                } else if (p == 'C')
                                {
                                        int val;
                                        sscanf(v.c_str(), "%04x", &val);
-                                       s->m_ca.insert(val);
+                                       s->m_ca.push_front((uint16_t)val);
                                }
                        }
                addService(ref, s);
@@ -510,12 +540,15 @@ void eDVBDB::saveServicelist()
                fprintf(f, "p:%s", i->second->m_provider_name.c_str());
 
                // write cached pids
-               for (std::map<int,int>::const_iterator ca(i->second->m_cache.begin());
-                       ca != i->second->m_cache.end(); ++ca)
-                       fprintf(f, ",c:%02d%04x", ca->first, ca->second);
+               for (int x=0; x < eDVBService::cacheMax; ++x)
+               {
+                       int entry = i->second->getCacheEntry((eDVBService::cacheID)x);
+                       if (entry != -1)
+                               fprintf(f, ",c:%02d%04x", x, entry);
+               }
 
                // write cached ca pids
-               for (std::set<int>::const_iterator ca(i->second->m_ca.begin());
+               for (CAID_LIST::const_iterator ca(i->second->m_ca.begin());
                        ca != i->second->m_ca.end(); ++ca)
                        fprintf(f, ",C:%04x", *ca);