Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

Simple1DIndexList.hpp

00001 #ifndef __Simple1DIndexList_H__
00002 #define __Simple1DIndexList_H__
00003 
00004 
00025 #include <string.h>
00026 
00027 class Simple1DIndexList
00028 {
00029 private:
00030 
00031 int                     n,nmax;
00032 int*    index;
00033 
00034 int                     position;
00035         
00036 public:
00037 Simple1DIndexList(int maxItems=5)
00038         {
00039         nmax= maxItems;    n=position=0;
00040         index= new int[nmax];
00041         clearAll();
00042         }
00043 ~Simple1DIndexList(){delete[] index;}
00044 
00045 void clear(){memset(index, 0, n*sizeof(int)); n=0; position=0;}
00046 void clearAll(){memset(index, 0, nmax*sizeof(int)); n=0; position=0; }
00047 
00048 inline int get(int i){ return index[i]; }
00049 inline void set(int i, int val){ index[i]= val; }
00050 
00051 inline int first()
00052                 { if(isEmpty()) return -1; 
00053                 position=0; return index[0]; }
00054 
00055 inline int next()
00056                 { if(isEmpty() || position == n-1) return -1; 
00057                 position++; return index[position]; }
00058 
00059 inline int previous()
00060                 { if(isEmpty() || position == 0) return -1; 
00061                 position--; return index[position]; }
00062 
00063 inline int last()               
00064                 { if(isEmpty()) return -1; 
00065                 position=n-1; return index[n-1]; }
00066 
00067 inline int maxIndexes(){ return nmax; } 
00068 inline int numberOfIndexes(){ return n; }       
00069 inline bool isEmpty(){ return (n==0) ? true : false; }
00070 inline bool isFull(){ return (n==nmax) ? true : false; }
00071 
00072 inline bool push(int newIndex)
00073         {
00074         if( isFull() ) return false;
00075         index[n]= newIndex;
00076         n++;
00077         return true;
00078         }
00079 
00080 inline int pop()
00081         {
00082         if( isEmpty() ) return -1;                      // indexes must be positive
00083         int nOld=n;
00084         n--;
00085         return index[nOld];
00086         }
00087 
00088 void output()
00089         {
00090         printf("indexes[%d,%d]: (", n,nmax);
00091         for(int i=0; i<n;i++)
00092                 printf(" %d", index[i]);
00093         printf(")\n");
00094         }
00095 };
00096 
00097 #endif
00098 
00099  
SourceForge.net Logo
Restoreinpaint sourceforge project `C++/Java Image Processing, Restoration, Inpainting Project'.

Bernard De Cuyper: Open Project Leader: Concept, design and development.
Bernard De Cuyper & Eddy Fraiha 2002, 2003. Bernard De Cuyper 2004. Open and free, for friendly usage only.
Modifications on Belgium ground of this piece of artistic work, by governement institutions or companies, must be notified to Bernard De Cuyper.
bern_bdc@hotmail.com