author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (side-by-side diff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/Navigation.h | |
parent | e90847c784c48bd21bf8768cb38edb853b832697 (diff) | |
download | opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2 |
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/Navigation.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Navigation.h | 83 |
1 files changed, 76 insertions, 7 deletions
diff --git a/noncore/apps/opie-reader/Navigation.h b/noncore/apps/opie-reader/Navigation.h index 19d7f81..d88443b 100644 --- a/noncore/apps/opie-reader/Navigation.h +++ b/noncore/apps/opie-reader/Navigation.h @@ -1,18 +1,87 @@ +#ifndef __NAVIGATION_H +#define __NAVIGATION_H + #include <string.h> #include <stdlib.h> const size_t NAVIGATION_HISTORY_SIZE = 32; -class CNavigation +template<class T> +class CNavigation_base { - size_t history[NAVIGATION_HISTORY_SIZE]; +protected: + T history[NAVIGATION_HISTORY_SIZE]; size_t historystart, historyend, historycurrent; public: - CNavigation() : historystart(0),historyend(0),historycurrent(0) {} - void saveposn(size_t posn); - void writeposn(size_t posn); - bool forward(size_t& loc); - bool back(size_t& loc); + CNavigation_base() : historystart(0),historyend(0),historycurrent(0) {} + void saveposn(T posn); + void writeposn(T posn); + bool forward(T& loc); + bool back(T& loc); +}; + +class CNavigation : public CNavigation_base<size_t> +{ + public: void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen); void putSaveData(unsigned char*& src, unsigned short& srclen); }; + +template<class T> +inline void CNavigation_base<T>::saveposn(T posn) +{ + history[historycurrent] = posn; + historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE; + if (historycurrent==historystart) + { + historystart=(historystart+1)%NAVIGATION_HISTORY_SIZE; + } + historyend = historycurrent; +} + +template<class T> +inline void CNavigation_base<T>::writeposn(T posn) +{ + history[historycurrent] = posn; +} + +template<class T> +inline bool CNavigation_base<T>::back(T& posn) +{ + if (historycurrent!=historystart) + { + // buffer is not empty + if (historycurrent==0) + { + historycurrent=NAVIGATION_HISTORY_SIZE-1; + } + else + { + historycurrent--; + } + posn=history[historycurrent]; + return true; + } + else + { + // circular buffer empty + return false; + } +} + +template<class T> +inline bool CNavigation_base<T>::forward(T& posn) +{ + if (historycurrent!=historyend) + { + historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE; + posn = history[historycurrent]; + return true; + } + else + { + return false; + } +} + +#endif |