Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

LinearExtent.cxx

00001 /*
00002  * Copyright (C) 1991-9 Eric M. Hopper <hopper@omnifarious.mn.org>
00003  * 
00004  *     This program is free software; you can redistribute it and/or modify it
00005  *     under the terms of the GNU Lesser General Public License as published
00006  *     by the Free Software Foundation; either version 2 of the License, or
00007  *     (at your option) any later version.
00008  * 
00009  *     This program is distributed in the hope that it will be useful, but
00010  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *     Lesser General Public License for more details.
00013  * 
00014  *     You should have received a copy of the GNU Lesser General Public
00015  *     License along with this program; if not, write to the Free Software
00016  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 /* $Header: /home/hopper/src/cvs/C++/StrMod/LinearExtent.cxx,v 1.8 2002/09/16 02:23:52 hopper Exp $ */
00020 
00021 // $Revision: 1.8 $
00022 
00023 // For a change log, see ChangeLog
00024 //
00025 // Revision 1.3  1996/09/21 18:40:12  hopper
00026 // Changed LinearExtent::SubExtent_eq to return const LinearExtent & to
00027 // be more like x= operators.
00028 //
00029 // Revision 1.2  1996/06/29 06:42:21  hopper
00030 // Added const qualifier.
00031 // New function SubExtent_eq, in place SubExtent calc.
00032 //
00033 // Revision 1.1  1996/05/08 11:16:47  hopper
00034 // First functional revision
00035 //
00036 
00037 #ifdef __GNUG__
00038 #  pragma implementation "LinearExtent.h"
00039 #endif
00040 
00041 #include <StrMod/LinearExtent.h>
00042 #include <climits>
00043 
00044 namespace strmod {
00045 namespace strmod {
00046 
00047 const LinearExtent LinearExtent::full_extent(0, LinearExtent::LENGTH_MAX);
00048 
00049 const LinearExtent LinearExtent::SubExtent(const LinearExtent &extent) const
00050 {
00051    if (extent.m_offset > m_length) {
00052       return(LinearExtent(m_offset + m_length, 0));
00053    } else {
00054       off_t newoff = m_offset + extent.m_offset;
00055 
00056       if ((extent.m_offset + extent.m_length) > m_length) {
00057          return(LinearExtent(newoff, m_length - extent.m_offset));
00058       } else {
00059          return(LinearExtent(newoff, extent.m_length));
00060       }
00061    }
00062 }
00063 
00064 const LinearExtent &LinearExtent::SubExtent_eq(const LinearExtent &extent)
00065 {
00066    if (this == &extent)
00067    {
00068       *this = SubExtent(extent);
00069    }
00070    else
00071    {
00072       if (extent.m_offset > m_length) {
00073          m_offset += m_length;
00074          m_length = 0;
00075       } else {
00076          m_offset += extent.m_offset;
00077          if ((extent.m_offset + extent.m_length) > m_length) {
00078             m_length -= extent.m_offset;
00079          } else {
00080             m_length = extent.m_length;
00081          }
00082       }
00083    }
00084    return(*this);
00085 }
00086 
00087 void LinearExtent::LengthenLeft(length_t by)
00088 {
00089    if (m_offset < by) {
00090       by = m_offset;
00091    }
00092 
00093    m_length += by;
00094    m_offset -= by;
00095 }
00096 
00097 void LinearExtent::ShortenLeft(length_t by)
00098 {
00099    if (m_length < by) {
00100       by = m_length;
00101    }
00102 
00103    m_length -= by;
00104    m_offset += by;
00105 }
00106 
00107 }  // End namespace strmod
00108 }  // End namespace strmod

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1