LibreOffice Module xmloff (master) 1
property_meta_data.cxx
Go to the documentation of this file.
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
23#include "strings.hxx"
24#include <xmloff/xmlimp.hxx>
25#include <xmloff/xmltoken.hxx>
27
28#include <o3tl/hash_combine.hxx>
29#include <tools/debug.hxx>
30#include <osl/diagnose.h>
31#include <sal/log.hxx>
32
33#include <unordered_map>
34
36{
37
38 using namespace ::xmloff::token;
39
40 //= property meta data
41 namespace
42 {
43 const PropertyDescription* lcl_getPropertyMetaData()
44 {
45 static const PropertyDescription s_propertyMetaData[] =
46 {
55
57 };
58 return s_propertyMetaData;
59 }
60 }
61
62 namespace
63 {
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.
70
71 typedef std::unordered_map< OUString, const PropertyDescription* > DescriptionsByName;
72
73 const DescriptionsByName& lcl_getPropertyDescriptions()
74 {
76 static DescriptionsByName s_propertyDescriptionsByName;
77 if ( s_propertyDescriptionsByName.empty() )
78 {
79 const PropertyDescription* desc = lcl_getPropertyMetaData();
80 while ( !desc->propertyName.isEmpty() )
81 {
82 s_propertyDescriptionsByName[ desc->propertyName ] = desc;
83 ++desc;
84 }
85 }
86 return s_propertyDescriptionsByName;
87 }
88
89 typedef std::unordered_map< OUString, XMLTokenEnum > ReverseTokenLookup;
90
91 struct AttributeHash
92 {
93 size_t operator()( const AttributeDescription& i_attribute ) const
94 {
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;
99 }
100 };
101
102 typedef std::unordered_map< AttributeDescription, PropertyGroups, AttributeHash > AttributesWithoutGroup;
103
104 const AttributesWithoutGroup& lcl_getAttributesWithoutGroups()
105 {
107 static AttributesWithoutGroup s_attributesWithoutGroup;
108 if ( s_attributesWithoutGroup.empty() )
109 {
110 const PropertyDescription* desc = lcl_getPropertyMetaData();
111 while ( !desc->propertyName.isEmpty() )
112 {
113 PropertyDescriptionList singleElementList;
114 singleElementList.push_back( desc );
115
116 s_attributesWithoutGroup[ desc->attribute ].push_back( singleElementList );
117 ++desc;
118 }
119 }
120 return s_attributesWithoutGroup;
121 }
122 }
123
124 const PropertyDescription* getPropertyDescription( const OUString& i_propertyName )
125 {
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;
131 }
132
133 void getPropertyGroupList( const AttributeDescription& i_attribute, PropertyGroups& o_propertyGroups )
134 {
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;
141 }
142
144 {
146 attribute.namespacePrefix = (nAttributeToken >> NMSP_SHIFT) - 1;
147 attribute.attributeToken = static_cast<XMLTokenEnum>(nAttributeToken & TOKEN_MASK);
148 return attribute;
149 }
150
151} // namespace xmloff::metadata
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static PPropertyHandler getFormPropertyHandler(const PropertyId i_propertyId)
#define DBG_TESTSOLARMUTEX()
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
void getPropertyGroupList(const AttributeDescription &i_attribute, PropertyGroups &o_propertyGroups)
retrieves all known property groups which are mapped to the given attribute
AttributeDescription getAttributeDescription(sal_Int32 nAttributeToken)
retrieves the attribute descriptor for the attribute given by namespace prefix and attribute name
const PropertyDescription * getPropertyDescription(const OUString &i_propertyName)
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
constexpr OUStringLiteral PROPERTY_DATE
Definition: strings.hxx:90
constexpr OUStringLiteral PROPERTY_TIME_MAX
Definition: strings.hxx:84
constexpr OUStringLiteral PROPERTY_TIME
Definition: strings.hxx:92
constexpr OUStringLiteral PROPERTY_DEFAULT_TIME
Definition: strings.hxx:91
::std::vector< PropertyDescriptionList > PropertyGroups
constexpr OUStringLiteral PROPERTY_DATE_MAX
Definition: strings.hxx:82
constexpr OUStringLiteral PROPERTY_TIME_MIN
Definition: strings.hxx:83
constexpr OUStringLiteral PROPERTY_DATE_MIN
Definition: strings.hxx:81
::std::vector< const PropertyDescription * > PropertyDescriptionList
constexpr OUStringLiteral PROPERTY_DEFAULT_DATE
Definition: strings.hxx:89
@ PID_DATE_MIN
@ PID_DEFAULT_TIME
@ PID_DEFAULT_DATE
@ PID_DATE_MAX
@ PID_TIME_MAX
@ PID_TIME_MIN
sal_Int32 attribute
::xmloff::token::XMLTokenEnum attributeToken
const OUString propertyName
is the name of the property
const AttributeDescription attribute
size_t pos
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
constexpr size_t NMSP_SHIFT
Definition: xmlimp.hxx:93
constexpr sal_uInt16 XML_NAMESPACE_FORM