# Extent.cc

Go to the documentation of this file.

    00001 // ----------------------------------------------------------------------------
    00002 // CERTI - HLA RunTime Infrastructure
    00003 // Copyright (C) 2003-2005  ONERA
    00004 //
    00005 // This file is part of CERTI-libCERTI
    00006 //
    00007 // CERTI-libCERTI is free software ; you can redistribute it and/or
    00008 // modify it under the terms of the GNU Lesser General Public License
    00009 // as published by the Free Software Foundation ; either version 2 of
    00010 // the License, or (at your option) any later version.
    00011 //
    00012 // CERTI-libCERTI is distributed in the hope that it will be useful, but
    00013 // WITHOUT ANY WARRANTY ; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    00015 // Lesser General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU Lesser General Public
    00018 // License along with this program ; if not, write to the Free Software
    00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    00020 // USA
    00021 //
    00022 // $Id: Extent.cc,v 3.10 2007/07/06 09:25:18 erk Exp $
    00023 // ----------------------------------------------------------------------------
    00024
    00025
    00026 #include "Extent.hh"
    00027 #include "Dimension.hh"
    00028 #include "PrettyDebug.hh"
    00029
    00030 using std::vector ;
    00031
    00032 namespace {
    00033
    00034 PrettyDebug D("EXTENT", __FILE__);
    00035
    00036 }
    00037
    00038 namespace certi {
    00039
    00040 // ----------------------------------------------------------------------------
    00044 Extent::Extent(size_t n)
    00045 {
    00046     Range range(Dimension::getLowerBound(), Dimension::getUpperBound());
    00047     ranges.resize(n, range);
    00048 }
    00049
    00050 // ----------------------------------------------------------------------------
    00053 ULong
    00054 Extent::getRangeLowerBound(DimensionHandle handle) const
    00055     throw (ArrayIndexOutOfBounds)
    00056 {
    00057     if ((handle <= 0) || (handle > ranges.size()))
    00058     throw ArrayIndexOutOfBounds("Invalid dimension handle");
    00059     else
    00060     return ranges[handle - 1].first ;
    00061 }
    00062
    00063 // ----------------------------------------------------------------------------
    00066 ULong
    00067 Extent::getRangeUpperBound(DimensionHandle handle) const
    00068     throw (ArrayIndexOutOfBounds)
    00069 {
    00070     if ((handle <= 0) || (handle > ranges.size()))
    00071     throw ArrayIndexOutOfBounds("Invalid dimension handle");
    00072     else
    00073     return ranges[handle - 1].second ;
    00074 }
    00075
    00076 // ----------------------------------------------------------------------------
    00079 void
    00080 Extent::setRangeLowerBound(DimensionHandle handle, ULong val)
    00081     throw (ArrayIndexOutOfBounds)
    00082 {
    00083     if ((handle <= 0) || (handle > ranges.size()))
    00084     throw ArrayIndexOutOfBounds("Invalid dimension handle");
    00085     else
    00086     ranges[handle - 1].first = val ;
    00087 }
    00088
    00089 // ----------------------------------------------------------------------------
    00092 void
    00093 Extent::setRangeUpperBound(DimensionHandle handle, ULong val)
    00094     throw (ArrayIndexOutOfBounds)
    00095 {
    00096     if ((handle <= 0) || (handle > ranges.size()))
    00097     throw ArrayIndexOutOfBounds("Invalid dimension handle");
    00098     else
    00099     ranges[handle - 1].second = val ;
    00100 }
    00101
    00102 // ----------------------------------------------------------------------------
    00105 size_t
    00106 Extent::size() const
    00107 {
    00108     return ranges.size();
    00109 }
    00110
    00111 // ----------------------------------------------------------------------------
    00114 bool
    00115 Extent::overlaps(const Extent &e) const
    00116 {
    00117     for (unsigned int i = 1 ; i <= size(); ++i) {
    00118     D[pdTrace] << e.getRangeLowerBound(i) << " < " << getRangeUpperBound(i)
    00119            << " or " << e.getRangeUpperBound(i) << " < "
    00120            << getRangeLowerBound(i) << " ?" << std::endl ;
    00121     if (e.getRangeLowerBound(i) > getRangeUpperBound(i) ||
    00122         e.getRangeUpperBound(i) < getRangeLowerBound(i))
    00123         return false ;
    00124     }
    00125     return true ;
    00126 }
    00127
    00128 } // namespace certi
    00129
    00130 // $Id: Extent.cc,v 3.10 2007/07/06 09:25:18 erk Exp $