xref: /aoo42x/main/soltools/inc/gi_parse.hxx (revision 38268e38)
1*38268e38SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38268e38SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38268e38SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38268e38SAndrew Rist  * distributed with this work for additional information
6*38268e38SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38268e38SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38268e38SAndrew Rist  * "License"); you may not use this file except in compliance
9*38268e38SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*38268e38SAndrew Rist  *
11*38268e38SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*38268e38SAndrew Rist  *
13*38268e38SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38268e38SAndrew Rist  * software distributed under the License is distributed on an
15*38268e38SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38268e38SAndrew Rist  * KIND, either express or implied.  See the License for the
17*38268e38SAndrew Rist  * specific language governing permissions and limitations
18*38268e38SAndrew Rist  * under the License.
19*38268e38SAndrew Rist  *
20*38268e38SAndrew Rist  *************************************************************/
21*38268e38SAndrew Rist 
22*38268e38SAndrew Rist 
23cdf0e10cSrcweir #ifndef SOLTOOLS_GI_PARSE_HXX
24cdf0e10cSrcweir #define SOLTOOLS_GI_PARSE_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "simstr.hxx"
27cdf0e10cSrcweir #include "gilacces.hxx"
28cdf0e10cSrcweir #include <fstream>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir class GenericInfoList_Builder;
31cdf0e10cSrcweir class GenericInfoList_Browser;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /** Reads generic information files into a simple structure in memory.
34cdf0e10cSrcweir 
35cdf0e10cSrcweir Information files used by this parser have the following format:
36cdf0e10cSrcweir 
37cdf0e10cSrcweir key [value]
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 	key [value]
40cdf0e10cSrcweir 	key [value]
41cdf0e10cSrcweir 	{
42cdf0e10cSrcweir 		key [value]
43cdf0e10cSrcweir 		...
44cdf0e10cSrcweir 		...
45cdf0e10cSrcweir 	}
46cdf0e10cSrcweir }
47cdf0e10cSrcweir key [value]
48cdf0e10cSrcweir ...
49cdf0e10cSrcweir ...
50cdf0e10cSrcweir 
51cdf0e10cSrcweir */
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir class GenericInfo_Parser : public GenericInfoParseTypes
55cdf0e10cSrcweir {
56cdf0e10cSrcweir   public:
57cdf0e10cSrcweir     typedef unsigned long   UINT32;
58cdf0e10cSrcweir     typedef short           INT16;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir                         GenericInfo_Parser();
61cdf0e10cSrcweir                         ~GenericInfo_Parser();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	/** reads a information file and stores the data in a
64cdf0e10cSrcweir         List_GenericInfo
65cdf0e10cSrcweir 	*/
66cdf0e10cSrcweir 	bool                LoadList(
67cdf0e10cSrcweir                             GenericInfoList_Builder &
68cdf0e10cSrcweir                                                 o_rResult,
69cdf0e10cSrcweir                             const Simstr &      i_sSourceFileName );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     /** save the InformationList to rSourceFile
72cdf0e10cSrcweir         returns false on error
73cdf0e10cSrcweir     */
74cdf0e10cSrcweir     bool                SaveList(
75cdf0e10cSrcweir                             const Simstr &      i_rOutputFile,
76cdf0e10cSrcweir 	                        GenericInfoList_Browser &
77cdf0e10cSrcweir                                                 io_rListBrowser );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	E_Error             GetLastError(
80cdf0e10cSrcweir                             UINT32 *            o_pErrorLine = 0 ) const;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir   private:
83cdf0e10cSrcweir     enum E_LineType
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         lt_empty = 0,
86cdf0e10cSrcweir         lt_key,
87cdf0e10cSrcweir         lt_open_list,
88cdf0e10cSrcweir         lt_close_list,
89cdf0e10cSrcweir         lt_comment
90cdf0e10cSrcweir     };
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     void                SetError(
93cdf0e10cSrcweir                             E_Error             i_eError );
94cdf0e10cSrcweir     void                ResetState(
95cdf0e10cSrcweir                             GenericInfoList_Builder &
96cdf0e10cSrcweir                                                 io_rResult );
97cdf0e10cSrcweir     void                ResetState(
98cdf0e10cSrcweir                             GenericInfoList_Browser &
99cdf0e10cSrcweir                                                 io_rSrc );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     void                ReadLine();
102cdf0e10cSrcweir     bool                InterpretLine();
103cdf0e10cSrcweir     E_LineType          ClassifyLine();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     void                ReadKey();
106cdf0e10cSrcweir     void                PushLevel_Read();           /// When list is opened by '{':
107cdf0e10cSrcweir     void                PopLevel_Read();            /// When list is closed by '}':
108cdf0e10cSrcweir     void                AddCurLine2CurComment();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     void                WriteList(
111cdf0e10cSrcweir                             std::ostream &      o_rFile );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     void                PushLevel_Write();          /// When SubList is pushed in pResource
114cdf0e10cSrcweir     void                PopLevel_Write();           /// When SubList is popped in pResource
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     void                WriteComment(
117cdf0e10cSrcweir                             std::ostream &      o_rFile,
118cdf0e10cSrcweir                             const char *        i_sStr );
119cdf0e10cSrcweir     void                WriteKey(
120cdf0e10cSrcweir                             std::ostream &      o_rFile,
121cdf0e10cSrcweir                             const char *        i_sStr );
122cdf0e10cSrcweir     void                WriteValue(
123cdf0e10cSrcweir                             std::ostream &      o_rFile,
124cdf0e10cSrcweir                             const char *        i_sStr );
125cdf0e10cSrcweir     void                WriteIndentation(
126cdf0e10cSrcweir                             std::ostream &      o_rFile );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     // DATA
129cdf0e10cSrcweir     const char *        sCurParsePosition;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     UINT32              nCurLine;
132cdf0e10cSrcweir     INT16               nLevel;
133cdf0e10cSrcweir     bool                bGoon;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     Simstr              sCurComment;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	E_Error             eErrorCode;
138cdf0e10cSrcweir 	UINT32              nErrorLine;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     GenericInfoList_Builder *
141cdf0e10cSrcweir                         pResult;
142cdf0e10cSrcweir     GenericInfoList_Browser *
143cdf0e10cSrcweir                         pResource;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     char *              dpBuffer;
146cdf0e10cSrcweir     char *              sFilePtr;
147cdf0e10cSrcweir };
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 
150cdf0e10cSrcweir inline GenericInfo_Parser::E_Error
GetLastError(UINT32 * o_pErrorLine) const151cdf0e10cSrcweir GenericInfo_Parser::GetLastError( UINT32 * o_pErrorLine ) const
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     if ( o_pErrorLine != 0 )
154cdf0e10cSrcweir         *o_pErrorLine = nErrorLine;
155cdf0e10cSrcweir     return eErrorCode;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
159cdf0e10cSrcweir #endif
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
162