LibreOffice Module svl (master) 1
typedwhich.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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#ifndef INCLUDED_SVL_TYPEDWHICH_HXX
10#define INCLUDED_SVL_TYPEDWHICH_HXX
11
12#include <sal/config.h>
13#include <sal/types.h>
14#include <type_traits>
15
20template <class T> class TypedWhichId final
21{
22public:
23 explicit constexpr TypedWhichId(sal_uInt16 nWhich)
24 : mnWhich(nWhich)
25 {
26 }
27
30 template <class derived_type>
32 std::enable_if_t<std::is_base_of_v<T, derived_type>, int> = 0)
33 : mnWhich(sal_uInt16(other))
34 {
35 }
36
37 constexpr operator sal_uInt16() const { return mnWhich; }
38
39private:
40 sal_uInt16 mnWhich;
41};
42
43template <class T> constexpr bool operator==(TypedWhichId<T> const& lhs, TypedWhichId<T> rhs)
44{
45 return sal_uInt16(lhs) == sal_uInt16(rhs);
46}
47template <class T> constexpr bool operator!=(TypedWhichId<T> const& lhs, TypedWhichId<T> rhs)
48{
49 return sal_uInt16(lhs) != sal_uInt16(rhs);
50}
51template <class T> constexpr bool operator==(sal_uInt16 lhs, TypedWhichId<T> const& rhs)
52{
53 return lhs == sal_uInt16(rhs);
54}
55template <class T> constexpr bool operator!=(sal_uInt16 lhs, TypedWhichId<T> const& rhs)
56{
57 return lhs != sal_uInt16(rhs);
58}
59template <class T> constexpr bool operator==(TypedWhichId<T> const& lhs, sal_uInt16 rhs)
60{
61 return sal_uInt16(lhs) == rhs;
62}
63template <class T> constexpr bool operator!=(TypedWhichId<T> const& lhs, sal_uInt16 rhs)
64{
65 return sal_uInt16(lhs) != rhs;
66}
67
68#endif // INCLUDED_SVL_TYPEDWHICH_HXX
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
A very thin wrapper around the sal_uInt16 WhichId whose purpose is mostly to carry type information,...
Definition: typedwhich.hxx:21
sal_uInt16 mnWhich
Definition: typedwhich.hxx:40
constexpr TypedWhichId(sal_uInt16 nWhich)
Definition: typedwhich.hxx:23
constexpr TypedWhichId(TypedWhichId< derived_type > other, std::enable_if_t< std::is_base_of_v< T, derived_type >, int >=0)
Up-casting conversion constructor.
Definition: typedwhich.hxx:31
constexpr bool operator!=(TypedWhichId< T > const &lhs, TypedWhichId< T > rhs)
Definition: typedwhich.hxx:47
constexpr bool operator==(TypedWhichId< T > const &lhs, TypedWhichId< T > rhs)
Definition: typedwhich.hxx:43