author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (unidiff) | |
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 @@ | |||
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 | ||
4 | const size_t NAVIGATION_HISTORY_SIZE = 32; | 7 | const size_t NAVIGATION_HISTORY_SIZE = 32; |
5 | 8 | ||
6 | class CNavigation | 9 | template<class T> |
10 | class CNavigation_base | ||
7 | { | 11 | { |
8 | size_t history[NAVIGATION_HISTORY_SIZE]; | 12 | protected: |
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 | |||
23 | class 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 | |||
30 | template<class T> | ||
31 | inline 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 | |||
42 | template<class T> | ||
43 | inline void CNavigation_base<T>::writeposn(T posn) | ||
44 | { | ||
45 | history[historycurrent] = posn; | ||
46 | } | ||
47 | |||
48 | template<class T> | ||
49 | inline 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 | |||
72 | template<class T> | ||
73 | inline 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 | ||