PageList Class Reference

#include <PageInfo.h>

Collaboration diagram for PageList:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 PageList ()
 ~PageList ()
void reset (const int size)
void clear ()
void addPage (CPageInfo *info)
void removeOldestOne (const int center)
CPageInfogetPage (const int number)
CPageInfocheckPage (const CPageInfo &info)
CPageInfocheckPage (const TodoItem *pItem)
void dump ()

Private Member Functions

void initialize ()

Private Attributes

pthread_mutex_t mutex
PageInfoPtrlist
int length


Detailed Description

Definition at line 80 of file PageInfo.h.


Constructor & Destructor Documentation

PageList::PageList (  ) 

Definition at line 74 of file PageInfo.cpp.

00075 {
00076     length = 0; list = NULL;
00077     initialize();
00078 }

Here is the call graph for this function:

PageList::~PageList (  ) 

Definition at line 80 of file PageInfo.cpp.

00081 {
00082     clear();
00083     delete [] list; list = NULL; length = 0;
00084     pthread_mutex_destroy(&mutex);
00085 }

Here is the call graph for this function:


Member Function Documentation

void PageList::initialize (  )  [private]

Definition at line 87 of file PageInfo.cpp.

00088 {
00089     pthread_mutex_init(&mutex, NULL);
00090 }

void PageList::reset ( const int  size  ) 

Definition at line 106 of file PageInfo.cpp.

00107 {
00108     pthread_mutex_lock(&mutex);
00109     for(int i = 0; i < length ; ++i)
00110     {
00111         if (list[i])
00112         {
00113             delete list[i];
00114             list[i] = NULL;
00115         }            
00116     }
00117     length = size; 
00118     if (list) 
00119     {
00120         delete [] list; list = NULL;
00121     }
00122     list = new PageInfoPtr[size];        
00123     memset(list, 0, length * sizeof(PageInfoPtr));
00124     pthread_mutex_unlock(&mutex);
00125 }

void PageList::clear (  ) 

Definition at line 92 of file PageInfo.cpp.

00093 {
00094     pthread_mutex_lock(&mutex);
00095     for(int i = 0; i < length ; ++i)
00096     {
00097         if (list[i])
00098         {
00099             delete list[i];
00100             list[i] = NULL;
00101         }            
00102     }
00103     pthread_mutex_unlock(&mutex);
00104 }

void PageList::addPage ( CPageInfo info  ) 

Definition at line 127 of file PageInfo.cpp.

00128 {
00129     if (NULL == info) return;
00130     int index = info->pageNumber;
00131     if (index < 1 || index > length) return;
00132     pthread_mutex_lock(&mutex);
00133     --index;
00134     if (list[index] == NULL)
00135     {
00136         list[index] = info;
00137     }
00138     else
00139     {
00140         /*
00141         PV_DUMP("Page already exist, parameters:\n");
00142         PV_DUMP("Original page %d\t\t", list[index]->pageNumber);
00143         PV_DUMP("zoom %lf\t", list[index]->pageZoom);       
00144         PV_DUMP("rotate %d\t", list[index]->rotate);     
00145         PV_DUMP("time %d\n", list[index]->timestamp);
00146         
00147         PV_DUMP("New page %d\t\t", info->pageNumber);
00148         PV_DUMP("zoom %lf\t", info->pageZoom);       
00149         PV_DUMP("rotate %d\t", info->rotate);     
00150         PV_DUMP("time %d\n", info->timestamp);
00151         */
00152         delete list[index]; list[index] = info;
00153     }
00154     pthread_mutex_unlock(&mutex);
00155 }

void PageList::removeOldestOne ( const int  center  ) 

Definition at line 161 of file PageInfo.cpp.

