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 _CODEMAKER_DEPENDENCY_HXX_
25 #define _CODEMAKER_DEPENDENCY_HXX_
26 
27 #include 	<hash_map>
28 #include	<registry/registry.hxx>
29 #ifndef __REGISTRY_REFLREAD_HXX__
30 #include	<registry/reflread.hxx>
31 #endif
32 #include	<codemaker/typemanager.hxx>
33 #include	<codemaker/global.hxx>
34 #include <osl/diagnose.h>
35 
36 #define	TYPEUSE_NORMAL		0x0001
37 #define	TYPEUSE_SUPER		0x0002
38 #define	TYPEUSE_MEMBER		0x0004
39 #define	TYPEUSE_INPARAM		0x0008
40 #define	TYPEUSE_OUTPARAM 	0x0010
41 #define	TYPEUSE_INOUTPARAM 	0x0020
42 #define	TYPEUSE_RETURN		0x0040
43 #define	TYPEUSE_EXCEPTION	0x0080
44 #define	TYPEUSE_SCOPE       0x0100
45 
46 /**
47  * Flag shows the state of the code generation. If the Flag is set
48  * the code for this type is generated.
49  */
50 #define	CODEGEN_DEFAULT		0x0001
51 
52 struct TypeUsing
53 {
TypeUsingTypeUsing54 	TypeUsing(const ::rtl::OString& type, sal_uInt16 use)
55 		: m_type(type)
56 		, m_use(use)
57 		{}
58 
59 	::rtl::OString 	m_type;
60 	sal_uInt16		m_use;
61 
operator ==TypeUsing62 	sal_Bool operator == (const TypeUsing & typeUsing) const
63 	{
64 		OSL_ASSERT(0);
65 		return m_type == typeUsing.m_type && m_use == typeUsing.m_use;
66 	}
67 };
68 
69 struct LessTypeUsing
70 {
operator ()LessTypeUsing71 	sal_Bool operator()(const TypeUsing& tuse1, const TypeUsing& tuse2) const
72 	{
73 		return (tuse1.m_type < tuse2.m_type);
74 	}
75 };
76 
77 typedef	::std::set< TypeUsing, LessTypeUsing > TypeUsingSet;
78 
79 
80 #if (defined( _MSC_VER ) && ( _MSC_VER < 1200 ))
81 typedef	::std::__hash_map__
82 <
83 	::rtl::OString,
84 	TypeUsingSet,
85 	HashString,
86 	EqualString,
87 	NewAlloc
88 > DependencyMap;
89 
90 typedef	::std::__hash_map__
91 <
92 	::rtl::OString,
93 	sal_uInt16,
94 	HashString,
95 	EqualString,
96 	NewAlloc
97 > GenerationMap;
98 #else
99 typedef	::std::hash_map
100 <
101 	::rtl::OString,
102 	TypeUsingSet,
103 	HashString,
104 	EqualString
105 > DependencyMap;
106 
107 typedef	::std::hash_map
108 <
109 	::rtl::OString,
110 	sal_uInt16,
111 	HashString,
112 	EqualString
113 > GenerationMap;
114 
115 #endif
116 
117 struct TypeDependencyImpl
118 {
TypeDependencyImplTypeDependencyImpl119 	TypeDependencyImpl()
120 		: m_refCount(0)
121 		{}
122 
123 	sal_Int32		m_refCount;
124 	DependencyMap	m_dependencies;
125 	GenerationMap	m_generatedTypes;
126 };
127 
128 class TypeDependency
129 {
130 public:
131 	TypeDependency();
132 	~TypeDependency();
133 
TypeDependency(const TypeDependency & value)134     TypeDependency( const TypeDependency& value )
135 		: m_pImpl( value.m_pImpl )
136 	{
137 		acquire();
138 	}
139 
operator =(const TypeDependency & value)140 	TypeDependency& operator = ( const TypeDependency& value )
141 	{
142 		release();
143 		m_pImpl = value.m_pImpl;
144 		acquire();
145 		return *this;
146 	}
147 
148 	sal_Bool 		insert(const ::rtl::OString& type, const ::rtl::OString& depend, sal_uInt16);
149 	TypeUsingSet	getDependencies(const ::rtl::OString& type);
150 	sal_Bool		hasDependencies(const ::rtl::OString& type);
151 
152 	void		setGenerated(const ::rtl::OString& type, sal_uInt16 genFlag=CODEGEN_DEFAULT);
153 	sal_Bool	isGenerated(const ::rtl::OString& type, sal_uInt16 genFlag=CODEGEN_DEFAULT);
154 
getSize()155 	sal_Int32 getSize() { return m_pImpl->m_generatedTypes.size(); }
156 protected:
157 	void acquire();
158 	void release();
159 
160 protected:
161 	TypeDependencyImpl*	m_pImpl;
162 };
163 
164 sal_Bool checkTypeDependencies(TypeManager& typeMgr, TypeDependency& dependencies, const ::rtl::OString& type, sal_Bool bDepend = sal_False);
165 
166 #endif // _CODEMAKER_DEPENDENCY_HXX_
167