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

kjsembed

  • sources
  • kde-4.12
  • kdelibs
  • 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 
31 struct PointerBase
32 {
33 public:
34  virtual ~PointerBase() {;}
35  virtual void cleanup() = 0;
36  virtual const std::type_info &type() const = 0;
37  virtual void *voidStar() = 0;
38 };
39 Q_DECLARE_METATYPE(PointerBase*)
40 
41 template<typename ValueType>
42 struct Pointer : public PointerBase
43 {
44 public:
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 
72 template<typename ValueType>
73 struct Value : public PointerBase
74 {
75 public:
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 
103 struct 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 
132 template<typename ValueType>
133 ValueType *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 
Value::voidStar
void * voidStar()
Definition: pointer.h:95
NullPtr::voidStar
void * voidStar()
Definition: pointer.h:123
NullPtr::ptr
void * ptr
Definition: pointer.h:128
Value::cleanup
void cleanup()
Definition: pointer.h:85
Pointer::cleanup
void cleanup()
Definition: pointer.h:53
Pointer
Definition: pointer.h:42
Pointer::type
const std::type_info & type() const
Definition: pointer.h:59
DomElementNS::val
QString val
Definition: dom.cpp:529
Pointer::Pointer
Pointer(ValueType *value)
Definition: pointer.h:45
NullPtr::type
const std::type_info & type() const
Definition: pointer.h:118
PointerBase
Definition: pointer.h:31
PointerBase::~PointerBase
virtual ~PointerBase()
Definition: pointer.h:34
NullPtr::~NullPtr
~NullPtr()
Definition: pointer.h:109
Pointer::~Pointer
~Pointer()
Definition: pointer.h:49
Value::value
ValueType value
Definition: pointer.h:100
NullPtr::NullPtr
NullPtr()
Definition: pointer.h:105
NullPtr::cleanup
void cleanup()
Definition: pointer.h:113
NullPtr
Definition: pointer.h:103
Pointer::voidStar
void * voidStar()
Definition: pointer.h:64
pointer_cast
ValueType * pointer_cast(PointerBase *pointer)
Definition: pointer.h:133
Value::type
const std::type_info & type() const
Definition: pointer.h:90
Value::Value
Value(ValueType val)
Definition: pointer.h:76
Value
Definition: pointer.h:73
Value::~Value
~Value()
Definition: pointer.h:80
Pointer::ptr
ValueType * ptr
Definition: pointer.h:69
PointerBase::voidStar
virtual void * voidStar()=0
value
QVariant value
Definition: settings.cpp:35
PointerBase::type
virtual const std::type_info & type() const =0
PointerBase::cleanup
virtual void cleanup()=0
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:53 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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