Breeze: Add Save All & Save a Copy icons
[LibreOffice.git] / include / xmloff / xmlement.hxx
blobbedef86e654c70d9e9ed8f8377cb72c36c01dcce
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 #ifndef INCLUDED_XMLOFF_XMLEMENT_HXX
21 #define INCLUDED_XMLOFF_XMLEMENT_HXX
23 #include <sal/types.h>
24 #include <xmloff/xmltoken.hxx>
26 /** Map an XMLTokenEnum to an enum value.
27 * To be used with SvXMLUnitConverter::convertEnum(...)
28 * We store the enum internally as a fixed size field, since there are
29 * places where we want to store a generic pointer to an array of SvXMLEnumMapEntry
30 * and we don't want to templatize the class.
32 template<typename EnumT>
33 struct SvXMLEnumMapEntry
35 private:
36 ::xmloff::token::XMLTokenEnum eToken;
37 sal_uInt16 nValue;
38 public:
39 SvXMLEnumMapEntry(::xmloff::token::XMLTokenEnum eToken_, EnumT nValue_)
40 : eToken(eToken_), nValue(static_cast<sal_uInt16>(nValue_)) {}
41 ::xmloff::token::XMLTokenEnum GetToken() const { return eToken; }
42 sal_uInt16 GetValue() const { return nValue; }
45 #if defined(_MSC_VER)
46 // specialisation to avoid lots of "C2398: conversion from 'const sal_Int16' to 'sal_uInt16' requires a narrowing conversion"
47 // errors when compiling on MSVC
48 template<>
49 struct SvXMLEnumMapEntry<sal_uInt16>
51 private:
52 ::xmloff::token::XMLTokenEnum eToken;
53 sal_uInt16 nValue;
54 public:
55 SvXMLEnumMapEntry(::xmloff::token::XMLTokenEnum eToken_, sal_Int32 nValue_)
56 : eToken(eToken_), nValue(nValue_) {}
57 ::xmloff::token::XMLTokenEnum GetToken() const { return eToken; }
58 sal_uInt16 GetValue() const { return nValue; }
60 #endif
62 #define ENUM_STRING_MAP_ENTRY(name,tok) { name, sizeof(name)-1, tok }
64 #define ENUM_STRING_MAP_END() { nullptr, 0, 0 }
66 /** Map a const char* (with length) to a sal_uInt16 value.
67 * To be used with SvXMLUnitConverter::convertEnum(...)
69 template<typename EnumT>
70 struct SvXMLEnumStringMapEntry
72 private:
73 const char * pName;
74 sal_Int32 nNameLength;
75 sal_uInt16 nValue;
76 public:
77 SvXMLEnumStringMapEntry(const char * pName_, sal_Int32 nNameLength_, EnumT nValue_)
78 : pName(pName_), nNameLength(nNameLength_), nValue(nValue_) {}
79 const char * GetName() const { return pName; }
80 sal_Int32 GetNameLength() const { return nNameLength; }
81 EnumT GetValue() const { return static_cast<EnumT>(nValue); }
84 #endif // INCLUDED_XMLOFF_XMLEMENT_HXX
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */