Chemical Data Processing Library C++ API - Version 1.4.0
Dereferencer.hpp
Go to the documentation of this file.
1 /*
2  * Dereferencer.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_UTIL_DEREFERENCER_HPP
30 #define CDPL_UTIL_DEREFERENCER_HPP
31 
32 #include "CDPL/Base/Exceptions.hpp"
33 
34 
35 namespace CDPL
36 {
37 
38  namespace Util
39  {
40 
50  template <typename ArgType, typename ResType>
51  struct Dereferencer
52  {
53 
54  public:
56  typedef ResType result_type;
57 
63  ResType operator()(const ArgType& ptr) const;
64  };
65 
75  template <typename ArgType, typename ResType>
77  {
78 
79  public:
81  typedef ResType result_type;
82 
89  ResType operator()(const ArgType& ptr) const;
90  };
91  } // namespace Util
92 } // namespace CDPL
93 
94 
95 // Implementation
96 
97 template <typename ArgType, typename ResType>
99 {
100  return *ptr;
101 }
102 
103 template <typename ArgType, typename ResType>
105 {
106  if (!ptr)
107  throw Base::NullPointerException("NullCheckDereferencer: attempt to dereference null pointer");
108 
109  return *ptr;
110 }
111 
112 #endif // CDPL_UTIL_DEREFERENCER_HPP
Definition of exception classes.
Thrown when an operation requires or expects a valid pointer but a null pointer was provided.
Definition: Base/Exceptions.hpp:95
The namespace of the Chemical Data Processing Library.
Unary functor for the dereferenciation of pointers without null pointer checking.
Definition: Dereferencer.hpp:52
ResType operator()(const ArgType &ptr) const
Returns a reference to or copy of the pointed-to argument object.
Definition: Dereferencer.hpp:98
ResType result_type
The functor's result type (made available to STL adaptors).
Definition: Dereferencer.hpp:56
Unary functor for the dereferenciation of pointers with null pointer checking.
Definition: Dereferencer.hpp:77
ResType result_type
The functor's result type (made available to STL adaptors).
Definition: Dereferencer.hpp:81
ResType operator()(const ArgType &ptr) const
Returns a reference to or copy of the pointed-to argument object.
Definition: Dereferencer.hpp:104