list.cpp

00001 /***************************************************************************
00002                           list.cpp  -  description
00003                              -------------------
00004     begin                : Fri Feb 20 2004
00005     copyright            : (C) 2004 by Dynacube Team
00006     email                : 
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  #include "gui/components/list.h"
00019 
00020  struct
00021  {
00022    DB avl;
00023    window *wind_ptr;
00024  } wind_list[MAX_PROC][WINDOW_MAX];
00025 
00026  struct
00027  {
00028    DB avl;
00029    frame *frm_ptr;
00030  }frm_list[MAX_PROC][FRAME_MAX];
00031 
00032  struct
00033  {
00034    DB avl;
00035    component *comp_ptr;
00036  } comp_list[MAX_PROC][COMPONENT_MAX];
00037 
00038   DW win_max[MAX_PROC] = {0};
00039   DW frm_max[MAX_PROC] = {0};
00040   DW comp_max[MAX_PROC]= {0};
00041 
00042   void list_init()
00043   {
00044     DW i, j;
00045 
00046     for(i = 0 ; i < MAX_PROC ; i++)
00047     {
00048       for(j = 0 ; j < WINDOW_MAX ; j++)
00049       {
00050        wind_list[i][j].avl  =  AVL;
00051       }
00052 
00053       for(j = 0 ; j < FRAME_MAX ; j++)
00054       {
00055         frm_list[i][j].avl = AVL;
00056       }
00057 
00058       for(j = 0 ; j < COMPONENT_MAX ; j++)
00059       {
00060         comp_list[i][j].avl = AVL;
00061       }
00062     }
00063   }
00064 
00065   SDW ladd(DW pid, DB type, void *ptr)
00066   {
00067    DW max1 = 0, *max2;
00068    DW i;
00069 
00070    switch(type)
00071    {
00072     case WIND_TYPE:
00073           max1 = WINDOW_MAX;
00074           max2 = &win_max[pid];
00075           
00076               if(*max2 < max1)
00077               {
00078                 wind_list[pid][*max2].avl = UNAVL;
00079                 wind_list[pid][*max2].wind_ptr = (window*)ptr;
00080                 *max2 = *max2 + 1;
00081                 return (*max2-1);
00082               }
00083               else
00084               {
00085                 for(i = 0 ; i < max1 ; i++)
00086                 {
00087                  if(wind_list[pid][i].avl == AVL)
00088                  {
00089                   wind_list[pid][i].avl = UNAVL;
00090                   wind_list[pid][i].wind_ptr = (window*)ptr;
00091                   return i;
00092                  }
00093                 }
00094 
00095                 if( i == max1)
00096                   return -1;
00097               }
00098           
00099           break;
00100 
00101     case FRM_TYPE:
00102           max1 = FRAME_MAX;
00103           max2 = &frm_max[pid];
00104 
00105               if(*max2 < max1)
00106               {
00107                 frm_list[pid][*max2].avl = UNAVL;
00108                 frm_list[pid][*max2].frm_ptr = (frame*)ptr;
00109                 *max2 = *max2 + 1;
00110                 return (*max2-1);
00111               }
00112               else
00113               {
00114                 for(i = 0 ; i < max1 ; i++)
00115                 {
00116                  if(frm_list[pid][i].avl == AVL)
00117                  {
00118                   frm_list[pid][i].avl = UNAVL;
00119                   frm_list[pid][i].frm_ptr = (frame*)ptr;
00120                   return i;
00121                  }
00122                 }
00123 
00124                 if( i == max1)
00125                   return -1;
00126               }
00127 
00128           break;
00129 
00130     case COMP_TYPE:
00131           max1 = COMPONENT_MAX;
00132           max2 = &comp_max[pid];
00133 
00134               if(*max2 < max1)
00135               {
00136                 comp_list[pid][*max2].avl = UNAVL;
00137                 comp_list[pid][*max2].comp_ptr = (component*)ptr;
00138                 *max2 = *max2 + 1;
00139                 return (*max2-1);                
00140               }
00141               else
00142               {
00143                 for(i = 0 ; i < max1 ; i++)
00144                 {
00145                  if(comp_list[pid][i].avl == AVL)
00146                  {
00147                   comp_list[pid][i].avl = UNAVL;
00148                   comp_list[pid][i].comp_ptr = (component*)ptr;
00149                   return i;
00150                  }
00151                 }
00152 
00153                 if( i == max1)
00154                   return -1;
00155               }
00156           break;
00157 
00158     default:
00159           return -1;          
00160    }
00161    
00162   }
00163 
00164   SDW lremove(DW pid, DB type, DW index)
00165   {
00166    switch(type)
00167    {
00168     case WIND_TYPE:
00169           if(wind_list[pid][index].avl == UNAVL)
00170           {
00171             wind_list[pid][index].avl = AVL;
00172             return 0;
00173           }
00174           else
00175             return -1;
00176           break;
00177 
00178     case FRM_TYPE:
00179           if(frm_list[pid][index].avl == UNAVL)
00180           {
00181             frm_list[pid][index].avl = AVL;
00182             return 0;
00183           }
00184           else
00185             return -1;
00186           break;
00187 
00188     case COMP_TYPE:
00189           if(comp_list[pid][index].avl == UNAVL)
00190           {
00191             comp_list[pid][index].avl = AVL;
00192             return 0;
00193           }
00194           else
00195             return -1;
00196           break;
00197 
00198     default:
00199           return -1;
00200    }
00201   }
00202 
00203   void lremoveAll(DW pid)
00204   {
00205     DW j;
00206 
00207       for(j = 0 ; j < WINDOW_MAX ; j++)
00208       {
00209 //change      
00210        if(wind_list[pid][j].avl == UNAVL)
00211         {
00212         wind_list[pid][j].wind_ptr->freeAll();
00213         free((void *)wind_list[pid][j].wind_ptr);
00214         }
00215        wind_list[pid][j].avl  =  AVL;
00216       }
00217       win_max[pid] = 0;
00218 
00219       for(j = 0 ; j < FRAME_MAX ; j++)
00220       {
00221         frm_list[pid][j].avl = AVL;
00222       }
00223       frm_max[pid] = 0;
00224 
00225       for(j = 0 ; j < COMPONENT_MAX ; j++)
00226       {
00227         comp_list[pid][j].avl = AVL;
00228       }
00229       comp_max[pid] = 0;
00230   }
00231 
00232   void* lfind(DW pid, DB type, DW index) //Return read_id or -1
00233   {
00234    switch(type)
00235    {
00236     case WIND_TYPE:
00237           if(wind_list[pid][index].avl == UNAVL)
00238             return (void *)wind_list[pid][index].wind_ptr;
00239           else
00240             return NULL;
00241           break;
00242 
00243     case FRM_TYPE:
00244           if(frm_list[pid][index].avl == UNAVL)
00245             return (void *)frm_list[pid][index].frm_ptr;
00246           else
00247             return NULL;
00248           break;
00249 
00250     case COMP_TYPE:
00251           if(comp_list[pid][index].avl == UNAVL)
00252             return (void *)comp_list[pid][index].comp_ptr;
00253           else
00254             return NULL;
00255           break;
00256 
00257     default:
00258           return NULL;
00259    }    
00260   }
00261 
00262 
00263   void printList(DW pid, DB type)
00264   {
00265    DW i;
00266 
00267    printf("\n PID %d type %d",pid,type);
00268    
00269    switch(type)
00270    {
00271     case WIND_TYPE:
00272           for(i = 0 ; i < win_max[pid] ; i++)
00273           {
00274             if(wind_list[pid][i].avl == UNAVL)
00275             {
00276               printf("\n (%d) ptr= %x ",i,wind_list[pid][i].wind_ptr);
00277             }            
00278           }
00279           break;
00280 
00281     case FRM_TYPE:
00282           for(i = 0 ; i < frm_max[pid] ; i++)
00283           {
00284             if(frm_list[pid][i].avl == UNAVL)
00285             {
00286               printf("\n (%d) ptr= %x ",i,frm_list[pid][i].frm_ptr);
00287             }
00288           }
00289           break;
00290 
00291     case COMP_TYPE:
00292           for(i = 0 ; i < comp_max[pid] ; i++)
00293           {
00294             if(comp_list[pid][i].avl == UNAVL)
00295             {
00296               printf("\n (%d) ptr= %x ",i,comp_list[pid][i].comp_ptr);
00297             }
00298           }
00299           break;
00300 
00301     default:
00302           return;
00303    }
00304     
00305   }

Generated on Thu Jul 27 23:52:27 2006 for Dynacube by  doxygen 1.4.7