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
32template<typename EnumT>
34{
35private:
37 sal_uInt16 nValue;
38public:
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
48template<>
49struct SvXMLEnumMapEntry<sal_uInt16>
50{
51private:
53 sal_uInt16 nValue;
54public:
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
69template<typename EnumT>
71{
72private:
73 const char * pName;
74 sal_Int32 nNameLength;
75 sal_uInt16 nValue;
76public:
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: */
sal_Int16 nValue
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
Map a const char* (with length) to a sal_uInt16 value.
Definition: xmlement.hxx:71
EnumT GetValue() const
Definition: xmlement.hxx:81
const char * pName
Definition: xmlement.hxx:73
const char * GetName() const
Definition: xmlement.hxx:79
sal_Int32 GetNameLength() const
Definition: xmlement.hxx:80
SvXMLEnumStringMapEntry(const char *pName_, sal_Int32 nNameLength_, EnumT nValue_)
Definition: xmlement.hxx:77
XMLTokenEnum eToken
Definition: xmltoken.cxx:40