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_XMLOFF_PRHDLFAC_HXX
21 #define INCLUDED_XMLOFF_PRHDLFAC_HXX
22 
23 #include <xmloff/dllapi.h>
24 #include <sal/types.h>
25 
26 #include <salhelper/simplereferenceobject.hxx>
27 #include <memory>
28 
29 class XMLPropertyHandler;
30 
31 /**
32  This class is a base-class to create XMLPropertyHandler.
33  It creates PropertyHandler for given XML-types and store
34  them in an internal cache. They'll be deleted at destruction-
35  time.
36  For create your own PropertyHandler for specific XML-types
37  you have to override the virtual method GetPropertyHandler
38  ( see below ).
39 */
40 class XMLOFF_DLLPUBLIC XMLPropertyHandlerFactory : public salhelper::SimpleReferenceObject
41 {
42     struct Impl;
43     std::unique_ptr<Impl> mpImpl;
44 
45     XMLPropertyHandlerFactory(const XMLPropertyHandlerFactory&) = delete;
46     XMLPropertyHandlerFactory& operator=(const XMLPropertyHandlerFactory&) = delete;
47 
48 public:
49     XMLPropertyHandlerFactory();
50     virtual ~XMLPropertyHandlerFactory() override;
51 
52     /**
53     This method retrieves a PropertyHandler for the given XML-type.
54     To extend this method for more XML-types override this method
55     like the example below. If you call the method of the base-class
56     you get propertyhandler for basic-XML-types ( e.g. for color, percent, ... ).
57     After that you could create your new XML-types. After creating a new type
58     you have to put the pointer into the cache via the method
59     PutHdlCache( sal_Int32 , XMLPropertyHandler* ).
60 
61     virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const
62     {
63         XMLPropertyHandler* pHdl = XMLPropertyHandlerFactory::GetPropertyHandler( nType );
64 
65         if( !pHdl )
66         {
67             switch( nType )
68             {
69                 case XML_TYPE_XYZ :
70                     pHdl = new XML_xyz_PropHdl;
71                     break;
72                 case ...
73                 :
74                 :
75             }
76 
77             if( pHdl )
78                 PutHdlCache( nType, pHdl );
79         }
80 
81         return pHdl;
82     }
83     */
84     virtual const XMLPropertyHandler* GetPropertyHandler(sal_Int32 nType) const;
85 
86     /** helper method to statically create a property handler; this will not
87      *  use the handler cache. This method should only be called in special
88      *  circumstances; calling GetPropertyHandler is almost always
89      *  preferable. */
90     static std::unique_ptr<XMLPropertyHandler> CreatePropertyHandler(sal_Int32 nType);
91 
92 protected:
93     /** Retrieves a PropertyHandler from the internal cache */
94     const XMLPropertyHandler* GetHdlCache(sal_Int32 nType) const;
95     /** Puts a PropertyHandler into the internal cache */
96     void PutHdlCache(sal_Int32 nType, const XMLPropertyHandler* pHdl) const;
97 
98 private:
99     /** Retrieves ( creates if necessary ) PropertyHandler for
100         basic XML-types */
101     SAL_DLLPRIVATE const XMLPropertyHandler* GetBasicHandler(sal_Int32 nType) const;
102 };
103 
104 #endif // INCLUDED_XMLOFF_PRHDLFAC_HXX
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
107