LibreOffice Module xmloff (master)  1
xmlement.hxx
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 
20 #ifndef INCLUDED_XMLOFF_XMLEMENT_HXX
21 #define INCLUDED_XMLOFF_XMLEMENT_HXX
22 
23 #include <sal/types.h>
24 #include <xmloff/xmltoken.hxx>
25 
32 template<typename EnumT>
33 struct SvXMLEnumMapEntry
34 {
35 private:
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; }
43 };
44 
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>
50 {
51 private:
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; }
59 };
60 #endif
61 
62 #define ENUM_STRING_MAP_ENTRY(name,tok) { name, sizeof(name)-1, tok }
63 
64 #define ENUM_STRING_MAP_END() { nullptr, 0, 0 }
65 
69 template<typename EnumT>
71 {
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); }
82 };
83 
84 #endif // INCLUDED_XMLOFF_XMLEMENT_HXX
85 
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
Definition: xmlement.hxx:73
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
Map a const char* (with length) to a sal_uInt16 value.
Definition: xmlement.hxx:70
const char * GetName() const
Definition: xmlement.hxx:79
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:40
EnumT GetValue() const
Definition: xmlement.hxx:81
sal_Int32 GetNameLength() const
Definition: xmlement.hxx:80
SvXMLEnumStringMapEntry(const char *pName_, sal_Int32 nNameLength_, EnumT nValue_)
Definition: xmlement.hxx:77