• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/DcBuffersList.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 
00005 Beesnest is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 Beesnest is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with Beesnest; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 /**
00021  * CdcBuffersLiat.cpp: implementation of the CdcBuffersList class.
00022  * for documentation see the header file.
00023  */
00024 
00025 #include "DcBuffersList.h"
00026 
00027 void CdcBuffersList::Clear ()
00028 {
00029     oIter = oBuffList.end ();
00030     oBuffList.clear ();
00031 }
00032 
00033 void CdcBuffersList::Add (const CdcBuffer& buff, const CdcFileAttrib& attr,
00034     int offset, int length)
00035 {
00036     /* Check offset + length is less then total buffer length. */
00037     if (offset + length <= buff.GetDataSize ())
00038         oBuffList.insert (oIter, CdcBuffersList::Buff (buff, attr, offset,
00039             length));
00040 }
00041 
00042 void CdcBuffersList::Insert (const CdcBuffer& buff, int start, int length)
00043 {
00044     if (oIter == oBuffList.end ()) return;          /* Empty list */
00045     if (start > (*oIter).nLength) return;           /* Invalid start point. */
00046     if (length > (*oIter).nLength - start) return;  /* Invalid length. */
00047 
00048     /* Keep copy of current buffer for letter use. */
00049     CdcBuffersList::Buff temp_buff = *oIter;
00050     if (start > 0 &&
00051         temp_buff.oBuff.IsWhiteSpaces (temp_buff.nOffset, start) == false)
00052     {   /* We need to keep first part of the current buffer. */
00053         (*oIter).nLength = start - 1;   /* Trim current buffer. */
00054         oIter++;                        /* Go to next buffer (may be .end()). */
00055     }
00056     /* Insert entire new buffer before current one. */
00057     oBuffList.insert (oIter, CdcBuffersList::Buff (buff));
00058 
00059     if (length > -1)    /* Need to push forward scond part of old buffer. */
00060     {
00061         int shift = start + length;
00062         temp_buff.nOffset += shift; /* Here is the new offset piont. */
00063         temp_buff.nLength -= shift; /* And the new length compensate for it. */
00064         if (temp_buff.oBuff.IsWhiteSpaces (temp_buff.nOffset, temp_buff.nLength)
00065             == false)
00066         {
00067             oBuffList.insert (oIter, temp_buff);
00068             oIter--;                /* Go back to point to this second new buffer. */
00069         }
00070     }
00071     oIter--;    /* And in the end point to the inserted buffer. */
00072 }
00073 
00074 bool CdcBuffersList::SeekFirst ()
00075 {
00076     if (oBuffList.empty ())
00077         return false;
00078     oIter = oBuffList.begin ();
00079     return true;
00080 }
00081 
00082 bool CdcBuffersList::SeekNext ()
00083 {
00084     oIter++;
00085     return !(oIter == oBuffList.end ());
00086 }
00087 
00088 t_buff_unit* CdcBuffersList::GetPointer ()
00089 {
00090     if (oIter == oBuffList.end ())  /* Empty list */
00091         return NULL;
00092     return ((*oIter).oBuff.GetPointer () + (*oIter).nOffset);
00093 }
00094 
00095 int CdcBuffersList::GetLength ()
00096 {
00097     if (oIter == oBuffList.end ())  /* Empty list */
00098         return 0;
00099     if ((*oIter).nLength == -1)     /* current buff is entire buffer */
00100         return ((*oIter).oBuff.GetDataSize () - (*oIter).nOffset);
00101     return (*oIter).nLength;
00102 }
00103 
00104 const CdcBuffer* CdcBuffersList::GetBufferPointer ()
00105 {
00106     if (oIter == oBuffList.end ())  /* Empty list */
00107         return NULL;
00108     return &((*oIter).oBuff);
00109 }
00110 
00111 int CdcBuffersList::GetBufferOffset ()
00112 {
00113     if (oIter == oBuffList.end ())  /* Empty list */
00114         return 0;
00115     return (*oIter).nOffset;
00116 }
00117 
00118 int CdcBuffersList::GetDataSize ()
00119 {
00120     int size = 0;
00121     if (SeekFirst () == false)
00122         return size;
00123 
00124     do
00125         size += GetLength ();
00126     while (SeekNext ());
00127     return size;
00128 }
00129 
00130 CdcFileAttrib CdcBuffersList::GetFileAttrib ()
00131 {
00132     if (oIter == oBuffList.end ())  /* Empty list */
00133         return CdcFileAttrib ();    /* Return an empty file-attrib object. */
00134     return (*oIter).oFileAttrib;
00135 }

Generated on Mon Oct 11 2010 16:23:23 for Beesnest by  doxygen 1.7.2