xref: /AOO42X/main/codemaker/inc/codemaker/typemanager.hxx (revision 9bce9b0d387299c68bd81d539e1478357a103de5)
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 INCLUDED_CODEMAKER_TYPEMANAGER_HXX
25 #define INCLUDED_CODEMAKER_TYPEMANAGER_HXX
26 
27 #include "codemaker/global.hxx"
28 #include "registry/registry.hxx"
29 #include "registry/types.h"
30 
31 #include <hash_map>
32 #include <list>
33 
34 namespace typereg { class Reader; }
35 
36 //typedef ::std::list< Registry* >  RegistryList;
37 typedef ::std::vector< Registry* >  RegistryList;
38 typedef ::std::pair< RegistryKey, sal_Bool >    KeyPair;
39 typedef ::std::vector< KeyPair >    RegistryKeyList;
40 
41 #if defined( _MSC_VER ) && ( _MSC_VER < 1200 )
42 typedef ::std::__hash_map__
43 <
44     ::rtl::OString, // Typename
45     RTTypeClass,    // TypeClass
46     HashString,
47     EqualString,
48     NewAlloc
49 > T2TypeClassMap;
50 #else
51 typedef ::std::hash_map
52 <
53     ::rtl::OString, // Typename
54     RTTypeClass,    // TypeClass
55     HashString,
56     EqualString
57 > T2TypeClassMap;
58 #endif
59 
60 struct TypeManagerImpl
61 {
TypeManagerImplTypeManagerImpl62     TypeManagerImpl()
63         : m_refCount(0)
64         {}
65 
66     sal_Int32       m_refCount;
67 };
68 
69 class TypeManager
70 {
71 public:
72     TypeManager();
73     virtual ~TypeManager();
74 
TypeManager(const TypeManager & value)75     TypeManager( const TypeManager& value )
76         : m_pImpl( value.m_pImpl )
77     {
78         acquire();
79     }
80 
operator =(const TypeManager & value)81     TypeManager& operator = ( const TypeManager& value )
82     {
83         release();
84         m_pImpl = value.m_pImpl;
85         acquire();
86         return *this;
87     }
88 
isValidType(const::rtl::OString &) const89     virtual sal_Bool isValidType(const ::rtl::OString&) const
90         { return sal_False; }
91 
getTypeName(RegistryKey &) const92     virtual ::rtl::OString getTypeName(RegistryKey&) const
93         { return ::rtl::OString(); }
94 
getTypeKey(const::rtl::OString &,sal_Bool * =0) const95     virtual RegistryKey getTypeKey(const ::rtl::OString&, sal_Bool * = 0 ) const
96         { return RegistryKey(); }
getTypeKeys(const::rtl::OString &) const97     virtual RegistryKeyList getTypeKeys(const ::rtl::OString&) const
98         { return RegistryKeyList(); }
99     virtual typereg::Reader getTypeReader(
100         const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const = 0;
101     virtual typereg::Reader getTypeReader(RegistryKey& rTypeKey) const = 0;
getTypeClass(const::rtl::OString &) const102     virtual RTTypeClass getTypeClass(const ::rtl::OString&) const
103         { return RT_TYPE_INVALID; }
getTypeClass(RegistryKey &) const104     virtual RTTypeClass getTypeClass(RegistryKey&) const
105         { return RT_TYPE_INVALID; }
106 
setBase(const::rtl::OString &)107     virtual void setBase(const ::rtl::OString&) {}
getBase() const108     virtual ::rtl::OString getBase() const { return ::rtl::OString(); }
109 
getSize() const110     virtual sal_Int32 getSize() const { return 0; }
111 
112     static sal_Bool isBaseType(const ::rtl::OString& name);
113 protected:
114     sal_Int32 acquire();
115     sal_Int32 release();
116 
117 protected:
118     TypeManagerImpl* m_pImpl;
119 };
120 
121 struct RegistryTypeManagerImpl
122 {
RegistryTypeManagerImplRegistryTypeManagerImpl123     RegistryTypeManagerImpl()
124         : m_base("/")
125         {}
126 
127     T2TypeClassMap  m_t2TypeClass;
128     RegistryList    m_registries;
129     RegistryList    m_extra_registries;
130     ::rtl::OString  m_base;
131 };
132 
133 class RegistryTypeManager : public TypeManager
134 {
135 public:
136     RegistryTypeManager();
137     virtual ~RegistryTypeManager();
138 
RegistryTypeManager(const RegistryTypeManager & value)139     RegistryTypeManager( const RegistryTypeManager& value )
140         : TypeManager(value)
141         , m_pImpl( value.m_pImpl )
142     {
143         acquire();
144     }
145 
146     sal_Bool init(const StringVector& regFiles, const StringVector& extraFiles = StringVector() );
147 
148     ::rtl::OString getTypeName(RegistryKey& rTypeKey) const;
149 
isValidType(const::rtl::OString & name) const150     sal_Bool    isValidType(const ::rtl::OString& name) const
151         { return searchTypeKey(name, 0).isValid(); }
getTypeKey(const::rtl::OString & name,sal_Bool * pIsExtraType=0) const152     RegistryKey getTypeKey(
153         const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const
154         { return searchTypeKey(name, pIsExtraType); }
155     RegistryKeyList getTypeKeys(const ::rtl::OString& name) const;
156     typereg::Reader getTypeReader(
157         const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const;
158     typereg::Reader getTypeReader(RegistryKey& rTypeKey) const;
159     RTTypeClass getTypeClass(const ::rtl::OString& name) const;
160     RTTypeClass getTypeClass(RegistryKey& rTypeKey) const;
161 
162     void setBase(const ::rtl::OString& base);
getBase() const163     ::rtl::OString getBase() const { return m_pImpl->m_base; }
164 
getSize() const165     sal_Int32 getSize() const { return m_pImpl->m_t2TypeClass.size(); }
166 protected:
167     RegistryKey searchTypeKey(
168         const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const;
169     void        freeRegistries();
170 
171     void acquire();
172     void release();
173 
174 protected:
175     RegistryTypeManagerImpl* m_pImpl;
176 };
177 
178 #endif // INCLUDED_CODEMAKER_TYPEMANAGER_HXX
179