Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Navigation.h

Go to the documentation of this file.
00001 #ifndef __NAVIGATION_H
00002 #define __NAVIGATION_H
00003 
00004 #include <string.h>
00005 #include <stdlib.h>
00006 
00007 const size_t NAVIGATION_HISTORY_SIZE = 32;
00008 
00009 template<class T>
00010 class CNavigation_base
00011 {
00012 protected:
00013     T history[NAVIGATION_HISTORY_SIZE];
00014     size_t historystart, historyend, historycurrent;
00015  public:
00016     CNavigation_base() : historystart(0),historyend(0),historycurrent(0) {}
00017     void saveposn(T posn);
00018     void writeposn(T posn);
00019     bool forward(T& loc);
00020     bool back(T& loc);
00021 };
00022 
00023 class CNavigation : public CNavigation_base<size_t>
00024 {
00025  public:
00026     void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen);
00027     void putSaveData(unsigned char*& src, unsigned short& srclen);
00028 };
00029 
00030 template<class T>
00031 inline void CNavigation_base<T>::saveposn(T posn)
00032 {
00033     history[historycurrent] = posn;
00034     historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE;
00035     if (historycurrent==historystart)
00036       {
00037         historystart=(historystart+1)%NAVIGATION_HISTORY_SIZE;
00038       }
00039     historyend = historycurrent;
00040 }
00041 
00042 template<class T>
00043 inline void CNavigation_base<T>::writeposn(T posn)
00044 {
00045     history[historycurrent] = posn;
00046 }
00047 
00048 template<class T>
00049 inline bool CNavigation_base<T>::back(T& posn)
00050 {
00051   if (historycurrent!=historystart)
00052     {
00053       // buffer is not empty
00054       if (historycurrent==0)
00055         {
00056           historycurrent=NAVIGATION_HISTORY_SIZE-1;
00057         }
00058       else
00059         {
00060           historycurrent--;
00061         }
00062       posn=history[historycurrent];
00063       return true;   
00064     }
00065   else
00066     {
00067       // circular buffer empty
00068       return false;
00069     }
00070 }
00071 
00072 template<class T>
00073 inline bool CNavigation_base<T>::forward(T& posn)
00074 {
00075   if (historycurrent!=historyend)
00076     {
00077       historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE;
00078       posn = history[historycurrent];
00079       return true;
00080     }
00081   else
00082     {
00083       return false;
00084     }
00085 }
00086 
00087 #endif

Generated on Sat Nov 5 16:16:56 2005 for OPIE by  doxygen 1.4.2