xref: /trunk/main/autodoc/source/parser_i/idl/pe_enum2.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include <s2_luidl/pe_enum2.hxx>
30 
31 
32 // NOT FULLY DECLARED SERVICES
33 #include <ary/idl/i_enum.hxx>
34 #include <ary/idl/i_enumvalue.hxx>
35 #include <ary/idl/i_gate.hxx>
36 #include <ary/idl/ip_ce.hxx>
37 #include <ary/doc/d_oldidldocu.hxx>
38 #include <s2_luidl/pe_evalu.hxx>
39 #include <s2_luidl/tk_punct.hxx>
40 #include <s2_luidl/tk_ident.hxx>
41 #include <s2_luidl/tk_keyw.hxx>
42 
43 
44 namespace csi
45 {
46 namespace uidl
47 {
48 
49 
50 #ifdef DF
51 #undef DF
52 #endif
53 #define DF  &PE_Enum::On_Default
54 
55 PE_Enum::F_TOK
56 PE_Enum::aDispatcher[PE_Enum::e_STATES_MAX][PE_Enum::tt_MAX] =
57         {   {  DF, DF },  // e_none
58             {  &PE_Enum::On_expect_name_Identifier,
59                    DF },  // expect_name
60             {  DF, &PE_Enum::On_expect_curl_bracket_open_Punctuation },  // expect_curl_bracket_open
61             {  &PE_Enum::On_expect_value_Identifier,
62                    &PE_Enum::On_expect_value_Punctuation },  // expect_value
63             {  DF, &PE_Enum::On_expect_finish_Punctuation }  // expect_finish
64         };
65 
66 
67 
68 inline void
69 PE_Enum::CallHandler( const char *      i_sTokenText,
70                           E_TokenType       i_eTokenType )
71     { (this->*aDispatcher[eState][i_eTokenType])(i_sTokenText); }
72 
73 
74 
75 
76 PE_Enum::PE_Enum()
77     :   eState(e_none),
78         sData_Name(),
79         nDataId(0),
80         pPE_Value(0),
81         sName(),
82         sAssignment()
83 {
84     pPE_Value = new PE_Value(sName, sAssignment, false);
85 }
86 
87 void
88 PE_Enum::EstablishContacts( UnoIDL_PE *                 io_pParentPE,
89                             ary::Repository &       io_rRepository,
90                             TokenProcessing_Result &    o_rResult )
91 {
92     UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
93     pPE_Value->EstablishContacts(this,io_rRepository,o_rResult);
94 }
95 
96 PE_Enum::~PE_Enum()
97 {
98 }
99 
100 void
101 PE_Enum::ProcessToken( const Token & i_rToken )
102 {
103     i_rToken.Trigger(*this);
104 }
105 
106 void
107 PE_Enum::Process_Identifier( const TokIdentifier & i_rToken )
108 {
109     CallHandler(i_rToken.Text(), tt_identifier);
110 }
111 
112 void
113 PE_Enum::Process_Punctuation( const TokPunctuation & i_rToken )
114 {
115     CallHandler(i_rToken.Text(), tt_punctuation);
116 }
117 
118 void
119 PE_Enum::On_expect_name_Identifier(const char * i_sText)
120 {
121     sName = i_sText;
122 
123     SetResult(done,stay);
124     eState = expect_curl_bracket_open;
125 }
126 
127 void
128 PE_Enum::On_expect_curl_bracket_open_Punctuation(const char * i_sText)
129 {
130     if ( i_sText[0] == '{')
131     {
132         sData_Name = sName;
133         ary::idl::Enum &
134             rCe = Gate().Ces().Store_Enum(CurNamespace().CeId(), sData_Name);
135         PassDocuAt(rCe);
136         nDataId = rCe.CeId();
137 
138         SetResult(done,stay);
139         eState = expect_value;
140     }
141     else
142     {
143         On_Default(i_sText);
144     }
145 }
146 
147 void
148 PE_Enum::On_expect_value_Punctuation(const char * i_sText)
149 {
150     if ( i_sText[0] == '}' )
151     {
152         SetResult(done,stay);
153         eState = expect_finish;
154     }
155     else
156     {
157         On_Default(i_sText);
158     }
159 }
160 
161 void
162 PE_Enum::On_expect_value_Identifier(const char *)
163 {
164     SetResult( not_done, push_sure, pPE_Value.Ptr() );
165 }
166 
167 void
168 PE_Enum::On_expect_finish_Punctuation(const char * i_sText)
169 {
170     if ( i_sText[0] == ';')
171     {
172         SetResult(done,pop_success);
173         eState = e_none;
174     }
175     else
176     {
177         On_Default(i_sText);
178     }
179 }
180 
181 void
182 PE_Enum::On_Default(const char * )
183 {
184     SetResult(not_done,pop_failure);
185     eState = e_none;
186 }
187 
188 void
189 PE_Enum::EmptySingleValueData()
190 {
191     sName = "";
192     sAssignment = "";
193 }
194 
195 void
196 PE_Enum::CreateSingleValue()
197 {
198     ary::idl::EnumValue &
199         rCe = Gate().Ces().Store_EnumValue( nDataId, sName, sAssignment );
200     pPE_Value->PassDocuAt(rCe);
201 }
202 
203 void
204 PE_Enum::InitData()
205 {
206     eState = expect_name;
207 
208     sData_Name.clear();
209     nDataId = 0;
210 
211     EmptySingleValueData();
212 }
213 
214 void
215 PE_Enum::ReceiveData()
216 {
217     switch (eState)
218     {
219         case expect_value:
220         {
221                     if (sName.length() == 0)
222                     {
223                         On_Default("");
224                         break;
225                     }
226 
227                     CreateSingleValue();
228                     EmptySingleValueData();
229         }           break;
230         default:
231                     SetResult(not_done, pop_failure);
232                     eState = e_none;
233     }   // end switch
234 }
235 
236 void
237 PE_Enum::TransferData()
238 {
239     csv_assert(sData_Name.length() > 0);
240     eState = e_none;
241 }
242 
243 UnoIDL_PE &
244 PE_Enum::MyPE()
245 {
246     return *this;
247 }
248 
249 }   // namespace uidl
250 }   // namespace csi
251 
252