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 
24 #ifndef ADC_CPP_SUB_PE_HXX
25 #define ADC_CPP_SUB_PE_HXX
26 
27 
28 
29 // USED SERVICES
30 	// BASE CLASSES
31 	// COMPONENTS
32 	// PARAMETERS
33 
34 
35 class ParseEnvironment;
36 
37 template <class PE, class SUB>
38 class SubPe
39 {
40   public:
41 	typedef SubPe< PE, SUB > 	self;
42 
43 						SubPe(
44 							PE &				i_rParent );
45 	PE &				Parent() const;
46 	SUB &				Child() const;
47 
48 	ParseEnvironment &	Get() const;
49 
50   private:
51 	SUB &				CreateChild() const;
52 
53 	PE &				rParent;
54 	Dyn<SUB>			pChild;
55 };
56 
57 
58 
59 // IMPLEMENTATION
60 
61 
62 // 	SubPe
63 
64 template <class PE, class SUB>
SubPe(PE & i_rParent)65 SubPe<PE,SUB>::SubPe( PE & i_rParent )
66 	:	rParent(i_rParent)
67 {
68 }
69 
70 template <class PE, class SUB>
71 PE &
Parent() const72 SubPe<PE,SUB>::Parent() const
73 {
74  	return rParent;
75 }
76 
77 template <class PE, class SUB>
78 inline SUB &
Child() const79 SubPe<PE,SUB>::Child() const
80 {
81 	return pChild ? *pChild.MutablePtr() : CreateChild();
82 }
83 
84 template <class PE, class SUB>
85 ParseEnvironment &
Get() const86 SubPe<PE,SUB>::Get() const
87 {
88 	return Child();
89 }
90 
91 template <class PE, class SUB>
92 SUB &
CreateChild() const93 SubPe<PE,SUB>::CreateChild() const
94 {
95     self * pThis = const_cast< self* >(this);
96 
97     SUB * pNewChild = new SUB( &rParent);
98 
99 	pThis->pChild = pNewChild;
100 
101 	return *pChild.MutablePtr();
102 }
103 
104 
105 
106 
107 #endif
108 
109