1 // -*-c++-*-
2 
3 // fixg2sxd - a utility to convert fig to sxd format
4 
5 // Copyright (C) 2003-2010 Alexander Bürger, acfb@users.sourceforge.net
6 
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 #include "check.h"
22 
23 #include <sstream>
24 #include <iostream>
25 #include <cassert>
26 using namespace std;
27 
28 bool out_of_range_error=true;
29 
30 template<typename T>
keep_range(T & value,const char * name,const T mini,const T maxi)31 void keep_range( T& value, const char* name, const T mini, const T maxi )
32 {
33     assert( mini <= maxi );
34     if( value < mini || value > maxi ) {
35         if( out_of_range_error ) {
36             ostringstream o;
37             o << "Error: " << name << '=' << value << " out of range ["
38               << mini << ',' << maxi << "]";
39             throw o.str();
40         } else {
41             cerr << "Warning: " << name << " was " << value
42                  << " which is out of range [" << mini << ','
43                  << maxi << "]; set to " << mini << '.' << endl;
44             value = mini;
45         }
46     }
47 }
48 
49 template
50 void keep_range<float>( float& v, const char* name, const float l, const float u );
51 
52 template
53 void keep_range<int>( int& v, const char* name, const int l, const int u );
54