00162 {
00163     int index = -1, i;
00164     int min   = 0x7fffffff;
00165     CPageInfo * pItem = NULL;
00166     pthread_mutex_lock(&mutex);
00167 
00168     // find oldest page in unprotected area
00169     for(i = 0; i < center - ProtectWidth && i < length; ++i)
00170     {
00171         pItem = list[i];
00172         if (pItem && min > pItem->timestamp)
00173         {
00174             index = i; min = pItem->timestamp;
00175         }
00176     }
00177     for(i = center + ProtectWidth; i < length; ++i)
00178     {
00179         pItem = list[i];
00180         if (pItem && min > pItem->timestamp)
00181         {
00182             index = i; min = pItem->timestamp;
00183         }
00184     }
00185     if (index >= 0  && index < length)
00186     {
00187         PV_LOGPRINTF("delete page %d", list[index]->pageNumber);        
00188         delete list[index]; list[index] = NULL;
00189         pthread_mutex_unlock(&mutex);
00190         return;
00191     }
00192 
00193     // remove page most far from current page
00194     index = -1;
00195     int dist = 0, pos = -1;
00196     for(i = -ProtectWidth; i <= ProtectWidth; ++i)
00197     {
00198         index = center + i - 1;
00199         if (index < 0) index = 0;
00200         else if (index >= length) index = length - 1;
00201         if (list[index] && abs(index + 1 - center) > dist)
00202         {
00203             pos = index;
00204             dist = abs(index + 1 - center);
00205         }
00206     }    
00207     if (pos >= 0 && pos != center - 1) 
00208     {
00209         PV_LOGPRINTF("delete page %d\n", list[pos]->pageNumber);  
00210         delete list[pos]; list[pos] = NULL;
00211     }
00212     pthread_mutex_unlock(&mutex);
00213 }

Here is the call graph for this function:

CPageInfo * PageList::getPage ( const int  number  ) 

Definition at line 215 of file PageInfo.cpp.

00216 {
00217     CPageInfo * pItem = NULL;
00218     if (number < 1 || number > length) return NULL;
00219     pthread_mutex_lock(&mutex);
00220     pItem = list[number - 1];
00221     pthread_mutex_unlock(&mutex);
00222     return pItem;
00223 }

CPageInfo * PageList::checkPage ( const CPageInfo info  ) 

Definition at line 226 of file PageInfo.cpp.

00227 {
00228     CPageInfo * pItem = getPage(info.pageNumber);
00229     if (NULL == pItem) return NULL;
00230     if (pItem->isSame(info.pageNumber, info.pageZoom, info.rotate))
00231     {
00232         return pItem;
00233     }
00234     return NULL;
00235 }

Here is the call graph for this function:

CPageInfo * PageList::checkPage ( const TodoItem pItem  ) 

Definition at line 237 of file PageInfo.cpp.

00238 {
00239     if (NULL == todo) return NULL;
00240     CPageInfo * pItem = getPage(todo->pageNumber);
00241     if (NULL == pItem) return NULL;
00242     if (pItem->isSame(todo->pageNumber, todo->zoom, todo->rotate))
00243     {
00244         return pItem;
00245     }
00246     return NULL;
00247 }

Here is the call graph for this function:

void PageList::dump (  ) 

Definition at line 249 of file PageInfo.cpp.

00250 {
00251     PV_DUMP("\n\nPageList:\n");
00252     CPageInfo * pItem = NULL;
00253     pthread_mutex_lock(&mutex);
00254     for(int i = 0; i < length; ++i)
00255     {
00256         pItem = list[i];
00257         if (pItem)
00258         {
00259             PV_DUMP("page %d\t", pItem->pageNumber);
00260             PV_DUMP("zoom %lf\t", pItem->pageZoom);   
00261             PV_DUMP("rotate %d\t", pItem->rotate);         
00262             PV_DUMP("time %d\n", pItem->timestamp);
00263         }
00264     }
00265     PV_DUMP("\n\n");
00266     pthread_mutex_unlock(&mutex);
00267 }


Member Data Documentation

pthread_mutex_t PageList::mutex [private]

Definition at line 83 of file PageInfo.h.

Definition at line 84 of file PageInfo.h.

int PageList::length [private]

Definition at line 85 of file PageInfo.h.


The documentation for this class was generated from the following files:

Generated on Wed Feb 4 18:26:35 2009 by  doxygen 1.5.6