Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# BoundsCheck.cpp

    00001 /*
    00002  *             Copyright (C) 2005 Maarten Keijzer
    00003  *
    00004  *          This program is free software; you can redistribute it and/or modify
    00005  *          it under the terms of version 2 of the GNU General Public License as
    00006  *          published by the Free Software Foundation.
    00007  *
    00008  *          This program is distributed in the hope that it will be useful,
    00009  *          but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010  *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00011  *          GNU General Public License for more details.
    00012  *
    00013  *          You should have received a copy of the GNU General Public License
    00014  *          along with this program; if not, write to the Free Software
    00015  *          Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00016  */
    00017
    00018 #include <vector>
    00019
    00020 #include "BoundsCheck.h"
    00021 #include <Sym.h>
    00022 #include <FunDef.h>
    00023 #include <sstream>
    00024
    00025 using namespace std;
    00026
    00027 class IntervalBoundsCheckImpl {
    00028     public :
    00029     vector<Interval> bounds;
    00030 };
    00031
    00032 IntervalBoundsCheck::IntervalBoundsCheck(const vector<double>& mins, const vector<double>& maxes) {
    00033     pimpl = new IntervalBoundsCheckImpl;
    00034     vector<Interval>& b = pimpl->bounds;
    00035
    00036     b.resize( mins.size());
    00037
    00038     for (unsigned i = 0; i < b.size(); ++i) {
    00039         b[i] = Interval(mins[i], maxes[i]);
    00040     }
    00041
    00042 }
    00043
    00044 IntervalBoundsCheck::~IntervalBoundsCheck() { delete pimpl; }
    00045 IntervalBoundsCheck::IntervalBoundsCheck(const IntervalBoundsCheck& that) { pimpl = new IntervalBoundsCheckImpl(*that.pimpl); }
    00046 IntervalBoundsCheck& IntervalBoundsCheck::operator=(const IntervalBoundsCheck& that)   { *pimpl = *that.pimpl; return *this; }
    00047
    00048 bool IntervalBoundsCheck::in_bounds(const Sym& sym) const {
    00049     Interval bounds;
    00050
    00051     try {
    00052         bounds = eval(sym, pimpl->bounds);
    00053         if (!valid(bounds)) return false;
    00054     } catch (interval_error) {
    00055         return false;
    00056     }
    00057     return true;
    00058 }
    00059
    00060 std::string IntervalBoundsCheck::get_bounds(const Sym& sym) const {
    00061
    00062     try {
    00063         Interval bounds = eval(sym, pimpl->bounds);
    00064         if (!valid(bounds)) return "err";
    00065         ostringstream os;
    00066         os << bounds;
    00067         return os.str();
    00068     } catch (interval_error) {
    00069         return "err";
    00070     }
    00071 }
    00072
    00073
    00074 std::pair<double, double> IntervalBoundsCheck::calc_bounds(const Sym& sym) const {
    00075
    00076     Interval bounds = eval(sym, pimpl->bounds);
    00077     return make_pair(bounds.lower(), bounds.upper());
    00078 }
    00079
    00080