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>
30 #include <osl/diagnose.h>
31 #include <sal/log.hxx>
33 #include <unordered_map>
35 namespace xmloff::metadata
38 using namespace ::xmloff::token
;
40 #define FORM_SINGLE_PROPERTY( id, att ) \
41 PropertyDescription( PROPERTY_##id, XML_NAMESPACE_FORM, att, &FormHandlerFactory::getFormPropertyHandler, PID_##id )
43 //= property meta data
46 const PropertyDescription
* lcl_getPropertyMetaData()
48 static const PropertyDescription s_propertyMetaData
[] =
50 FORM_SINGLE_PROPERTY( DATE_MIN
, XML_MIN_VALUE
),
51 FORM_SINGLE_PROPERTY( DATE_MAX
, XML_MAX_VALUE
),
52 FORM_SINGLE_PROPERTY( DEFAULT_DATE
, XML_VALUE
),
53 FORM_SINGLE_PROPERTY( DATE
, XML_CURRENT_VALUE
),
54 FORM_SINGLE_PROPERTY( TIME_MIN
, XML_MIN_VALUE
),
55 FORM_SINGLE_PROPERTY( TIME_MAX
, XML_MAX_VALUE
),
56 FORM_SINGLE_PROPERTY( DEFAULT_TIME
, XML_VALUE
),
57 FORM_SINGLE_PROPERTY( TIME
, XML_CURRENT_VALUE
),
61 return s_propertyMetaData
;
67 // TODO: instead of having all of the below static, it should be some per-instance data. This way, the
68 // approach used here would scale much better.
69 // That is, if you have multiple "meta data instances", which manage a small, but closed set of properties,
70 // then looking through those multiple instances would probably be faster than searching within
71 // one big instance, since in this case, every instance can quickly decide whether it is responsible
72 // for some attribute or property, and otherwise delegate to the next instance.
74 typedef std::unordered_map
< OUString
, const PropertyDescription
* > DescriptionsByName
;
76 const DescriptionsByName
& lcl_getPropertyDescriptions()
79 static DescriptionsByName s_propertyDescriptionsByName
;
80 if ( s_propertyDescriptionsByName
.empty() )
82 const PropertyDescription
* desc
= lcl_getPropertyMetaData();
83 while ( !desc
->propertyName
.isEmpty() )
85 s_propertyDescriptionsByName
[ desc
->propertyName
] = desc
;
89 return s_propertyDescriptionsByName
;
92 typedef std::unordered_map
< OUString
, XMLTokenEnum
> ReverseTokenLookup
;
96 size_t operator()( const AttributeDescription
& i_attribute
) const
99 o3tl::hash_combine(seed
, i_attribute
.attributeToken
);
100 o3tl::hash_combine(seed
, i_attribute
.namespacePrefix
);
105 typedef std::unordered_map
< AttributeDescription
, PropertyGroups
, AttributeHash
> AttributesWithoutGroup
;
107 const AttributesWithoutGroup
& lcl_getAttributesWithoutGroups()
109 DBG_TESTSOLARMUTEX();
110 static AttributesWithoutGroup s_attributesWithoutGroup
;
111 if ( s_attributesWithoutGroup
.empty() )
113 const PropertyDescription
* desc
= lcl_getPropertyMetaData();
114 while ( !desc
->propertyName
.isEmpty() )
116 PropertyDescriptionList singleElementList
;
117 singleElementList
.push_back( desc
);
119 s_attributesWithoutGroup
[ desc
->attribute
].push_back( singleElementList
);
123 return s_attributesWithoutGroup
;
127 const PropertyDescription
* getPropertyDescription( const OUString
& i_propertyName
)
129 const DescriptionsByName
& rAllDescriptions( lcl_getPropertyDescriptions() );
130 DescriptionsByName::const_iterator pos
= rAllDescriptions
.find( i_propertyName
);
131 if ( pos
!= rAllDescriptions
.end() )
136 void getPropertyGroupList( const AttributeDescription
& i_attribute
, PropertyGroups
& o_propertyGroups
)
138 // the attribute is not used for any non-trivial group, which means it is mapped directly to
140 const AttributesWithoutGroup
& attributesWithoutGroups( lcl_getAttributesWithoutGroups() );
141 const AttributesWithoutGroup::const_iterator pos
= attributesWithoutGroups
.find( i_attribute
);
142 if ( pos
!= attributesWithoutGroups
.end() )
143 o_propertyGroups
= pos
->second
;
146 AttributeDescription
getAttributeDescription( sal_Int32 nAttributeToken
)
148 AttributeDescription attribute
;
149 attribute
.namespacePrefix
= (nAttributeToken
>> NMSP_SHIFT
) - 1;
150 attribute
.attributeToken
= static_cast<XMLTokenEnum
>(nAttributeToken
& TOKEN_MASK
);
154 } // namespace xmloff::metadata
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */