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 <rtl/ustring.hxx>
26 :
27 : #include "address.hxx"
28 : #include "global.hxx"
29 :
30 : class SvStream;
31 : class SvNumberFormatter;
32 : class ScDocument;
33 : class ScPatternAttr;
34 :
35 : extern const sal_Unicode pKeyTABLE[];
36 : extern const sal_Unicode pKeyVECTORS[];
37 : extern const sal_Unicode pKeyTUPLES[];
38 : extern const sal_Unicode pKeyDATA[];
39 : extern const sal_Unicode pKeyBOT[];
40 : extern const sal_Unicode pKeyEOD[];
41 : extern const sal_Unicode pKeyTRUE[];
42 : extern const sal_Unicode pKeyFALSE[];
43 : extern const sal_Unicode pKeyNA[];
44 : extern const sal_Unicode pKeyV[];
45 : extern const sal_Unicode pKey1_0[];
46 :
47 : enum TOPIC
48 : {
49 : T_UNKNOWN,
50 : T_TABLE, T_VECTORS, T_TUPLES, T_DATA, T_LABEL, T_COMMENT, T_SIZE,
51 : T_PERIODICITY, T_MAJORSTART, T_MINORSTART, T_TRUELENGTH, T_UINITS,
52 : T_DISPLAYUNITS,
53 : T_END
54 : };
55 :
56 : enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR };
57 :
58 : class DifAttrCache;
59 : class ScPatternAttr;
60 :
61 0 : class DifParser
62 : {
63 : public:
64 : OUString aData;
65 : double fVal;
66 : sal_uInt32 nVector;
67 : sal_uInt32 nVal;
68 : sal_uInt32 nNumFormat;
69 : rtl_TextEncoding eCharSet;
70 : private:
71 : SvNumberFormatter* pNumFormatter;
72 : SvStream& rIn;
73 : bool bPlain;
74 : OUString aLookAheadLine;
75 :
76 : bool ReadNextLine( OUString& rStr );
77 : bool LookAhead();
78 : DATASET GetNumberDataset( const sal_Unicode* pPossibleNumericData );
79 : static inline bool IsBOT( const sal_Unicode* pRef );
80 : static inline bool IsEOD( const sal_Unicode* pRef );
81 : static inline bool Is1_0( const sal_Unicode* pRef );
82 : public:
83 : DifParser( SvStream&, const sal_uInt32 nOption, ScDocument&, rtl_TextEncoding );
84 :
85 : TOPIC GetNextTopic( void );
86 :
87 : DATASET GetNextDataset( void );
88 :
89 : const sal_Unicode* ScanIntVal( const sal_Unicode* pStart, sal_uInt32& rRet );
90 : bool ScanFloatVal( const sal_Unicode* pStart );
91 :
92 : inline bool IsNumber( const sal_Unicode cChar );
93 : inline bool IsNumberEnding( const sal_Unicode cChar );
94 :
95 : static inline bool IsV( const sal_Unicode* pRef );
96 :
97 : inline bool IsPlain( void ) const;
98 : };
99 :
100 0 : inline bool DifParser::IsBOT( const sal_Unicode* pRef )
101 : {
102 0 : return ( pRef[ 0 ] == pKeyBOT[0] &&
103 0 : pRef[ 1 ] == pKeyBOT[1] &&
104 0 : pRef[ 2 ] == pKeyBOT[2] &&
105 0 : pRef[ 3 ] == pKeyBOT[3] );
106 : }
107 :
108 0 : inline bool DifParser::IsEOD( const sal_Unicode* pRef )
109 : {
110 0 : return ( pRef[ 0 ] == pKeyEOD[0] &&
111 0 : pRef[ 1 ] == pKeyEOD[1] &&
112 0 : pRef[ 2 ] == pKeyEOD[2] &&
113 0 : pRef[ 3 ] == pKeyEOD[3] );
114 : }
115 :
116 0 : inline bool DifParser::Is1_0( const sal_Unicode* pRef )
117 : {
118 0 : return ( pRef[ 0 ] == pKey1_0[0] &&
119 0 : pRef[ 1 ] == pKey1_0[1] &&
120 0 : pRef[ 2 ] == pKey1_0[2] &&
121 0 : pRef[ 3 ] == pKey1_0[3] );
122 : }
123 :
124 0 : inline bool DifParser::IsV( const sal_Unicode* pRef )
125 : {
126 0 : return ( pRef[ 0 ] == pKeyV[0] &&
127 0 : pRef[ 1 ] == pKeyV[1] );
128 : }
129 :
130 0 : inline bool DifParser::IsNumber( const sal_Unicode cChar )
131 : {
132 0 : return ( cChar >= '0' && cChar <= '9' );
133 : }
134 :
135 0 : inline bool DifParser::IsNumberEnding( const sal_Unicode cChar )
136 : {
137 0 : return ( cChar == 0x00 );
138 : }
139 :
140 0 : inline bool DifParser::IsPlain( void ) const
141 : {
142 0 : return bPlain;
143 : }
144 :
145 0 : class DifColumn
146 : {
147 : friend class DifAttrCache;
148 :
149 : struct ENTRY
150 : {
151 : sal_uInt32 nNumFormat;
152 : SCROW nStart;
153 : SCROW nEnd;
154 : };
155 :
156 : ENTRY *pAkt;
157 : boost::ptr_vector<ENTRY> aEntries;
158 :
159 : DifColumn();
160 :
161 : void SetLogical( SCROW nRow );
162 :
163 : void SetNumFormat( SCROW nRow, const sal_uInt32 nNumFormat );
164 :
165 : void NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat );
166 :
167 : void Apply( ScDocument&, const SCCOL nCol, const SCTAB nTab, const ScPatternAttr& );
168 :
169 : void Apply( ScDocument &rDoc, const SCCOL nCol, const SCTAB nTab );
170 : };
171 :
172 : class DifAttrCache
173 : {
174 : public:
175 :
176 : DifAttrCache( const bool bPlain );
177 :
178 : ~DifAttrCache();
179 :
180 : void SetLogical( const SCCOL nCol, const SCROW nRow );
181 :
182 : void SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat );
183 :
184 : void Apply( ScDocument&, SCTAB nTab );
185 :
186 : private:
187 :
188 : DifColumn** ppCols;
189 : bool bPlain;
190 : };
191 :
192 : #endif
193 :
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|