~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libaqsistypes/validate.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright � 1997 - 2001, Paul C. Gregory
 
2
//
 
3
// Contact: pgregory@aqsis.com
 
4
//
 
5
// This library is free software; you can redistribute it and/or
 
6
// modify it under the terms of the GNU General Public
 
7
// License as published by the Free Software Foundation; either
 
8
// version 2 of the License, or (at your option) any later version.
 
9
//
 
10
// This library is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
// General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public
 
16
// License along with this library; if not, write to the Free Software
 
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
 
 
20
/** \file
 
21
                \brief Global Aqsis include to include all files required within Aqsis
 
22
                \author Matthaeus G. Chajdas (Matthaeus@darkside-conflict.net)
 
23
*/
 
24
 
 
25
//? Is .h included already?
 
26
#ifndef AQERROR_H_INCLUDED
 
27
#define AQERROR_H_INCLUDED 1
 
28
 
 
29
//! A callback/functor class to perform range checks
 
30
/**
 
31
 * This class is an abstract base class. In order to use the range check
 
32
 * class, you need to derive a class from this (see CqLogRangeCheckCallback in ri.cpp)
 
33
 * The function call takes an argument which is the result of a CheckMinMax function call.
 
34
*/
 
35
 
 
36
class CqRangeCheckCallback
 
37
{
 
38
public:
 
39
    virtual void operator()( int res) = 0;
 
40
    virtual void Call( int res )
 
41
    {
 
42
        this->operator()( res );
 
43
    }
 
44
 
 
45
    enum {      LOWER_BOUND_HIT,
 
46
           UPPER_BOUND_HIT,
 
47
           VALID        }       EqRangeCheck;
 
48
};
 
49
 
 
50
//! Range check funtion using CqRangeCheckCallback
 
51
/**
 
52
 *      Do the range check
 
53
 *
 
54
 *      Calls a CqRangeCheckCallback functor class, which is responsible for the output.
 
55
 *  \return A boolean indicating whether the variable val is inside the range [min,max]
 
56
 */
 
57
template<class T>
 
58
bool CheckMinMax( const T& val, const T& min, const T& max, CqRangeCheckCallback* callBack)
 
59
{
 
60
    if( val < min )
 
61
    {
 
62
        (*callBack)( CqRangeCheckCallback::LOWER_BOUND_HIT );
 
63
        return false;
 
64
    }
 
65
 
 
66
    if( val > max )
 
67
    {
 
68
        (*callBack)( CqRangeCheckCallback::UPPER_BOUND_HIT );
 
69
        return false;
 
70
    }
 
71
 
 
72
    (*callBack)( CqRangeCheckCallback::VALID );
 
73
    return true;
 
74
}
 
75
 
 
76
#endif
 
77