summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Navigation.h
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Navigation.h') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Navigation.h83
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 @@
1#ifndef __NAVIGATION_H
2#define __NAVIGATION_H
3
1#include <string.h> 4#include <string.h>
2#include <stdlib.h> 5#include <stdlib.h>
3 6
4const size_t NAVIGATION_HISTORY_SIZE = 32; 7const size_t NAVIGATION_HISTORY_SIZE = 32;
5 8
6class CNavigation 9template<class T>
10class CNavigation_base
7{ 11{
8 size_t history[NAVIGATION_HISTORY_SIZE]; 12protected:
13 T history[NAVIGATION_HISTORY_SIZE];
9 size_t historystart, historyend, historycurrent; 14 size_t historystart, historyend, historycurrent;
10 public: 15 public:
11 CNavigation() : historystart(0),historyend(0),historycurrent(0) {} 16 CNavigation_base() : historystart(0),historyend(0),historycurrent(0) {}
12 void saveposn(size_t posn); 17 void saveposn(T posn);
13 void writeposn(size_t posn); 18 void writeposn(T posn);
14 bool forward(size_t& loc); 19 bool forward(T& loc);
15 bool back(size_t& loc); 20 bool back(T& loc);
21};
22
23class CNavigation : public CNavigation_base<size_t>
24{
25 public:
16 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen); 26 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen);
17 void putSaveData(unsigned char*& src, unsigned short& srclen); 27 void putSaveData(unsigned char*& src, unsigned short& srclen);
18}; 28};
29
30template<class T>
31inline void CNavigation_base<T>::saveposn(T posn)
32{
33 history[historycurrent] = posn;
34 historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE;
35 if (historycurrent==historystart)
36 {
37 historystart=(historystart+1)%NAVIGATION_HISTORY_SIZE;
38 }
39 historyend = historycurrent;
40}
41
42template<class T>
43inline void CNavigation_base<T>::writeposn(T posn)
44{
45 history[historycurrent] = posn;
46}
47
48template<class T>
49inline bool CNavigation_base<T>::back(T& posn)
50{
51 if (historycurrent!=historystart)
52 {
53 // buffer is not empty
54 if (historycurrent==0)
55 {
56 historycurrent=NAVIGATION_HISTORY_SIZE-1;
57 }
58 else
59 {
60 historycurrent--;
61 }
62 posn=history[historycurrent];
63 return true;
64 }
65 else
66 {
67 // circular buffer empty
68 return false;
69 }
70}
71
72template<class T>
73inline bool CNavigation_base<T>::forward(T& posn)
74{
75 if (historycurrent!=historyend)
76 {
77 historycurrent=(historycurrent+1)%NAVIGATION_HISTORY_SIZE;
78 posn = history[historycurrent];
79 return true;
80 }
81 else
82 {
83 return false;
84 }
85}
86
87#endif