fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / svtools / svparser.hxx
blobbd2ee966469a6d2cc345536dc6044f4bb276a8e9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SVPARSER_HXX
21 #define _SVPARSER_HXX
23 #include "svtools/svtdllapi.h"
24 #include <tools/link.hxx>
25 #include <tools/string.hxx>
26 #include <tools/ref.hxx>
27 #include <rtl/textenc.h>
28 #include <boost/ptr_container/ptr_vector.hpp>
29 #include <boost/utility.hpp>
30 #include <vector>
32 struct SvParser_Impl;
33 class SvStream;
35 enum SvParserState
37 SVPAR_ACCEPTED = 0,
38 SVPAR_NOTSTARTED,
39 SVPAR_WORKING,
40 SVPAR_PENDING,
41 SVPAR_WAITFORDATA,
42 SVPAR_ERROR
45 class SVT_DLLPUBLIC SvParser : public SvRefBase
47 DECL_STATIC_LINK( SvParser, NewDataRead, void* );
49 protected:
50 SvStream& rInput;
51 String aToken; // gescanntes Token
52 sal_uLong nlLineNr; // akt. Zeilen Nummer
53 sal_uLong nlLinePos; // akt. Spalten Nummer
55 SvParser_Impl *pImplData; // interne Daten
56 long nTokenValue; // zusaetzlicher Wert (RTF)
57 sal_Bool bTokenHasValue; // indicates whether nTokenValue is valid
58 SvParserState eState; // Status auch in abgl. Klassen
60 rtl_TextEncoding eSrcEnc; // Source encoding
62 sal_uLong nNextChPos;
63 sal_Unicode nNextCh; // Akt. Zeichen fuer die "lex"
66 sal_Bool bDownloadingFile : 1;// sal_True: Es wird gerade ein externes
67 // File geladen. d.h. alle
68 // DataAvailable Links muessen
69 // ignoriert werden.
70 // Wenn keibes der folgenden
71 // Flags gesetzt ist, wird der
72 // Stream als ANSI gelesen,
73 // aber als CharSet DONTKNOW
74 // zurueckgegeben.
75 sal_Bool bUCS2BSrcEnc : 1; // oder als big-endian UCS2
76 sal_Bool bSwitchToUCS2 : 1; // Umschalten des ist erlaubt
78 sal_Bool bRTF_InTextRead : 1; // only for RTF-Parser!!!
80 struct TokenStackType
82 String sToken;
83 long nTokenValue;
84 sal_Bool bTokenHasValue;
85 int nTokenId;
87 inline TokenStackType() { nTokenId = 0; }
88 inline ~TokenStackType() { }
91 // Methoden fuer Token-Stack
92 int SkipToken( short nCnt = -1 ); // n Tokens zurueck "skippen"
93 TokenStackType* GetStackPtr( short nCnt );
94 inline sal_uInt8 GetStackPos() const;
96 // scanne das naechste Token:
97 // Tokenstack abarbeiten und ggfs. _GetNextToken() rufen. Diese
98 // ist fuers erkennen von neuen Token verantwortlich
99 int GetNextToken();
100 virtual int _GetNextToken() = 0;
102 // wird fuer jedes Token gerufen, das in CallParser erkannt wird
103 virtual void NextToken( int nToken );
105 // zu Zeiten der SvRefBase-Ableitung darf nicht jeder loeschen
106 virtual ~SvParser();
108 void ClearTxtConvContext();
110 private:
111 TokenStackType* pTokenStack;
112 TokenStackType *pTokenStackPos;
113 sal_uInt8 nTokenStackSize, nTokenStackPos;
115 public:
116 // Konstruktor
117 SvParser( SvStream& rIn, sal_uInt8 nStackSize = 3 );
119 virtual SvParserState CallParser() = 0; // Aufruf des Parsers
121 inline SvParserState GetStatus() const { return eState; } // StatusInfo
123 inline sal_uLong GetLineNr() const { return nlLineNr; }
124 inline sal_uLong GetLinePos() const { return nlLinePos; }
125 inline sal_uLong IncLineNr() { return ++nlLineNr; }
126 inline sal_uLong IncLinePos() { return ++nlLinePos; }
127 inline sal_uLong SetLineNr( sal_uLong nlNum ); // inline unten
128 inline sal_uLong SetLinePos( sal_uLong nlPos ); // inline unten
130 sal_Unicode GetNextChar();
131 void RereadLookahead();
133 inline int IsParserWorking() const { return SVPAR_WORKING == eState; }
135 Link GetAsynchCallLink() const
136 { return STATIC_LINK( this, SvParser, NewDataRead ); }
138 long CallAsyncCallLink() { return NewDataRead( this, 0 ); }
140 // fuers asynchrone lesen aus dem SvStream
141 /*virtual*/ void SaveState( int nToken );
142 /*virtual*/ void RestoreState();
143 virtual void Continue( int nToken );
145 inline void SetDownloadingFile( sal_Bool bSet ) { bDownloadingFile = bSet; }
146 inline sal_Bool IsDownloadingFile() const { return bDownloadingFile; }
148 // Set/get source encoding. The UCS2BEncoding flag is valid if source
149 // encoding is UCS2. It specifies a big endian encoding.
150 void SetSrcEncoding( rtl_TextEncoding eSrcEnc );
151 rtl_TextEncoding GetSrcEncoding() const { return eSrcEnc; }
153 void SetSrcUCS2BEncoding( sal_Bool bSet ) { bUCS2BSrcEnc = bSet; }
154 sal_Bool IsSrcUCS2BEncoding() const { return bUCS2BSrcEnc; }
156 // Darf der Zeichensatz auf UCS/2 umgeschaltet werden, wenn
157 // in den ersten beiden Zeichen im Stream eine BOM steht?
158 void SetSwitchToUCS2( sal_Bool bSet ) { bSwitchToUCS2 = bSet; }
159 sal_Bool IsSwitchToUCS2() const { return bSwitchToUCS2; }
161 // Aus wie vielen Bytes betseht ein Zeichen
162 inline sal_uInt16 GetCharSize() const;
164 int GetSaveToken() const;
166 // Aufbau einer Which-Map 'rWhichMap' aus einem Array von
167 // 'pWhichIds' von Which-Ids. Es hat die Lange 'nWhichIds'.
168 // Die Which-Map wird nicht geloescht.
169 static void BuildWhichTbl( std::vector<sal_uInt16> &rWhichMap,
170 sal_uInt16 *pWhichIds,
171 sal_uInt16 nWhichIds );
175 #ifndef GOODIES_DECL_SVPARSER_DEFINED
176 #define GOODIES_DECL_SVPARSER_DEFINED
177 SV_DECL_REF(SvParser)
178 #endif
179 SV_IMPL_REF(SvParser)
183 inline sal_uLong SvParser::SetLineNr( sal_uLong nlNum )
184 { sal_uLong nlOld = nlLineNr; nlLineNr = nlNum; return nlOld; }
186 inline sal_uLong SvParser::SetLinePos( sal_uLong nlPos )
187 { sal_uLong nlOld = nlLinePos; nlLinePos = nlPos; return nlOld; }
189 inline sal_uInt8 SvParser::GetStackPos() const
190 { return nTokenStackPos; }
192 inline sal_uInt16 SvParser::GetCharSize() const
194 return (RTL_TEXTENCODING_UCS2 == eSrcEnc) ? 2 : 1;
198 /*========================================================================
200 * SvKeyValue.
202 *======================================================================*/
204 SV_DECL_REF(SvKeyValueIterator)
206 class SvKeyValue
208 /** Representation.
210 String m_aKey;
211 String m_aValue;
213 public:
214 /** Construction.
216 SvKeyValue (void)
219 SvKeyValue (const String &rKey, const String &rValue)
220 : m_aKey (rKey), m_aValue (rValue)
223 SvKeyValue (const SvKeyValue &rOther)
224 : m_aKey (rOther.m_aKey), m_aValue (rOther.m_aValue)
227 /** Assignment.
229 SvKeyValue& operator= (SvKeyValue &rOther)
231 m_aKey = rOther.m_aKey;
232 m_aValue = rOther.m_aValue;
233 return *this;
236 /** Operation.
238 const String& GetKey (void) const { return m_aKey; }
239 const String& GetValue (void) const { return m_aValue; }
241 void SetKey (const String &rKey ) { m_aKey = rKey; }
242 void SetValue (const String &rValue) { m_aValue = rValue; }
245 /*========================================================================
247 * SvKeyValueIterator.
249 *======================================================================*/
251 typedef boost::ptr_vector<SvKeyValue> SvKeyValueList_Impl;
253 class SVT_DLLPUBLIC SvKeyValueIterator : public SvRefBase,
254 private boost::noncopyable
256 /** Representation.
258 SvKeyValueList_Impl* m_pList;
259 sal_uInt16 m_nPos;
261 public:
262 /** Construction/Destruction.
264 SvKeyValueIterator (void);
265 virtual ~SvKeyValueIterator (void);
267 /** Operation.
269 virtual sal_Bool GetFirst (SvKeyValue &rKeyVal);
270 virtual sal_Bool GetNext (SvKeyValue &rKeyVal);
271 virtual void Append (const SvKeyValue &rKeyVal);
274 SV_IMPL_REF(SvKeyValueIterator);
276 #endif //_SVPARSER_HXX
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */