• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

WTF

  • kjs
  • wtf
VectorTraits.h
Go to the documentation of this file.
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 2006 Apple Computer, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef WTF_VectorTraits_h
24#define WTF_VectorTraits_h
25
26#include "RefPtr.h"
27#include <utility>
28
29using std::pair;
30
31namespace WTF {
32
33 template <typename T> struct IsPod { static const bool value = false; };
34 template <> struct IsPod<bool> { static const bool value = true; };
35 template <> struct IsPod<char> { static const bool value = true; };
36 template <> struct IsPod<signed char> { static const bool value = true; };
37 template <> struct IsPod<unsigned char> { static const bool value = true; };
38 template <> struct IsPod<short> { static const bool value = true; };
39 template <> struct IsPod<unsigned short> { static const bool value = true; };
40 template <> struct IsPod<int> { static const bool value = true; };
41 template <> struct IsPod<unsigned int> { static const bool value = true; };
42 template <> struct IsPod<long> { static const bool value = true; };
43 template <> struct IsPod<unsigned long> { static const bool value = true; };
44 template <> struct IsPod<long long> { static const bool value = true; };
45 template <> struct IsPod<unsigned long long> { static const bool value = true; };
46 template <> struct IsPod<float> { static const bool value = true; };
47 template <> struct IsPod<double> { static const bool value = true; };
48 template <> struct IsPod<long double> { static const bool value = true; };
49 template <typename P> struct IsPod<P *> { static const bool value = true; };
50
51 template<bool isPod, typename T>
52 struct VectorTraitsBase;
53
54 template<typename T>
55 struct VectorTraitsBase<false, T>
56 {
57 static const bool needsDestruction = true;
58 static const bool needsInitialization = true;
59 static const bool canInitializeWithMemset = false;
60 static const bool canMoveWithMemcpy = false;
61 static const bool canCopyWithMemcpy = false;
62 static const bool canFillWithMemset = false;
63 static const bool canCompareWithMemcmp = false;
64 };
65
66 template<typename T>
67 struct VectorTraitsBase<true, T>
68 {
69 static const bool needsDestruction = false;
70 static const bool needsInitialization = false;
71 static const bool canInitializeWithMemset = false;
72 static const bool canMoveWithMemcpy = true;
73 static const bool canCopyWithMemcpy = true;
74 static const bool canFillWithMemset = sizeof(T) == sizeof(char);
75 static const bool canCompareWithMemcmp = true;
76 };
77
78 template<typename T>
79 struct VectorTraits : VectorTraitsBase<IsPod<T>::value, T> { };
80
81 struct SimpleClassVectorTraits
82 {
83 static const bool needsDestruction = true;
84 static const bool needsInitialization = true;
85 static const bool canInitializeWithMemset = true;
86 static const bool canMoveWithMemcpy = true;
87 static const bool canCopyWithMemcpy = false;
88 static const bool canFillWithMemset = false;
89 static const bool canCompareWithMemcmp = true;
90 };
91
92 // we know RefPtr is simple enough that initializing to 0 and moving with memcpy
93 // (and then not destructing the original) will totally work
94 template<typename P>
95 struct VectorTraits<RefPtr<P> > : SimpleClassVectorTraits { };
96
97 template<typename First, typename Second>
98 struct VectorTraits<pair<First, Second> >
99 {
100 typedef VectorTraits<First> FirstTraits;
101 typedef VectorTraits<Second> SecondTraits;
102
103 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
104 static const bool needsInitialization = FirstTraits::needsInitialization || SecondTraits::needsInitialization;
105 static const bool canInitializeWithMemset = FirstTraits::canInitializeWithMemset && SecondTraits::canInitializeWithMemset;
106 static const bool canMoveWithMemcpy = FirstTraits::canMoveWithMemcpy && SecondTraits::canMoveWithMemcpy;
107 static const bool canCopyWithMemcpy = FirstTraits::canCopyWithMemcpy && SecondTraits::canCopyWithMemcpy;
108 static const bool canFillWithMemset = false;
109 static const bool canCompareWithMemcmp = FirstTraits::canCompareWithMemcmp && SecondTraits::canCompareWithMemcmp;
110 };
111
112} // namespace WTF
113
114using WTF::VectorTraits;
115using WTF::SimpleClassVectorTraits;
116
117#endif // WTF_VectorTraits_h
RefPtr.h
WTF::RefPtr
Definition: RefPtr.h:37
int
WTF
Definition: ASCIICType.h:45
WTF::IsPod
Definition: VectorTraits.h:33
WTF::IsPod::value
static const bool value
Definition: VectorTraits.h:33
WTF::SimpleClassVectorTraits
Definition: VectorTraits.h:82
WTF::SimpleClassVectorTraits::canMoveWithMemcpy
static const bool canMoveWithMemcpy
Definition: VectorTraits.h:86
WTF::SimpleClassVectorTraits::canInitializeWithMemset
static const bool canInitializeWithMemset
Definition: VectorTraits.h:85
WTF::SimpleClassVectorTraits::canCompareWithMemcmp
static const bool canCompareWithMemcmp
Definition: VectorTraits.h:89
WTF::SimpleClassVectorTraits::needsInitialization
static const bool needsInitialization
Definition: VectorTraits.h:84
WTF::SimpleClassVectorTraits::canFillWithMemset
static const bool canFillWithMemset
Definition: VectorTraits.h:88
WTF::SimpleClassVectorTraits::needsDestruction
static const bool needsDestruction
Definition: VectorTraits.h:83
WTF::SimpleClassVectorTraits::canCopyWithMemcpy
static const bool canCopyWithMemcpy
Definition: VectorTraits.h:87
WTF::VectorTraitsBase
Definition: VectorTraits.h:52
WTF::VectorTraits< pair< First, Second > >::SecondTraits
VectorTraits< Second > SecondTraits
Definition: VectorTraits.h:101
WTF::VectorTraits< pair< First, Second > >::FirstTraits
VectorTraits< First > FirstTraits
Definition: VectorTraits.h:100
WTF::VectorTraits
Definition: VectorTraits.h:79
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

WTF

Skip menu "WTF"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal