Guiliani  Version 2.6 revision 7293 (documentation build 12)
GUIAutoPtr.h
1/*
2* Copyright (C) TES Electronic Solutions GmbH,
3* All Rights Reserved.
4* Contact: info@guiliani.de
5*
6* This file is part of the Guiliani HMI framework
7* for the development of graphical user interfaces on embedded systems.
8*/
9
10#ifndef __GUIAUTOPTR_H__
11#define __GUIAUTOPTR_H__
12
13#include "eC_Types.h"
14
15#include "eC_CustomMemoryMapping.h"
16
18
46template<class T>
48{
49public:
50
52 typedef T element_type;
53
58 explicit CGUIAutoPtr(element_type* p, eC_Bool bIsArray) throw() :
59 m_ptr(p),
60 m_bIsArray(bIsArray)
61 { }
62
67 CGUIAutoPtr(CGUIAutoPtr<T>& kSource) throw()
68 {
69 m_ptr = kSource.m_ptr;
70 kSource.m_ptr = NULL;
71 m_bIsArray = kSource.m_bIsArray;
72 }
73
76 ~CGUIAutoPtr() throw()
77 {
78 DestroyPointer();
79 }
80
87 {
88 m_ptr = kSource.m_ptr;
89 kSource.m_ptr = NULL;
90 m_bIsArray = kSource.m_bIsArray;
91 return *this;
92 }
93
97 element_type& operator* () const throw() {return *m_ptr;}
98
102 element_type* operator-> () const throw() {return m_ptr;}
103
107 element_type* get() const throw() {return m_ptr;}
108
112 element_type* release() throw() {element_type* p=m_ptr; m_ptr = NULL; return p;}
113
117 void reset(element_type* p=0) throw() {if (p!=m_ptr){DestroyPointer(); m_ptr=p;}}
118
123 CGUIAutoPtr& operator = (element_type* p){if (p!=m_ptr){DestroyPointer(); m_ptr=p;}return *this;}
124
126 template<class Y> operator CGUIAutoPtr<Y>() throw()
127 {
128 CGUIAutoPtr<Y> kYAutoPtr = *this;
129 return kYAutoPtr;
130 }
131
132private:
134 void DestroyPointer()
135 {
136 if (m_bIsArray == true)
137 {
138 delete[] m_ptr;
139 }
140 else
141 {
142 delete m_ptr;
143 }
144 m_ptr = NULL;
145 }
146
148 element_type* m_ptr;
150 eC_Bool m_bIsArray;
151};
152
153#include "eC_CustomMemoryMappingUndef.h"
154
155#endif
Guiliani-implementation of an auto-pointer.
Definition: GUIAutoPtr.h:48
void reset(element_type *p=0)
Definition: GUIAutoPtr.h:117
element_type & operator*() const
Definition: GUIAutoPtr.h:97
CGUIAutoPtr(CGUIAutoPtr< T > &kSource)
Definition: GUIAutoPtr.h:67
CGUIAutoPtr< T > & operator=(CGUIAutoPtr< T > &kSource)
Definition: GUIAutoPtr.h:86
element_type * operator->() const
Definition: GUIAutoPtr.h:102
~CGUIAutoPtr()
Definition: GUIAutoPtr.h:76
CGUIAutoPtr(element_type *p, eC_Bool bIsArray)
Definition: GUIAutoPtr.h:58
T element_type
typedef of element type
Definition: GUIAutoPtr.h:52
element_type * get() const
Definition: GUIAutoPtr.h:107
element_type * release()
Definition: GUIAutoPtr.h:112