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

Beesnest/DcRetrieveFile.h

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 /* DcRetrieveFile.h: interface for the CdcRetrieveFile class. */
00021 
00022 #ifndef __CDC_RETRIEVE_FILE
00023 #define __CDC_RETRIEVE_FILE
00024 
00025 /* Includes... */
00026 #include "DcGlobals.h"
00027 #include "DcBuffer.h"
00028 #include "DcExceptionFile.h"
00029 #include "DcFileCacher.h"
00030 #include "DcFileAttrib.h"
00031 
00032 /**
00033  * This class gets a URL string, and a Host string in it's Constructor, and
00034  * retrieve the proper file for this request. Each host's files are in a
00035  * different folder.
00036  *
00037  * The user can get the data as a CdcBuffer by calling
00038  * <b>CdcRetrieveFile::GetData</b>. The class opens the file just in this
00039  * function.
00040  *
00041  * <p>
00042  * To avoid exceptions, before asking for the file, the user should call
00043  * <b>CdcRetrieveFile::IsFileFound</b>.
00044  *
00045  * <p>
00046  * @author Erez Bibi
00047  * @version 1.1
00048  */
00049 class CdcRetrieveFile
00050 {
00051 private:
00052     /** The file's Attributes. */
00053     CdcFileAttrib oFileAttrib;
00054 
00055     /** The file to read. */
00056     ifstream oFile;
00057 
00058     /** Static file cacher object. */
00059     static CdcFileCacher oFileCache;
00060 
00061 public:
00062     /**
00063      * Constructor - finds the file that should be returned by this URL, and
00064      * gets it's system parameters. It also finds the file type.
00065      * <p>
00066      * @param u The URL, as a string
00067      * @param h The host that is trying to get the file.
00068      * @param inc True if this is an include file.
00069      */
00070     CdcRetrieveFile (const CdcString& u, const CdcString& h, bool inc = false)
00071     : oFileAttrib (u, h, inc) {}
00072 
00073     /**
00074      * Destructor - Close file.
00075      */
00076     virtual ~CdcRetrieveFile ()
00077     { if (oFile.is_open ()) oFile.close (); }
00078 
00079     /**
00080      * Return a copy of the file attributes object.
00081      * <p>
00082      * @return (CdcFileAttrib) Shallow copy of the file attributes object.
00083      *  This is a read only object.
00084      */
00085      CdcFileAttrib GetFileAttrib () const { return oFileAttrib; }
00086 
00087     /**
00088      * This function reads a file, and builds a buffer (CdcBuffer) that contains
00089      * the data in the file.
00090      * <p>
00091      * @return (CdcBuffer) The buffer that holds the file data.
00092      * @throw (CdcException) FILE NOT FOUND if it cannot find the file under the
00093      * root directory of the host.
00094      */
00095      CdcBuffer GetData () throw (CdcException);
00096 
00097     /**
00098      * Init is just for the File Cacher.
00099      */
00100     static void Init () { oFileCache.Init (); }
00101 };
00102 
00103 #endif /* __CDC_RETRIEVE_FILE */
00104 
00105 

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