Nvwa  1.1
cont_ptr_utils.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 // vim:tabstop=4:shiftwidth=4:expandtab:
3 
4 /*
5  * Copyright (C) 2004-2013 Wu Yongwei <adah at users dot sourceforge dot net>
6  *
7  * This software is provided 'as-is', without any express or implied
8  * warranty. In no event will the authors be held liable for any
9  * damages arising from the use of this software.
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute
13  * it freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must
16  * not claim that you wrote the original software. If you use this
17  * software in a product, an acknowledgement in the product
18  * documentation would be appreciated but is not required.
19  * 2. Altered source versions must be plainly marked as such, and must
20  * not be misrepresented as being the original software.
21  * 3. This notice may not be removed or altered from any source
22  * distribution.
23  *
24  * This file is part of Stones of Nvwa:
25  * http://sourceforge.net/projects/nvwa
26  *
27  */
28 
38 #ifndef NVWA_CONT_PTR_UTILS_H
39 #define NVWA_CONT_PTR_UTILS_H
40 
41 #include "_nvwa.h" // NVWA_NAMESPACE_*
42 
43 NVWA_NAMESPACE_BEGIN
44 
58 {
59  template <typename _Tp>
60  const _Tp& operator()(const _Tp* ptr) const
61  {
62  return *ptr;
63  }
64 };
65 
80 {
81  template <typename _Pointer>
82  bool operator()(const _Pointer& ptr1, const _Pointer& ptr2) const
83  {
84  return *ptr1 < *ptr2;
85  }
86 };
87 
99 {
100  template <typename _Tp>
101  void operator()(_Tp* ptr) const
102  {
103  delete ptr;
104  }
105 };
106 
117 template <typename _OutputStrm, typename _StringType = const char*>
119 {
120  output_object(_OutputStrm& outs, const _StringType& sep)
121  : _M_outs(outs), _M_sep(sep)
122  {}
123 
124  template <typename _Pointer>
125  void operator()(const _Pointer& ptr) const
126  {
127  _M_outs << *ptr << _M_sep;
128  }
129 
130 private:
131  _OutputStrm& _M_outs;
132  _StringType _M_sep;
133 };
134 
135 NVWA_NAMESPACE_END
136 
137 #endif // NVWA_CONT_PTR_UTILS_H
Functor to compare objects pointed by a container of pointers.
Definition: cont_ptr_utils.h:79
Functor to return objects pointed by a container of pointers.
Definition: cont_ptr_utils.h:57
Functor to delete objects pointed by a container of pointers.
Definition: cont_ptr_utils.h:98
Functor to output objects pointed by a container of pointers.
Definition: cont_ptr_utils.h:118
Common definitions for preprocessing.