1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "property_description.hxx"
21 #include "property_meta_data.hxx"
22 #include <forms/form_handler_factory.hxx>
23 #include "strings.hxx"
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnamespace.hxx>
28 #include <o3tl/hash_combine.hxx>
29 #include <tools/debug.hxx>
31 #include <unordered_map>
33 namespace xmloff::metadata
36 using namespace ::xmloff::token
;
38 //= property meta data
41 const PropertyDescription
* lcl_getPropertyMetaData()
43 static const PropertyDescription s_propertyMetaData
[] =
45 PropertyDescription( PROPERTY_DATE_MIN
, XML_NAMESPACE_FORM
, XML_MIN_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_DATE_MIN
),
46 PropertyDescription( PROPERTY_DATE_MAX
, XML_NAMESPACE_FORM
, XML_MAX_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_DATE_MAX
),
47 PropertyDescription( PROPERTY_DEFAULT_DATE
, XML_NAMESPACE_FORM
, XML_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_DEFAULT_DATE
),
48 PropertyDescription( PROPERTY_DATE
, XML_NAMESPACE_FORM
, XML_CURRENT_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_DATE
),
49 PropertyDescription( PROPERTY_TIME_MIN
, XML_NAMESPACE_FORM
, XML_MIN_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_TIME_MIN
),
50 PropertyDescription( PROPERTY_TIME_MAX
, XML_NAMESPACE_FORM
, XML_MAX_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_TIME_MAX
),
51 PropertyDescription( PROPERTY_DEFAULT_TIME
, XML_NAMESPACE_FORM
, XML_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_DEFAULT_TIME
),
52 PropertyDescription( PROPERTY_TIME
, XML_NAMESPACE_FORM
, XML_CURRENT_VALUE
, &FormHandlerFactory::getFormPropertyHandler
, PID_TIME
),
56 return s_propertyMetaData
;
62 // TODO: instead of having all of the below static, it should be some per-instance data. This way, the
63 // approach used here would scale much better.
64 // That is, if you have multiple "meta data instances", which manage a small, but closed set of properties,
65 // then looking through those multiple instances would probably be faster than searching within
66 // one big instance, since in this case, every instance can quickly decide whether it is responsible
67 // for some attribute or property, and otherwise delegate to the next instance.
69 typedef std::unordered_map
< OUString
, const PropertyDescription
* > DescriptionsByName
;
71 const DescriptionsByName
& lcl_getPropertyDescriptions()
74 static DescriptionsByName s_propertyDescriptionsByName
;
75 if ( s_propertyDescriptionsByName
.empty() )
77 const PropertyDescription
* desc
= lcl_getPropertyMetaData();
78 while ( !desc
->propertyName
.isEmpty() )
80 s_propertyDescriptionsByName
[ desc
->propertyName
] = desc
;
84 return s_propertyDescriptionsByName
;
87 typedef std::unordered_map
< OUString
, XMLTokenEnum
> ReverseTokenLookup
;
91 size_t operator()( const AttributeDescription
& i_attribute
) const
94 o3tl::hash_combine(seed
, i_attribute
.attributeToken
);
95 o3tl::hash_combine(seed
, i_attribute
.namespacePrefix
);
100 typedef std::unordered_map
< AttributeDescription
, PropertyGroups
, AttributeHash
> AttributesWithoutGroup
;
102 const AttributesWithoutGroup
& lcl_getAttributesWithoutGroups()
104 DBG_TESTSOLARMUTEX();
105 static AttributesWithoutGroup s_attributesWithoutGroup
;
106 if ( s_attributesWithoutGroup
.empty() )
108 const PropertyDescription
* desc
= lcl_getPropertyMetaData();
109 while ( !desc
->propertyName
.isEmpty() )
111 PropertyDescriptionList singleElementList
;
112 singleElementList
.push_back( desc
);
114 s_attributesWithoutGroup
[ desc
->attribute
].push_back( singleElementList
);
118 return s_attributesWithoutGroup
;
122 const PropertyDescription
* getPropertyDescription( const OUString
& i_propertyName
)
124 const DescriptionsByName
& rAllDescriptions( lcl_getPropertyDescriptions() );
125 DescriptionsByName::const_iterator pos
= rAllDescriptions
.find( i_propertyName
);
126 if ( pos
!= rAllDescriptions
.end() )
131 void getPropertyGroupList( const AttributeDescription
& i_attribute
, PropertyGroups
& o_propertyGroups
)
133 // the attribute is not used for any non-trivial group, which means it is mapped directly to
135 const AttributesWithoutGroup
& attributesWithoutGroups( lcl_getAttributesWithoutGroups() );
136 const AttributesWithoutGroup::const_iterator pos
= attributesWithoutGroups
.find( i_attribute
);
137 if ( pos
!= attributesWithoutGroups
.end() )
138 o_propertyGroups
= pos
->second
;
141 AttributeDescription
getAttributeDescription( sal_Int32 nAttributeToken
)
143 AttributeDescription attribute
;
144 attribute
.namespacePrefix
= (nAttributeToken
>> NMSP_SHIFT
) - 1;
145 attribute
.attributeToken
= static_cast<XMLTokenEnum
>(nAttributeToken
& TOKEN_MASK
);
149 } // namespace xmloff::metadata
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */