TPIE

v1.1rc1-6-g0c97303
sort_deprecated.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2008-2012, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef __TPIE_SORT_DEPRECATED_H__
21 #define __TPIE_SORT_DEPRECATED_H__
22 
66 
67 // Get definitions for working with Unix and Windows
68 #include <tpie/portability.h>
69 
70 // The class that actually does the sorting
71 #include <tpie/sort_manager.h>
72 #include <tpie/mergeheap.h>
73 #include <tpie/internal_sort.h>
74 
77 
78 #include <tpie/sort.h>
79 
80 #include <tpie/comparator.h>
81 
82 namespace tpie {
83 
84  namespace ami {
85  inline err exception_kind(const exception & e) {
86  if (0 != dynamic_cast<const end_of_stream_exception *>(&e)) return END_OF_STREAM;
87  return BTE_ERROR;
88  }
89  }
132 
133  namespace ami {
134 
135  template<class T>
136  err sort(stream<T> *instream_ami, stream<T> *outstream_ami,
137  tpie::progress_indicator_base* indicator=NULL) {
138  try {
139  tpie::sort(instream_ami->underlying_stream(), outstream_ami->underlying_stream(), indicator);
140  } catch (const exception & e) {
141  TP_LOG_FATAL_ID(e.what());
142  return exception_kind(e);
143  }
144  return NO_ERROR;
145  }
146 
147  }
148 
157 
158  namespace ami {
159  template<class T, class CMPR>
160  err sort(stream<T> *instream_ami, stream<T> *outstream_ami,
161  CMPR *cmp, progress_indicator_base* indicator=NULL) {
162  try {
163  TPIE2STL_cmp<T, CMPR> comp(cmp);
164  if (indicator) {
165  tpie::sort(instream_ami->underlying_stream(), outstream_ami->underlying_stream(), comp, *indicator);
166  } else {
167  progress_indicator_null dummy(1);
168  tpie::sort(instream_ami->underlying_stream(), outstream_ami->underlying_stream(), comp, dummy);
169  }
170  } catch (const exception & e) {
171  TP_LOG_FATAL_ID(e.what());
172  return exception_kind(e);
173  }
174  return NO_ERROR;
175  }
176  }
177 
178 // --------------------------------------------------------------------
179 // - -
180 // - These versions used to build a heap on pointers to objects -
181 // - but have been deprecated, since they have been broken for -
182 // - many years and caused unnecessary code duplication. -
183 // - -
184 // --------------------------------------------------------------------
185 
186  namespace ami {
187  template<class T>
188  err ptr_sort(stream<T> *instream_ami, stream<T> *outstream_ami,
189  progress_indicator_base* indicator=NULL) {
190 
191  TP_LOG_WARNING_ID("tpie::ami::ptr_sort is deprecated");
192  return sort(instream_ami, outstream_ami, indicator);
193  }
194  }
195 
196  namespace ami {
197  template<class T, class CMPR>
198  err ptr_sort(stream<T> *instream_ami, stream<T> *outstream_ami,
199  CMPR *cmp, progress_indicator_base* indicator=NULL) {
200  TP_LOG_WARNING_ID("tpie::ami::ptr_sort is deprecated");
201  return sort(instream_ami, outstream_ami, cmp, indicator);
202  }
203  }
204 
205 // ********************************************************************
206 // * *
207 // * This version used to keep a heap of keys and pointers, but has *
208 // * been deprecated since nobody uses it. *
209 // * *
210 // ********************************************************************
211 
212  namespace ami {
213  template<class T, class KEY, class CMPR>
214  err key_sort(stream<T> *instream_ami, stream<T> *outstream_ami,
215  KEY, CMPR *cmp, progress_indicator_base* indicator=NULL) {
216  TP_LOG_WARNING_ID("tpie::ami::key_sort is deprecated");
217  return sort(instream_ami, outstream_ami, cmp, indicator);
218  }
219  }
220 
221 // ********************************************************************
222 // * *
223 // * Duplicates of the above versions that only use 2x space and *
224 // * overwrite the original input stream *
225 // * *
226 // ********************************************************************/
227 
232  namespace ami {
233  template<class T>
234  err sort(stream<T> *instream_ami,
235  progress_indicator_base* indicator=0) {
236  try {
237  if (indicator) {
238  tpie::sort(instream_ami->underlying_stream(), *indicator);
239  } else {
240  progress_indicator_null dummy(1);
241  tpie::sort(instream_ami->underlying_stream(), dummy);
242  }
243  } catch (const exception & e) {
244  TP_LOG_FATAL_ID(e.what());
245  return exception_kind(e);
246  }
247  return NO_ERROR;
248  }
249  }
250 
251 
256  namespace ami {
257  template<class T, class CMPR>
258  err sort(stream<T> *instream_ami,
259  CMPR *cmp, progress_indicator_base* indicator=NULL) {
260  try {
261  TPIE2STL_cmp<T, CMPR> comp(cmp);
262  if (indicator) {
263  tpie::sort(instream_ami->underlying_stream(), comp, *indicator);
264  } else {
265  progress_indicator_null dummy(1);
266  tpie::sort(instream_ami->underlying_stream(), comp, dummy);
267  }
268  } catch (const exception & e) {
269  TP_LOG_FATAL_ID(e.what());
270  return exception_kind(e);
271  }
272  return NO_ERROR;
273  }
274  }
275 
280  namespace ami {
281  template<class T>
282  err ptr_sort(stream<T> *instream_ami,
283  progress_indicator_base* indicator=NULL) {
284  TP_LOG_WARNING_ID("tpie::ami::ptr_sort is deprecated");
285  return sort(instream_ami, indicator);
286  }
287  }
288 
293  namespace ami {
294  template<class T, class CMPR>
295  err ptr_sort(stream<T> *instream_ami,
296  CMPR *cmp, progress_indicator_base* indicator=NULL) {
297  TP_LOG_WARNING_ID("tpie::ami::ptr_sort is deprecated");
298  return sort(instream_ami, cmp, indicator);
299  }
300  }
301 
306  namespace ami {
307  template<class T, class KEY, class CMPR>
308  err key_sort(stream<T> *instream_ami,
309  KEY /*dummykey*/, CMPR *cmp, progress_indicator_base* indicator=NULL) {
310  TP_LOG_WARNING_ID("tpie::ami::key_sort is deprecated");
311  return sort(instream_ami, cmp, indicator);
312  }
313  }
314 
315 } // tpie namespace
316 
317 
318 #endif // __TPIE_SORT_DEPRECATED_H__
The base class for indicating the progress of some task.
Null-object progress indicator.
No error occurred.
Definition: err.h:47
This file contains a few deprecated definitions for legacy code.
Sorting algorithms.
Internal sorter objects.
Merge heap templates.
Conversion between STL and TPIE comparators.
Progress indicator base.
External merge sorting.
err
Legacy TPIE error codes.
Definition: err.h:45
An error occurred at the BTE level.
Definition: err.h:63
void sort(file_stream< T > &instream, file_stream< T > &outstream, Compare comp, progress_indicator_base &indicator)
Sort elements of a stream using the given STL-style comparator object.
Definition: sort.h:59
An attempt was made to read past the end of a stream or write past the end of a substream.
Definition: err.h:52