|
1 // bufferbase.h |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #ifndef BUFFERBASE_H_ |
|
14 #define BUFFERBASE_H_ |
|
15 |
|
16 #include <e32base.h> |
|
17 |
|
18 #include "common.h" |
|
19 |
|
20 enum TEncodingType |
|
21 { |
|
22 EEncodingUnknown, |
|
23 EEncodingNarrow, |
|
24 EEncodingUtf8, |
|
25 EEncodingUtf16LE, |
|
26 EEncodingUtf16BE, |
|
27 #ifdef __BIG_ENDIAN__ // I know Symbian doesn't actually define the endian macros (afaics) but if they do, we'll do the right thing(TM) |
|
28 EEncodingUtf16Native = EEncodingUtf16BE, |
|
29 EEncodingUtf16Switched = EEncodingUtf16LE, |
|
30 #else |
|
31 // Assume little-endian unless specifically told otherwise |
|
32 EEncodingUtf16Native = EEncodingUtf16LE, |
|
33 EEncodingUtf16Switched = EEncodingUtf16BE, |
|
34 #endif |
|
35 }; |
|
36 |
|
37 enum TDelimiterType |
|
38 { |
|
39 EDelimNotYetKnown = 0, |
|
40 EDelimLF, // Unix |
|
41 EDelimCRLF, // DOS |
|
42 EDelimCR, // old school mac |
|
43 EDelimUnicode, // KUnicodeLineBreak - really doubt we'll see many of these! |
|
44 }; |
|
45 |
|
46 class CFileBlock; |
|
47 |
|
48 //Parent class for all memory buffers which can be used by appropriate views to read/write data and show it on the screen |
|
49 class CFedBufferBase : public CActive, public MSharedCacheProvider |
|
50 { |
|
51 protected: |
|
52 CFedBufferBase(); |
|
53 |
|
54 public: |
|
55 TInt RefCount() const; |
|
56 void PushL(); // Pushes a cleanup stack item that does a DecRef() |
|
57 void IncRef(); |
|
58 TInt DecRef(); |
|
59 ~CFedBufferBase(); |
|
60 |
|
61 public: // From MSharedCacheProvider |
|
62 TInt RegisterClient(MSharedCacheClient& aClient, TPtrC& aDes, TRange& aRange, TInt& aRangeStartLineNumber); |
|
63 void UnregisterClient(MSharedCacheClient& aClient); |
|
64 |
|
65 public: // CActive (noops in this class, override if you actually use the CActive-ness |
|
66 void DoCancel(); |
|
67 void RunL(); |
|
68 |
|
69 public: |
|
70 virtual const TDesC& Title() const = 0; |
|
71 virtual TBool Modified() const; |
|
72 virtual TBool Editable() const; |
|
73 virtual TDelimiterType DelimiterType() const = 0; |
|
74 virtual TEncodingType Encoding() const = 0; |
|
75 virtual TBool IsOpen() const; |
|
76 |
|
77 virtual TInt GetData(MSharedCacheClient& aClient, TInt aDocumentPosition) = 0; // "Get me the block containing aDocumentPosition". |
|
78 virtual TInt SeekFromOffset(MSharedCacheClient& aClient, TInt aOffset, TInt aNumLinesFromOffset, TInt aLineLength) = 0; |
|
79 virtual TBool DocumentPositionIsEof(TInt aDocumentPosition) const = 0; // The block containing aDocumentPosition MUST have already have been loaded (otherwise we could not guarantee const-ness) |
|
80 virtual TInt Find(TInt aStartingPosition, const TDesC& aSearchString, TBool aBackwards) = 0; |
|
81 |
|
82 virtual void InsertTextL(TInt aDocumentPosition, const TDesC& aText); |
|
83 virtual void DeleteTextL(TRange aRange); |
|
84 virtual void SaveL(const TDesC& aName, TBool aReplace); |
|
85 |
|
86 protected: |
|
87 TInt FindClientRequest(MSharedCacheClient& aClient); |
|
88 |
|
89 class TClientRequest |
|
90 { |
|
91 public: |
|
92 TClientRequest(MSharedCacheClient* aClient, TPtrC& aDes, TRange& aRange, TInt& aRangeStartLineNumber) |
|
93 : iClient(aClient), iDes(aDes), iRange(aRange), iLastRequestedBlock(NULL), iRangeStartLineNumber(aRangeStartLineNumber) |
|
94 {} |
|
95 public: |
|
96 MSharedCacheClient* iClient; |
|
97 TPtrC& iDes; |
|
98 TRange& iRange; // iRange is the document range for whatever's in iDes (used for something else during seeking) |
|
99 CFileBlock* iLastRequestedBlock; |
|
100 TInt& iRangeStartLineNumber; |
|
101 }; |
|
102 |
|
103 private: |
|
104 TInt iRefCount; |
|
105 protected: |
|
106 RArray<TClientRequest> iClientRequests; |
|
107 |
|
108 }; |
|
109 |
|
110 class CConstDataBuffer : public CFedBufferBase |
|
111 { |
|
112 public: |
|
113 CConstDataBuffer(const TDesC& aTitle, const TDesC& aText); |
|
114 CConstDataBuffer(const TDesC& aTitle, HBufC* aTextPtr); |
|
115 ~CConstDataBuffer(); |
|
116 |
|
117 const TDesC& Title() const; |
|
118 TDelimiterType DelimiterType() const; |
|
119 TEncodingType Encoding() const; |
|
120 |
|
121 TInt GetData(MSharedCacheClient& aClient, TInt aDocumentPosition); |
|
122 TInt SeekFromOffset(MSharedCacheClient& aClient, TInt aOffset, TInt aNumLinesFromOffset, TInt aLineLength); |
|
123 TBool DocumentPositionIsEof(TInt aDocumentPosition) const; |
|
124 TInt Find(TInt aStartingPosition, const TDesC& aSearchString, TBool aBackwards); |
|
125 |
|
126 private: |
|
127 const TDesC& iTitle; |
|
128 TPtrC iText; |
|
129 HBufC* iOwnedTextPtr; |
|
130 }; |
|
131 |
|
132 #endif /*BUFFERBASE_H_*/ |