LibreOffice Module lotuswordpro (master) 1
clone.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
10#ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_CLONE_HXX
11#define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_CLONE_HXX
12
13namespace detail
14{
15
16template<typename T>
18{
19 template<typename U, U x>
20 struct test;
21
22 typedef char yes;
23 typedef struct { char a[2]; } no;
24
25 template<typename U>
26 static yes& check_sig(U*, test<U* (U::*)() const, &U::clone>* = nullptr);
27 template<typename U>
28 static no& check_sig(...);
29
30 enum
31 {
32 value = sizeof(check_sig<T>(nullptr)) == sizeof(yes)
33 };
34};
35
36template<typename T, bool HasClone>
37struct cloner
38{
39 static T* clone(T* const other)
40 {
41 return new T(*other);
42 }
43};
44
45template<typename T>
46struct cloner<T, true>
47{
48 static T* clone(T* const other)
49 {
50 return other->clone();
51 }
52};
53
54}
55
63template<typename T>
64T* clone(T* const other)
65{
66 return other ? ::detail::cloner<T, ::detail::has_clone<T>::value>::clone(other) : nullptr;
67}
68
69#endif // INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_CLONE_HXX
70
71/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
T * clone(T *const other)
Creates a new copy of the passed object.
Definition: clone.hxx:64
uno_Any a
static T * clone(T *const other)
Definition: clone.hxx:48
static T * clone(T *const other)
Definition: clone.hxx:39
static yes & check_sig(U *, test< U *(U::*)() const, &U::clone > *=nullptr)
static no & check_sig(...)