xref: /aoo41x/main/soltools/inc/gi_parse.hxx (revision 38268e38)
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 #ifndef SOLTOOLS_GI_PARSE_HXX
24 #define SOLTOOLS_GI_PARSE_HXX
25 
26 #include "simstr.hxx"
27 #include "gilacces.hxx"
28 #include <fstream>
29 
30 class GenericInfoList_Builder;
31 class GenericInfoList_Browser;
32 
33 /** Reads generic information files into a simple structure in memory.
34 
35 Information files used by this parser have the following format:
36 
37 key [value]
38 {
39 	key [value]
40 	key [value]
41 	{
42 		key [value]
43 		...
44 		...
45 	}
46 }
47 key [value]
48 ...
49 ...
50 
51 */
52 
53 
54 class GenericInfo_Parser : public GenericInfoParseTypes
55 {
56   public:
57     typedef unsigned long   UINT32;
58     typedef short           INT16;
59 
60                         GenericInfo_Parser();
61                         ~GenericInfo_Parser();
62 
63 	/** reads a information file and stores the data in a
64         List_GenericInfo
65 	*/
66 	bool                LoadList(
67                             GenericInfoList_Builder &
68                                                 o_rResult,
69                             const Simstr &      i_sSourceFileName );
70 
71     /** save the InformationList to rSourceFile
72         returns false on error
73     */
74     bool                SaveList(
75                             const Simstr &      i_rOutputFile,
76 	                        GenericInfoList_Browser &
77                                                 io_rListBrowser );
78 
79 	E_Error             GetLastError(
80                             UINT32 *            o_pErrorLine = 0 ) const;
81 
82   private:
83     enum E_LineType
84     {
85         lt_empty = 0,
86         lt_key,
87         lt_open_list,
88         lt_close_list,
89         lt_comment
90     };
91 
92     void                SetError(
93                             E_Error             i_eError );
94     void                ResetState(
95                             GenericInfoList_Builder &
96                                                 io_rResult );
97     void                ResetState(
98                             GenericInfoList_Browser &
99                                                 io_rSrc );
100 
101     void                ReadLine();
102     bool                InterpretLine();
103     E_LineType          ClassifyLine();
104 
105     void                ReadKey();
106     void                PushLevel_Read();           /// When list is opened by '{':
107     void                PopLevel_Read();            /// When list is closed by '}':
108     void                AddCurLine2CurComment();
109 
110     void                WriteList(
111                             std::ostream &      o_rFile );
112 
113     void                PushLevel_Write();          /// When SubList is pushed in pResource
114     void                PopLevel_Write();           /// When SubList is popped in pResource
115 
116     void                WriteComment(
117                             std::ostream &      o_rFile,
118                             const char *        i_sStr );
119     void                WriteKey(
120                             std::ostream &      o_rFile,
121                             const char *        i_sStr );
122     void                WriteValue(
123                             std::ostream &      o_rFile,
124                             const char *        i_sStr );
125     void                WriteIndentation(
126                             std::ostream &      o_rFile );
127 
128     // DATA
129     const char *        sCurParsePosition;
130 
131     UINT32              nCurLine;
132     INT16               nLevel;
133     bool                bGoon;
134 
135     Simstr              sCurComment;
136 
137 	E_Error             eErrorCode;
138 	UINT32              nErrorLine;
139 
140     GenericInfoList_Builder *
141                         pResult;
142     GenericInfoList_Browser *
143                         pResource;
144 
145     char *              dpBuffer;
146     char *              sFilePtr;
147 };
148 
149 
150 inline GenericInfo_Parser::E_Error
GetLastError(UINT32 * o_pErrorLine) const151 GenericInfo_Parser::GetLastError( UINT32 * o_pErrorLine ) const
152 {
153     if ( o_pErrorLine != 0 )
154         *o_pErrorLine = nErrorLine;
155     return eErrorCode;
156 }
157 
158 
159 #endif
160 
161 
162