Make constant array accessible from different places

Regina Henschel rb.henschel at t-online.de
Fri Aug 28 17:43:40 UTC 2020


Hi Stephan,

thanks. I'll do it as you have suggested.

Kind regards
Regina

Stephan Bergmann schrieb am 28-Aug-20 um 19:16:
> On 28/08/2020 18:53, Regina Henschel wrote:
>> I have a constant array
>> const std::pair<OUString, OUString> aApiToLabelFooPairs[] =
>> {
>>      {"LineStyle", "LabelBorderStyle"},
>>     etc.
>> }
>>
>> for to map draw object fill and line property names to data-label 
>> related properties of series and points in a chart on ODF import.
>>
>> I need it in SchXMLSeries2Context::setStylesToSeries and in 
>> SchXMLSeries2Context::setStylesToDataPoints.
>>
>> I have not worked on export yet, so I don't know whether it will be 
>> needed on export too.
>>
>> Where to put this array and how?
>>
>> I can put it separately from the SchXMLSeries2Context methods into the 
>> file SchXMLSeries2Context.cxx. Would that be "static" or not?
> 
> If aApiToLabelFooPairs is only used in 
> xmloff/source/chart/SchXMLSeries2Context.cxx, you best put it in that 
> file, at file scope.  And as the object is const, "static" would be 
> redundant (and loplugin:redundantstatic would even warn about it).
> 
> (There's a slight drawback with global static objects involving e.g. 
> OUString construction, as that incurs some cost when the library 
> containing the object is loaded.  std::pair construction is by now 
> constexpr if the construction of its members is, and two 
> constexpr-constructible replacements for OUString that are suitable in 
> many use cases is/was OUStringLiteral---but for which I'm planing on 
> changing its role somewhat, so that it would unfortunately no longer be 
> usable in your example---and std::u16string_view.  But you can ignore 
> that for now and we can revisit things once (a) you know the final place 
> for aApiToLabelFooPairs when all uses across import and export have been 
> determined, and (b) the OUStringLiteral -> std::u16string_view situation 
> has settled.)
> 
> _______________________________________________
> LibreOffice mailing list
> LibreOffice at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/libreoffice



More information about the LibreOffice mailing list