Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef SC_DIF_HXX
21 : #define SC_DIF_HXX
22 :
23 : #include <boost/ptr_container/ptr_vector.hpp>
24 :
25 : #include <tools/string.hxx>
26 : #include <rtl/ustring.hxx>
27 :
28 : #include "address.hxx"
29 : #include "global.hxx"
30 :
31 : class SvStream;
32 : class SvNumberFormatter;
33 : class ScDocument;
34 : class ScPatternAttr;
35 :
36 : extern const sal_Unicode pKeyTABLE[];
37 : extern const sal_Unicode pKeyVECTORS[];
38 : extern const sal_Unicode pKeyTUPLES[];
39 : extern const sal_Unicode pKeyDATA[];
40 : extern const sal_Unicode pKeyBOT[];
41 : extern const sal_Unicode pKeyEOD[];
42 : extern const sal_Unicode pKeyTRUE[];
43 : extern const sal_Unicode pKeyFALSE[];
44 : extern const sal_Unicode pKeyNA[];
45 : extern const sal_Unicode pKeyV[];
46 : extern const sal_Unicode pKey1_0[];
47 :
48 : enum TOPIC
49 : {
50 : T_UNKNOWN,
51 : T_TABLE, T_VECTORS, T_TUPLES, T_DATA, T_LABEL, T_COMMENT, T_SIZE,
52 : T_PERIODICITY, T_MAJORSTART, T_MINORSTART, T_TRUELENGTH, T_UINITS,
53 : T_DISPLAYUNITS,
54 : T_END
55 : };
56 :
57 : enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR };
58 :
59 : class DifAttrCache;
60 : class ScPatternAttr;
61 :
62 0 : class DifParser
63 : {
64 : public:
65 : String aData;
66 : double fVal;
67 : sal_uInt32 nVector;
68 : sal_uInt32 nVal;
69 : sal_uInt32 nNumFormat;
70 : CharSet eCharSet;
71 : private:
72 : SvNumberFormatter* pNumFormatter;
73 : SvStream& rIn;
74 : sal_Bool bPlain;
75 : rtl::OUString aLookAheadLine;
76 :
77 : bool ReadNextLine( rtl::OUString& rStr );
78 : bool LookAhead();
79 : DATASET GetNumberDataset( const sal_Unicode* pPossibleNumericData );
80 : static inline sal_Bool IsBOT( const sal_Unicode* pRef );
81 : static inline sal_Bool IsEOD( const sal_Unicode* pRef );
82 : static inline sal_Bool Is1_0( const sal_Unicode* pRef );
83 : public:
84 : DifParser( SvStream&, const sal_uInt32 nOption, ScDocument&, CharSet );
85 :
86 : TOPIC GetNextTopic( void );
87 :
88 : DATASET GetNextDataset( void );
89 :
90 : const sal_Unicode* ScanIntVal( const sal_Unicode* pStart, sal_uInt32& rRet );
91 : sal_Bool ScanFloatVal( const sal_Unicode* pStart );
92 :
93 : inline sal_Bool IsNumber( const sal_Unicode cChar );
94 : inline sal_Bool IsNumberEnding( const sal_Unicode cChar );
95 :
96 : static inline sal_Bool IsV( const sal_Unicode* pRef );
97 :
98 : inline sal_Bool IsPlain( void ) const;
99 : };
100 :
101 0 : inline sal_Bool DifParser::IsBOT( const sal_Unicode* pRef )
102 : {
103 0 : return ( pRef[ 0 ] == pKeyBOT[0] &&
104 0 : pRef[ 1 ] == pKeyBOT[1] &&
105 0 : pRef[ 2 ] == pKeyBOT[2] &&
106 0 : pRef[ 3 ] == pKeyBOT[3] );
107 : }
108 :
109 0 : inline sal_Bool DifParser::IsEOD( const sal_Unicode* pRef )
110 : {
111 0 : return ( pRef[ 0 ] == pKeyEOD[0] &&
112 0 : pRef[ 1 ] == pKeyEOD[1] &&
113 0 : pRef[ 2 ] == pKeyEOD[2] &&
114 0 : pRef[ 3 ] == pKeyEOD[3] );
115 : }
116 :
117 0 : inline sal_Bool DifParser::Is1_0( const sal_Unicode* pRef )
118 : {
119 0 : return ( pRef[ 0 ] == pKey1_0[0] &&
120 0 : pRef[ 1 ] == pKey1_0[1] &&
121 0 : pRef[ 2 ] == pKey1_0[2] &&
122 0 : pRef[ 3 ] == pKey1_0[3] );
123 : }
124 :
125 0 : inline sal_Bool DifParser::IsV( const sal_Unicode* pRef )
126 : {
127 0 : return ( pRef[ 0 ] == pKeyV[0] &&
128 0 : pRef[ 1 ] == pKeyV[1] );
129 : }
130 :
131 0 : inline sal_Bool DifParser::IsNumber( const sal_Unicode cChar )
132 : {
133 0 : return ( cChar >= '0' && cChar <= '9' );
134 : }
135 :
136 0 : inline sal_Bool DifParser::IsNumberEnding( const sal_Unicode cChar )
137 : {
138 0 : return ( cChar == 0x00 );
139 : }
140 :
141 0 : inline sal_Bool DifParser::IsPlain( void ) const
142 : {
143 0 : return bPlain;
144 : }
145 :
146 0 : class DifColumn
147 : {
148 : friend class DifAttrCache;
149 :
150 : struct ENTRY
151 : {
152 : sal_uInt32 nNumFormat;
153 : SCROW nStart;
154 : SCROW nEnd;
155 : };
156 :
157 : ENTRY *pAkt;
158 : boost::ptr_vector<ENTRY> aEntries;
159 :
160 : DifColumn();
161 :
162 : void SetLogical( SCROW nRow );
163 :
164 : void SetNumFormat( SCROW nRow, const sal_uInt32 nNumFormat );
165 :
166 : void NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat );
167 :
168 : void Apply( ScDocument&, const SCCOL nCol, const SCTAB nTab, const ScPatternAttr& );
169 :
170 : void Apply( ScDocument &rDoc, const SCCOL nCol, const SCTAB nTab );
171 : };
172 :
173 : class DifAttrCache
174 : {
175 : public:
176 :
177 : DifAttrCache( const sal_Bool bPlain );
178 :
179 : ~DifAttrCache();
180 :
181 : void SetLogical( const SCCOL nCol, const SCROW nRow );
182 :
183 : void SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat );
184 :
185 : void Apply( ScDocument&, SCTAB nTab );
186 :
187 : private:
188 :
189 : DifColumn** ppCols;
190 : sal_Bool bPlain;
191 : };
192 :
193 : #endif
194 :
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|