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

kjsembed

  • kjsembed
  • kjsembed
pointer.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
3 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
4 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
5 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23
24#ifndef POINTER_H
25#define POINTER_H
26
27#include <algorithm>
28#include <typeinfo>
29#include <QtCore/QVariant>
30
31struct PointerBase
32{
33public:
34 virtual ~PointerBase() {;}
35 virtual void cleanup() = 0;
36 virtual const std::type_info &type() const = 0;
37 virtual void *voidStar() = 0;
38};
39Q_DECLARE_METATYPE(PointerBase*)
40
41template<typename ValueType>
42struct Pointer : public PointerBase
43{
44public:
45 Pointer( ValueType *value) : ptr(value)
46 {
47// qDebug("new pointer %s %0x", typeid(ValueType).name(), value);
48 }
49 ~Pointer( )
50 {
51
52 }
53 void cleanup()
54 {
55// qDebug("delete pointer %s %0x", typeid(ValueType).name(), ptr );
56 delete ptr;
57 ptr=0L;
58 }
59 const std::type_info &type() const
60 {
61 return typeid(ValueType);
62 }
63
64 void *voidStar()
65 {
66 return (void*)ptr;
67 }
68
69 ValueType *ptr;
70};
71
72template<typename ValueType>
73struct Value : public PointerBase
74{
75public:
76 Value( ValueType val) : value(val)
77 {
78 //qDebug("new value %s", typeid(ValueType).name());
79 }
80 ~Value( )
81 {
82 //qDebug("delete value");
83 }
84
85 void cleanup()
86 {
87
88 }
89
90 const std::type_info &type() const
91 {
92 return typeid(ValueType);
93 }
94
95 void *voidStar()
96 {
97 return (void*)&value;
98 }
99
100 ValueType value;
101};
102
103struct NullPtr : public PointerBase
104{
105 NullPtr( ) : ptr(0)
106 {
107 ;
108 }
109 ~NullPtr( )
110 {
111 ;
112 }
113 void cleanup()
114 {
115 ;
116 }
117
118 const std::type_info &type() const
119 {
120 return typeid(NullPtr);
121 }
122
123 void *voidStar()
124 {
125 return &ptr;
126 }
127
128 void* ptr;
129
130};
131
132template<typename ValueType>
133ValueType *pointer_cast( PointerBase *pointer )
134{
135// qDebug("pointers %s %s", typeid(ValueType).name(), pointer->type().name() );
136 if( typeid(ValueType) != pointer->type() )
137 return 0L;
138 Pointer<ValueType> *upcast = static_cast< Pointer<ValueType> *>(pointer);
139 return upcast->ptr;
140}
141
142#endif
143
144//kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
145
pointer_cast
ValueType * pointer_cast(PointerBase *pointer)
Definition: pointer.h:133
value
QVariant value
Definition: settings.cpp:35
NullPtr
Definition: pointer.h:104
NullPtr::cleanup
void cleanup()
Definition: pointer.h:113
NullPtr::voidStar
void * voidStar()
Definition: pointer.h:123
NullPtr::NullPtr
NullPtr()
Definition: pointer.h:105
NullPtr::type
const std::type_info & type() const
Definition: pointer.h:118
NullPtr::~NullPtr
~NullPtr()
Definition: pointer.h:109
NullPtr::ptr
void * ptr
Definition: pointer.h:128
PointerBase
Definition: pointer.h:32
PointerBase::voidStar
virtual void * voidStar()=0
PointerBase::~PointerBase
virtual ~PointerBase()
Definition: pointer.h:34
PointerBase::cleanup
virtual void cleanup()=0
PointerBase::type
virtual const std::type_info & type() const =0
Pointer
Definition: pointer.h:43
Pointer::ptr
ValueType * ptr
Definition: pointer.h:69
Pointer::voidStar
void * voidStar()
Definition: pointer.h:64
Pointer::~Pointer
~Pointer()
Definition: pointer.h:49
Pointer::cleanup
void cleanup()
Definition: pointer.h:53
Pointer::type
const std::type_info & type() const
Definition: pointer.h:59
Pointer::Pointer
Pointer(ValueType *value)
Definition: pointer.h:45
Value
Definition: pointer.h:74
Value::~Value
~Value()
Definition: pointer.h:80
Value::voidStar
void * voidStar()
Definition: pointer.h:95
Value::Value
Value(ValueType val)
Definition: pointer.h:76
Value::value
ValueType value
Definition: pointer.h:100
Value::type
const std::type_info & type() const
Definition: pointer.h:90
Value::cleanup
void cleanup()
Definition: pointer.h:85
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.

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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