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 <tokens/stmstarr.hxx>
24 
25 
26 // NOT FULLY DECLARED SERVICES
27 #include <x_parse.hxx>
28 
29 
30 
StmArrayStatus(intt i_nStatusSize,const INT16 * in_aArrayModel,F_CRTOK i_fTokenCreateFunction,bool in_bIsDefault)31 StmArrayStatus::StmArrayStatus( intt			i_nStatusSize,
32 								const INT16 * 	in_aArrayModel,
33 								F_CRTOK			i_fTokenCreateFunction,
34 							    bool			in_bIsDefault )
35 	:	dpBranches(new StmStatus::Branch[i_nStatusSize]),
36 		nNrOfBranches(i_nStatusSize),
37 		fTokenCreateFunction(i_fTokenCreateFunction),
38 		bIsADefault(in_bIsDefault)
39 {
40 	if (in_aArrayModel != 0)
41 	{
42 		intt count = 0;
43 		for (const INT16 * get = in_aArrayModel; count < nNrOfBranches; count++, get++)
44 			dpBranches[count] = *get;
45 	}
46 	else //
47 	{
48 		memset(dpBranches, 0, nNrOfBranches);
49 	}  // endif
50 }
51 
~StmArrayStatus()52 StmArrayStatus::~StmArrayStatus()
53 {
54 	delete [] dpBranches;
55 }
56 
57 bool
SetBranch(intt in_nBranchIx,StmStatus::Branch in_nBranch)58 StmArrayStatus::SetBranch( intt    		 	 in_nBranchIx,
59 						   StmStatus::Branch in_nBranch )
60 {
61 	if ( csv::in_range(intt(0), in_nBranchIx, intt(nNrOfBranches) ) )
62 	{
63 		dpBranches[in_nBranchIx] = in_nBranch;
64 		return true;
65 	}
66 	return false;
67 }
68 
69 
70 StmStatus::Branch
NextBy(intt in_nIndex) const71 StmArrayStatus::NextBy(intt in_nIndex) const
72 {
73 	if (in_nIndex < 0)
74 		throw X_Parser(X_Parser::x_InvalidChar, "", String::Null_(), 0);
75 
76 	return in_nIndex < nNrOfBranches
77 				?	dpBranches[in_nIndex]
78 				:   dpBranches[nNrOfBranches - 1];
79 }
80 
81 
82 bool
IsADefault() const83 StmArrayStatus::IsADefault() const
84 {
85 	return bIsADefault;
86 }
87 
88 StmArrayStatus *
AsArray()89 StmArrayStatus::AsArray()
90 {
91 	return this;
92 }
93 
94