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 #include <precomp.h>
23 #include <s2_luidl/pe_enum2.hxx>
24 
25 
26 // NOT FULLY DECLARED SERVICES
27 #include <ary/idl/i_enum.hxx>
28 #include <ary/idl/i_enumvalue.hxx>
29 #include <ary/idl/i_gate.hxx>
30 #include <ary/idl/ip_ce.hxx>
31 #include <ary/doc/d_oldidldocu.hxx>
32 #include <s2_luidl/pe_evalu.hxx>
33 #include <s2_luidl/tk_punct.hxx>
34 #include <s2_luidl/tk_ident.hxx>
35 #include <s2_luidl/tk_keyw.hxx>
36 
37 
38 namespace csi
39 {
40 namespace uidl
41 {
42 
43 
44 #ifdef DF
45 #undef DF
46 #endif
47 #define DF 	&PE_Enum::On_Default
48 
49 PE_Enum::F_TOK
50 PE_Enum::aDispatcher[PE_Enum::e_STATES_MAX][PE_Enum::tt_MAX] =
51 		{ 	{  DF, DF },  // e_none
52 			{  &PE_Enum::On_expect_name_Identifier,
53 				   DF },  // expect_name
54 			{  DF, &PE_Enum::On_expect_curl_bracket_open_Punctuation },  // expect_curl_bracket_open
55 			{  &PE_Enum::On_expect_value_Identifier,
56 				   &PE_Enum::On_expect_value_Punctuation },  // expect_value
57 			{  DF, &PE_Enum::On_expect_finish_Punctuation }  // expect_finish
58 		};
59 
60 
61 
62 inline void
CallHandler(const char * i_sTokenText,E_TokenType i_eTokenType)63 PE_Enum::CallHandler( const char *		i_sTokenText,
64 						  E_TokenType		i_eTokenType )
65 	{ (this->*aDispatcher[eState][i_eTokenType])(i_sTokenText); }
66 
67 
68 
69 
PE_Enum()70 PE_Enum::PE_Enum()
71 	:	eState(e_none),
72 		sData_Name(),
73         nDataId(0),
74 		pPE_Value(0),
75 		sName(),
76 		sAssignment()
77 {
78 	pPE_Value = new PE_Value(sName, sAssignment, false);
79 }
80 
81 void
EstablishContacts(UnoIDL_PE * io_pParentPE,ary::Repository & io_rRepository,TokenProcessing_Result & o_rResult)82 PE_Enum::EstablishContacts( UnoIDL_PE *					io_pParentPE,
83                             ary::Repository &		io_rRepository,
84                             TokenProcessing_Result & 	o_rResult )
85 {
86 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
87 	pPE_Value->EstablishContacts(this,io_rRepository,o_rResult);
88 }
89 
~PE_Enum()90 PE_Enum::~PE_Enum()
91 {
92 }
93 
94 void
ProcessToken(const Token & i_rToken)95 PE_Enum::ProcessToken( const Token & i_rToken )
96 {
97 	i_rToken.Trigger(*this);
98 }
99 
100 void
Process_Identifier(const TokIdentifier & i_rToken)101 PE_Enum::Process_Identifier( const TokIdentifier & i_rToken )
102 {
103 	CallHandler(i_rToken.Text(), tt_identifier);
104 }
105 
106 void
Process_Punctuation(const TokPunctuation & i_rToken)107 PE_Enum::Process_Punctuation( const TokPunctuation & i_rToken )
108 {
109 	CallHandler(i_rToken.Text(), tt_punctuation);
110 }
111 
112 void
On_expect_name_Identifier(const char * i_sText)113 PE_Enum::On_expect_name_Identifier(const char * i_sText)
114 {
115 	sName = i_sText;
116 
117 	SetResult(done,stay);
118 	eState = expect_curl_bracket_open;
119 }
120 
121 void
On_expect_curl_bracket_open_Punctuation(const char * i_sText)122 PE_Enum::On_expect_curl_bracket_open_Punctuation(const char * i_sText)
123 {
124 	if ( i_sText[0] == '{')
125 	{
126 		sData_Name = sName;
127     	ary::idl::Enum &
128             rCe = Gate().Ces().Store_Enum(CurNamespace().CeId(), sData_Name);
129 		PassDocuAt(rCe);
130         nDataId = rCe.CeId();
131 
132 		SetResult(done,stay);
133 		eState = expect_value;
134 	}
135 	else
136 	{
137 		On_Default(i_sText);
138 	}
139 }
140 
141 void
On_expect_value_Punctuation(const char * i_sText)142 PE_Enum::On_expect_value_Punctuation(const char * i_sText)
143 {
144 	if ( i_sText[0] == '}' )
145 	{
146 		SetResult(done,stay);
147 		eState = expect_finish;
148 	}
149 	else
150 	{
151 		On_Default(i_sText);
152 	}
153 }
154 
155 void
On_expect_value_Identifier(const char *)156 PE_Enum::On_expect_value_Identifier(const char *)
157 {
158 	SetResult( not_done, push_sure, pPE_Value.Ptr() );
159 }
160 
161 void
On_expect_finish_Punctuation(const char * i_sText)162 PE_Enum::On_expect_finish_Punctuation(const char * i_sText)
163 {
164 	if ( i_sText[0] == ';')
165 	{
166 		SetResult(done,pop_success);
167 		eState = e_none;
168 	}
169 	else
170 	{
171 		On_Default(i_sText);
172 	}
173 }
174 
175 void
On_Default(const char *)176 PE_Enum::On_Default(const char * )
177 {
178 	SetResult(not_done,pop_failure);
179 	eState = e_none;
180 }
181 
182 void
EmptySingleValueData()183 PE_Enum::EmptySingleValueData()
184 {
185 	sName = "";
186 	sAssignment = "";
187 }
188 
189 void
CreateSingleValue()190 PE_Enum::CreateSingleValue()
191 {
192 	ary::idl::EnumValue &
193         rCe = Gate().Ces().Store_EnumValue( nDataId, sName, sAssignment );
194 	pPE_Value->PassDocuAt(rCe);
195 }
196 
197 void
InitData()198 PE_Enum::InitData()
199 {
200 	eState = expect_name;
201 
202 	sData_Name.clear();
203 	nDataId = 0;
204 
205 	EmptySingleValueData();
206 }
207 
208 void
ReceiveData()209 PE_Enum::ReceiveData()
210 {
211 	switch (eState)
212 	{
213 		case expect_value:
214 		{
215 					if (sName.length() == 0)
216 					{
217 						On_Default("");
218 						break;
219 					}
220 
221 					CreateSingleValue();
222 					EmptySingleValueData();
223 		}			break;
224 		default:
225 					SetResult(not_done, pop_failure);
226 					eState = e_none;
227 	}	// end switch
228 }
229 
230 void
TransferData()231 PE_Enum::TransferData()
232 {
233 	csv_assert(sData_Name.length() > 0);
234 	eState = e_none;
235 }
236 
237 UnoIDL_PE &
MyPE()238 PE_Enum::MyPE()
239 {
240 	return *this;
241 }
242 
243 }   // namespace uidl
244 }   // namespace csi
245 
246