1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24
25 #ifndef SC_DIF_HXX
26 #define SC_DIF_HXX
27
28 #include <tools/debug.hxx>
29 #include <tools/list.hxx>
30 #include <tools/string.hxx>
31 #include "global.hxx"
32 #include "address.hxx"
33
34
35 class SvStream;
36 class SvNumberFormatter;
37 class ScDocument;
38 class ScPatternAttr;
39
40 extern const sal_Unicode pKeyTABLE[];
41 extern const sal_Unicode pKeyVECTORS[];
42 extern const sal_Unicode pKeyTUPLES[];
43 extern const sal_Unicode pKeyDATA[];
44 extern const sal_Unicode pKeyBOT[];
45 extern const sal_Unicode pKeyEOD[];
46 extern const sal_Unicode pKeyTRUE[];
47 extern const sal_Unicode pKeyFALSE[];
48 extern const sal_Unicode pKeyNA[];
49 extern const sal_Unicode pKeyV[];
50 extern const sal_Unicode pKey1_0[];
51
52
53 enum TOPIC
54 {
55 T_UNKNOWN,
56 T_TABLE, T_VECTORS, T_TUPLES, T_DATA, T_LABEL, T_COMMENT, T_SIZE,
57 T_PERIODICITY, T_MAJORSTART, T_MINORSTART, T_TRUELENGTH, T_UINITS,
58 T_DISPLAYUNITS,
59 T_END
60 };
61
62 enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR };
63
64
65 class DifParser
66 {
67 public:
68 String aData;
69 double fVal;
70 sal_uInt32 nVector;
71 sal_uInt32 nVal;
72 sal_uInt32 nNumFormat;
73 CharSet eCharSet;
74 private:
75 SvNumberFormatter* pNumFormatter;
76 SvStream& rIn;
77 sal_Bool bPlain;
78 String aLookAheadLine;
79
80 bool ReadNextLine( String& rStr );
81 bool LookAhead();
82 DATASET GetNumberDataset( const sal_Unicode* pPossibleNumericData );
83 static inline sal_Bool IsBOT( const sal_Unicode* pRef );
84 static inline sal_Bool IsEOD( const sal_Unicode* pRef );
85 static inline sal_Bool Is1_0( const sal_Unicode* pRef );
86 public:
87 DifParser( SvStream&, const sal_uInt32 nOption, ScDocument&, CharSet );
88
89 TOPIC GetNextTopic( void );
90
91 DATASET GetNextDataset( void );
92
93 const sal_Unicode* ScanIntVal( const sal_Unicode* pStart, sal_uInt32& rRet );
94 sal_Bool ScanFloatVal( const sal_Unicode* pStart );
95
96 inline sal_Bool IsNumber( const sal_Unicode cChar );
97 inline sal_Bool IsNumberEnding( const sal_Unicode cChar );
98
99 static inline sal_Bool IsV( const sal_Unicode* pRef );
100
101 inline sal_Bool IsPlain( void ) const;
102 };
103
104
IsBOT(const sal_Unicode * pRef)105 inline sal_Bool DifParser::IsBOT( const sal_Unicode* pRef )
106 {
107 return ( pRef[ 0 ] == pKeyBOT[0] &&
108 pRef[ 1 ] == pKeyBOT[1] &&
109 pRef[ 2 ] == pKeyBOT[2] &&
110 pRef[ 3 ] == pKeyBOT[3] );
111 }
112
113
IsEOD(const sal_Unicode * pRef)114 inline sal_Bool DifParser::IsEOD( const sal_Unicode* pRef )
115 {
116 return ( pRef[ 0 ] == pKeyEOD[0] &&
117 pRef[ 1 ] == pKeyEOD[1] &&
118 pRef[ 2 ] == pKeyEOD[2] &&
119 pRef[ 3 ] == pKeyEOD[3] );
120 }
121
122
Is1_0(const sal_Unicode * pRef)123 inline sal_Bool DifParser::Is1_0( const sal_Unicode* pRef )
124 {
125 return ( pRef[ 0 ] == pKey1_0[0] &&
126 pRef[ 1 ] == pKey1_0[1] &&
127 pRef[ 2 ] == pKey1_0[2] &&
128 pRef[ 3 ] == pKey1_0[3] );
129 }
130
131
IsV(const sal_Unicode * pRef)132 inline sal_Bool DifParser::IsV( const sal_Unicode* pRef )
133 {
134 return ( pRef[ 0 ] == pKeyV[0] &&
135 pRef[ 1 ] == pKeyV[1] );
136 }
137
138
IsNumber(const sal_Unicode cChar)139 inline sal_Bool DifParser::IsNumber( const sal_Unicode cChar )
140 {
141 return ( cChar >= '0' && cChar <= '9' );
142 }
143
144
IsNumberEnding(const sal_Unicode cChar)145 inline sal_Bool DifParser::IsNumberEnding( const sal_Unicode cChar )
146 {
147 return ( cChar == 0x00 );
148 }
149
150
IsPlain(void) const151 inline sal_Bool DifParser::IsPlain( void ) const
152 {
153 return bPlain;
154 }
155
156
157
158
159 class DifAttrCache;
160 class ScPatternAttr;
161
162
163 class DifColumn : private List
164 {
165 private:
166 friend class DifAttrCache;
167 struct ENTRY
168 {
169 sal_uInt32 nNumFormat;
170
171 SCROW nStart;
172 SCROW nEnd;
173 };
174
175 ENTRY* pAkt;
176
177 inline DifColumn( void );
178 ~DifColumn();
179 void SetLogical( SCROW nRow );
180 void SetNumFormat( SCROW nRow, const sal_uInt32 nNumFormat );
181 void NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat );
182 void Apply( ScDocument&, const SCCOL nCol, const SCTAB nTab, const ScPatternAttr& );
183 void Apply( ScDocument &rDoc, const SCCOL nCol, const SCTAB nTab );
184 public: // geht niemanden etwas an...
185 };
186
187
DifColumn(void)188 inline DifColumn::DifColumn( void )
189 {
190 pAkt = NULL;
191 }
192
193
194
195
196 class DifAttrCache
197 {
198 private:
199 DifColumn** ppCols;
200 sal_Bool bPlain;
201 public:
202 DifAttrCache( const sal_Bool bPlain );
203 ~DifAttrCache();
204 inline void SetLogical( const SCCOL nCol, const SCROW nRow );
205 void SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat );
206 void Apply( ScDocument&, SCTAB nTab );
207 };
208
209
SetLogical(const SCCOL nCol,const SCROW nRow)210 inline void DifAttrCache::SetLogical( const SCCOL nCol, const SCROW nRow )
211 {
212 DBG_ASSERT( ValidCol(nCol), "-DifAttrCache::SetLogical(): Col zu gross!" );
213 DBG_ASSERT( bPlain, "*DifAttrCache::SetLogical(): muss Plain sein!" );
214
215 if( !ppCols[ nCol ] )
216 ppCols[ nCol ] = new DifColumn;
217 ppCols[ nCol ]->SetLogical( nRow );
218 }
219
220
221 #endif
222
223
224