bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / forms / property_meta_data.cxx
blobf8cb46c316c5d704ce115b4cf9714c785bc42d31
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 #include <osl/diagnose.h>
31 #include <sal/log.hxx>
33 #include <unordered_map>
35 namespace xmloff::metadata
38 using namespace ::xmloff::token;
40 //= property meta data
41 namespace
43 const PropertyDescription* lcl_getPropertyMetaData()
45 static const PropertyDescription s_propertyMetaData[] =
47 PropertyDescription( PROPERTY_DATE_MIN, XML_NAMESPACE_FORM, XML_MIN_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_DATE_MIN ),
48 PropertyDescription( PROPERTY_DATE_MAX, XML_NAMESPACE_FORM, XML_MAX_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_DATE_MAX ),
49 PropertyDescription( PROPERTY_DEFAULT_DATE, XML_NAMESPACE_FORM, XML_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_DEFAULT_DATE ),
50 PropertyDescription( PROPERTY_DATE, XML_NAMESPACE_FORM, XML_CURRENT_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_DATE ),
51 PropertyDescription( PROPERTY_TIME_MIN, XML_NAMESPACE_FORM, XML_MIN_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_TIME_MIN ),
52 PropertyDescription( PROPERTY_TIME_MAX, XML_NAMESPACE_FORM, XML_MAX_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_TIME_MAX ),
53 PropertyDescription( PROPERTY_DEFAULT_TIME, XML_NAMESPACE_FORM, XML_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_DEFAULT_TIME ),
54 PropertyDescription( PROPERTY_TIME, XML_NAMESPACE_FORM, XML_CURRENT_VALUE, &FormHandlerFactory::getFormPropertyHandler, PID_TIME ),
56 PropertyDescription()
58 return s_propertyMetaData;
62 namespace
64 // TODO: instead of having all of the below static, it should be some per-instance data. This way, the
65 // approach used here would scale much better.
66 // That is, if you have multiple "meta data instances", which manage a small, but closed set of properties,
67 // then looking through those multiple instances would probably be faster than searching within
68 // one big instance, since in this case, every instance can quickly decide whether it is responsible
69 // for some attribute or property, and otherwise delegate to the next instance.
71 typedef std::unordered_map< OUString, const PropertyDescription* > DescriptionsByName;
73 const DescriptionsByName& lcl_getPropertyDescriptions()
75 DBG_TESTSOLARMUTEX();
76 static DescriptionsByName s_propertyDescriptionsByName;
77 if ( s_propertyDescriptionsByName.empty() )
79 const PropertyDescription* desc = lcl_getPropertyMetaData();
80 while ( !desc->propertyName.isEmpty() )
82 s_propertyDescriptionsByName[ desc->propertyName ] = desc;
83 ++desc;
86 return s_propertyDescriptionsByName;
89 typedef std::unordered_map< OUString, XMLTokenEnum > ReverseTokenLookup;
91 struct AttributeHash
93 size_t operator()( const AttributeDescription& i_attribute ) const
95 std::size_t seed = 0;
96 o3tl::hash_combine(seed, i_attribute.attributeToken);
97 o3tl::hash_combine(seed, i_attribute.namespacePrefix);
98 return seed;
102 typedef std::unordered_map< AttributeDescription, PropertyGroups, AttributeHash > AttributesWithoutGroup;
104 const AttributesWithoutGroup& lcl_getAttributesWithoutGroups()
106 DBG_TESTSOLARMUTEX();
107 static AttributesWithoutGroup s_attributesWithoutGroup;
108 if ( s_attributesWithoutGroup.empty() )
110 const PropertyDescription* desc = lcl_getPropertyMetaData();
111 while ( !desc->propertyName.isEmpty() )
113 PropertyDescriptionList singleElementList;
114 singleElementList.push_back( desc );
116 s_attributesWithoutGroup[ desc->attribute ].push_back( singleElementList );
117 ++desc;
120 return s_attributesWithoutGroup;
124 const PropertyDescription* getPropertyDescription( const OUString& i_propertyName )
126 const DescriptionsByName& rAllDescriptions( lcl_getPropertyDescriptions() );
127 DescriptionsByName::const_iterator pos = rAllDescriptions.find( i_propertyName );
128 if ( pos != rAllDescriptions.end() )
129 return pos->second;
130 return nullptr;
133 void getPropertyGroupList( const AttributeDescription& i_attribute, PropertyGroups& o_propertyGroups )
135 // the attribute is not used for any non-trivial group, which means it is mapped directly to
136 // a single property
137 const AttributesWithoutGroup& attributesWithoutGroups( lcl_getAttributesWithoutGroups() );
138 const AttributesWithoutGroup::const_iterator pos = attributesWithoutGroups.find( i_attribute );
139 if ( pos != attributesWithoutGroups.end() )
140 o_propertyGroups = pos->second;
143 AttributeDescription getAttributeDescription( sal_Int32 nAttributeToken )
145 AttributeDescription attribute;
146 attribute.namespacePrefix = (nAttributeToken >> NMSP_SHIFT) - 1;
147 attribute.attributeToken = static_cast<XMLTokenEnum>(nAttributeToken & TOKEN_MASK);
148 return attribute;
151 } // namespace xmloff::metadata
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */