bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESAutoPtr.h
1// BESAutoPtr.h
2
3// This file is part of fits_handler, a data handler for the OPeNDAP data
4// server.
5
6// Copyright (c) 2004,2005 University Corporation for Atmospheric Research
7// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact University Corporation for Atmospheric Research at
24// 3080 Center Green Drive, Boulder, CO 80301
25
26// (c) COPYRIGHT University Corporation for Atmostpheric Research 2004-2005
27// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28//
29// Authors:
30// pwest Patrick West <pwest@ucar.edu>
31// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33#ifndef BESAutoPtr_h_
34#define BESAutoPtr_h_ 1
35
36template<class T>
37class BESAutoPtr {
38private:
39 T* p;
40 bool _is_vector;
41
42 // disable copy constructor.
43 template<class U> BESAutoPtr(BESAutoPtr<U> &) { }
44
45
46 // disable overloaded = operator.
47 template<class U> BESAutoPtr<T>& operator=(BESAutoPtr<U> &)
48 {
49 return *this;
50 }
51
52public:
53 explicit BESAutoPtr(T* pointed = 0, bool v = false)
54 {
55 p = pointed;
56 _is_vector = v;
57 }
58
59 ~BESAutoPtr()
60 {
61 if (_is_vector)
62 delete[] p;
63 else
64 delete p;
65 p = 0;
66 }
67
68 T* set(T *pointed, bool v = false)
69 {
70 T* temp = p;
71 p = pointed;
72 _is_vector = v;
73 return temp;
74 }
75
76 T* get() const
77 {
78 return p;
79 }
80
81 T* operator ->() const
82 {
83 return p;
84 }
85
86 T& operator *() const
87 {
88 return *p;
89 }
90
91 T* release()
92 {
93 T* old = p;
94 p = 0;
95 return old;
96 }
97
98 void reset()
99 {
100 if (_is_vector)
101 delete[] p;
102 else
103 delete p;
104 p = 0;
105 }
106};
107
108#endif // BESAutoPtr_h_