Update ooo320-m1
[ooovba.git] / soltools / inc / gi_parse.hxx
bloba28cb4fa3716b3917e0549d5ec71034c64b91efa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gi_parse.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef SOLTOOLS_GI_PARSE_HXX
31 #define SOLTOOLS_GI_PARSE_HXX
33 #include "simstr.hxx"
34 #include "gilacces.hxx"
35 #include <fstream>
37 class GenericInfoList_Builder;
38 class GenericInfoList_Browser;
40 /** Reads generic information files into a simple structure in memory.
42 Information files used by this parser have the following format:
44 key [value]
46 key [value]
47 key [value]
49 key [value]
50 ...
51 ...
54 key [value]
55 ...
56 ...
61 class GenericInfo_Parser : public GenericInfoParseTypes
63 public:
64 typedef unsigned long UINT32;
65 typedef short INT16;
67 GenericInfo_Parser();
68 ~GenericInfo_Parser();
70 /** reads a information file and stores the data in a
71 List_GenericInfo
73 bool LoadList(
74 GenericInfoList_Builder &
75 o_rResult,
76 const Simstr & i_sSourceFileName );
78 /** save the InformationList to rSourceFile
79 returns false on error
81 bool SaveList(
82 const Simstr & i_rOutputFile,
83 GenericInfoList_Browser &
84 io_rListBrowser );
86 E_Error GetLastError(
87 UINT32 * o_pErrorLine = 0 ) const;
89 private:
90 enum E_LineType
92 lt_empty = 0,
93 lt_key,
94 lt_open_list,
95 lt_close_list,
96 lt_comment
99 void SetError(
100 E_Error i_eError );
101 void ResetState(
102 GenericInfoList_Builder &
103 io_rResult );
104 void ResetState(
105 GenericInfoList_Browser &
106 io_rSrc );
108 void ReadLine();
109 bool InterpretLine();
110 E_LineType ClassifyLine();
112 void ReadKey();
113 void PushLevel_Read(); /// When list is opened by '{':
114 void PopLevel_Read(); /// When list is closed by '}':
115 void AddCurLine2CurComment();
117 void WriteList(
118 std::ostream & o_rFile );
120 void PushLevel_Write(); /// When SubList is pushed in pResource
121 void PopLevel_Write(); /// When SubList is popped in pResource
123 void WriteComment(
124 std::ostream & o_rFile,
125 const char * i_sStr );
126 void WriteKey(
127 std::ostream & o_rFile,
128 const char * i_sStr );
129 void WriteValue(
130 std::ostream & o_rFile,
131 const char * i_sStr );
132 void WriteIndentation(
133 std::ostream & o_rFile );
135 // DATA
136 const char * sCurParsePosition;
138 UINT32 nCurLine;
139 INT16 nLevel;
140 bool bGoon;
142 Simstr sCurComment;
144 E_Error eErrorCode;
145 UINT32 nErrorLine;
147 GenericInfoList_Builder *
148 pResult;
149 GenericInfoList_Browser *
150 pResource;
152 char * dpBuffer;
153 char * sFilePtr;
157 inline GenericInfo_Parser::E_Error
158 GenericInfo_Parser::GetLastError( UINT32 * o_pErrorLine ) const
160 if ( o_pErrorLine != 0 )
161 *o_pErrorLine = nErrorLine;
162 return eErrorCode;
166 #endif