blitz  Version 0.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extremum.h
Go to the documentation of this file.
1 /***************************************************************************
2  * blitz/extremum.h Declaration of the Extremum<T_numtype, T_index> class
3  *
4  * $Id: extremum.h,v 1.4 2003/12/11 03:44:22 julianc Exp $
5  *
6  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program 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
16  * GNU General Public License for more details.
17  *
18  * Suggestions: blitz-dev@oonumerics.org
19  * Bugs: blitz-bugs@oonumerics.org
20  *
21  * For more information, please see the Blitz++ Home Page:
22  * http://oonumerics.org/blitz/
23  *
24  ***************************************************************************/
25 
26 #ifndef BZ_EXTREMUM_H
27 #define BZ_EXTREMUM_H
28 
29 #ifndef BZ_BLITZ_H
30  #include <blitz/blitz.h>
31 #endif
32 
33 BZ_NAMESPACE(blitz)
34 
35 // The Extremum class is used for returning extreme values and their
36 // locations in a numeric container. It's a simple 2-tuple, with the
37 // first element being the extreme value, and the send its location.
38 // An object of type Extremum can be automatically converted to
39 // the numeric type via operator T_numtype().
40 template<typename P_numtype, typename P_index>
41 class Extremum {
42 public:
43  typedef P_numtype T_numtype;
44  typedef P_index T_index;
45 
46  Extremum(T_numtype value, T_index index)
47  : value_(value), index_(index)
48  { }
49 
50  T_numtype value() const
51  { return value_; }
52 
53  T_index index() const
54  { return index_; }
55 
56  void setValue(T_numtype value)
57  { value_ = value; }
58 
59  void setIndex(T_index index)
60  { index_ = index; }
61 
62  operator T_numtype() const
63  { return value_; }
64 
65 protected:
66  T_numtype value_;
67  T_index index_;
68 };
69 
71 
72 #endif // BZ_EXTREMUM_H
73