include/EDocBFD/Section.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003    Copyright (C) 2007 Brendon Costa
00004 
00005    This code 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, or (at your option)
00008    any later version.
00009 
00010    This code 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 this code; see the file COPYING.  If not, write to
00017    the Free Software Foundation, 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 
00020 *******************************************************************************/
00021 #ifndef EDOCBFD_SECTION_H
00022 #define EDOCBFD_SECTION_H
00023 
00024 #include "EDoc/stdint.h"
00025 #include "EDoc/utils.h"
00026 
00027 #include <bfd.h>
00028 #include <string>
00029 
00030 namespace EDocBFD
00031 {
00032    //===========================================================================
00033    /** \brief Used to simplify writing/reading to/from bfd sections.
00034     */
00035    class Section
00036    {
00037    public:
00038 
00039       //------------------------------------------------------------------------
00040       /** \brief Create an instance for the given section of the bfd.
00041        */
00042       Section(bfd* abfd_in, asection* asect_in);
00043 
00044       //------------------------------------------------------------------------
00045       /** \brief Write a char of data to the section.
00046        */
00047       ssize_t Write(unsigned char data);
00048 
00049       //------------------------------------------------------------------------
00050       /** \brief Write data to the given section.
00051        */
00052       ssize_t Write(const void* data, size_t len);
00053 
00054       //------------------------------------------------------------------------
00055       /** \brief Read data from the section.
00056        */
00057       std::string Read(size_t max_size = 0xFFFFFFFF);
00058 
00059       //------------------------------------------------------------------------
00060       /** \brief Read data from the section.
00061        */
00062       std::string ReadEx(size_t max_size = 0xFFFFFFFF);
00063 
00064       //------------------------------------------------------------------------
00065       /** \brief Read data from the section.
00066        */
00067       ssize_t Read(void* sectbuf, size_t max_size);
00068 
00069       //------------------------------------------------------------------------
00070       /** \brief Read data from the section.
00071        */
00072       ssize_t ReadEx(void* sectbuf, size_t max_size);
00073 
00074       //------------------------------------------------------------------------
00075       /** \brief Return true if at the end of the sections data.
00076        */
00077       inline bool IsEof() const
00078       {
00079          return file_pos >= sectsize;
00080       }
00081 
00082       //------------------------------------------------------------------------
00083 
00084    private:
00085 
00086       //------------------------------------------------------------------------
00087       /** \brief The bfd
00088        */
00089       bfd* abfd;
00090 
00091       //------------------------------------------------------------------------
00092       /** \brief The bfds section object.
00093        */
00094       asection* asect;
00095 
00096       //------------------------------------------------------------------------
00097       /** \brief The location of the file pointer in the sections data.
00098        */
00099       size_t file_pos;
00100 
00101       //------------------------------------------------------------------------
00102       /** \brief The total size of the section.
00103        */
00104       size_t sectsize;
00105 
00106       //------------------------------------------------------------------------
00107 
00108    };
00109    //===========================================================================
00110 
00111 }
00112 
00113 #endif // EDOCBFD_SECTION_H

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1