Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef INCLUDED_CODEMAKER_TYPEMANAGER_HXX
21 : : #define INCLUDED_CODEMAKER_TYPEMANAGER_HXX
22 : :
23 : : #include "codemaker/global.hxx"
24 : : #include "registry/registry.hxx"
25 : : #include "registry/types.h"
26 : :
27 : : #include <boost/unordered_map.hpp>
28 : : #include <list>
29 : :
30 : : namespace typereg { class Reader; }
31 : :
32 : : //typedef ::std::list< Registry* > RegistryList;
33 : : typedef ::std::vector< Registry* > RegistryList;
34 : : typedef ::std::pair< RegistryKey, sal_Bool > KeyPair;
35 : : typedef ::std::vector< KeyPair > RegistryKeyList;
36 : :
37 : : typedef ::boost::unordered_map
38 : : <
39 : : ::rtl::OString, // Typename
40 : : RTTypeClass, // TypeClass
41 : : HashString,
42 : : EqualString
43 : : > T2TypeClassMap;
44 : :
45 : : struct TypeManagerImpl
46 : : {
47 : 28 : TypeManagerImpl()
48 : 28 : : m_refCount(0)
49 : 28 : {}
50 : :
51 : : sal_Int32 m_refCount;
52 : : };
53 : :
54 : : class TypeManager
55 : : {
56 : : public:
57 : : TypeManager();
58 : : virtual ~TypeManager();
59 : :
60 : : TypeManager( const TypeManager& value )
61 : : : m_pImpl( value.m_pImpl )
62 : : {
63 : : acquire();
64 : : }
65 : :
66 : : TypeManager& operator = ( const TypeManager& value )
67 : : {
68 : : release();
69 : : m_pImpl = value.m_pImpl;
70 : : acquire();
71 : : return *this;
72 : : }
73 : :
74 : 0 : virtual sal_Bool isValidType(const ::rtl::OString&) const
75 : 0 : { return sal_False; }
76 : :
77 : 0 : virtual ::rtl::OString getTypeName(RegistryKey&) const
78 : 0 : { return ::rtl::OString(); }
79 : :
80 : 0 : virtual RegistryKey getTypeKey(const ::rtl::OString&, sal_Bool * = 0 ) const
81 : 0 : { return RegistryKey(); }
82 : 0 : virtual RegistryKeyList getTypeKeys(const ::rtl::OString&) const
83 : 0 : { return RegistryKeyList(); }
84 : : virtual typereg::Reader getTypeReader(
85 : : const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const = 0;
86 : : virtual typereg::Reader getTypeReader(RegistryKey& rTypeKey) const = 0;
87 : 0 : virtual RTTypeClass getTypeClass(const ::rtl::OString&) const
88 : 0 : { return RT_TYPE_INVALID; }
89 : 0 : virtual RTTypeClass getTypeClass(RegistryKey&) const
90 : 0 : { return RT_TYPE_INVALID; }
91 : :
92 : 0 : virtual void setBase(const ::rtl::OString&) {}
93 : 0 : virtual ::rtl::OString getBase() const { return ::rtl::OString(); }
94 : :
95 : 0 : virtual sal_Int32 getSize() const { return 0; }
96 : :
97 : : static sal_Bool isBaseType(const ::rtl::OString& name);
98 : : protected:
99 : : sal_Int32 acquire();
100 : : sal_Int32 release();
101 : :
102 : : protected:
103 : : TypeManagerImpl* m_pImpl;
104 : : };
105 : :
106 : 0 : struct RegistryTypeManagerImpl
107 : : {
108 : 28 : RegistryTypeManagerImpl()
109 [ + - ][ + - ]: 28 : : m_base("/")
[ + - ]
110 : 28 : {}
111 : :
112 : : T2TypeClassMap m_t2TypeClass;
113 : : RegistryList m_registries;
114 : : RegistryList m_extra_registries;
115 : : ::rtl::OString m_base;
116 : : };
117 : :
118 : : class RegistryTypeManager : public TypeManager
119 : : {
120 : : public:
121 : : RegistryTypeManager();
122 : : virtual ~RegistryTypeManager();
123 : :
124 : : RegistryTypeManager( const RegistryTypeManager& value )
125 : : : TypeManager(value)
126 : : , m_pImpl( value.m_pImpl )
127 : : {
128 : : acquire();
129 : : }
130 : :
131 : : sal_Bool init(const StringVector& regFiles, const StringVector& extraFiles = StringVector() );
132 : :
133 : : ::rtl::OString getTypeName(RegistryKey& rTypeKey) const;
134 : :
135 : 0 : sal_Bool isValidType(const ::rtl::OString& name) const
136 : 0 : { return searchTypeKey(name, 0).isValid(); }
137 : 0 : RegistryKey getTypeKey(
138 : : const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const
139 : 0 : { return searchTypeKey(name, pIsExtraType); }
140 : : RegistryKeyList getTypeKeys(const ::rtl::OString& name) const;
141 : : typereg::Reader getTypeReader(
142 : : const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const;
143 : : typereg::Reader getTypeReader(RegistryKey& rTypeKey) const;
144 : : RTTypeClass getTypeClass(const ::rtl::OString& name) const;
145 : : RTTypeClass getTypeClass(RegistryKey& rTypeKey) const;
146 : :
147 : : void setBase(const ::rtl::OString& base);
148 : 75274 : ::rtl::OString getBase() const { return m_pImpl->m_base; }
149 : :
150 : 0 : sal_Int32 getSize() const { return m_pImpl->m_t2TypeClass.size(); }
151 : : protected:
152 : : RegistryKey searchTypeKey(
153 : : const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const;
154 : : void freeRegistries();
155 : :
156 : : void acquire();
157 : : void release();
158 : :
159 : : protected:
160 : : RegistryTypeManagerImpl* m_pImpl;
161 : : };
162 : :
163 : : #endif // INCLUDED_CODEMAKER_TYPEMANAGER_HXX
164 : :
165 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|