cod.h

Go to the documentation of this file.
00001 ///
00002 /// \file       cod.h
00003 ///             COD file API
00004 ///
00005 
00006 /*
00007     Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_COD_H__
00023 #define __BARRY_COD_H__
00024 
00025 #include "dll.h"
00026 #include "data.h"
00027 #include <sys/types.h>
00028 #include <stdint.h>
00029 #include <iostream>
00030 #include <sstream>
00031 
00032 namespace Barry {
00033 
00034 
00035 //
00036 // SeekNextCod
00037 //
00038 /// Seeks the input stream to the next packed sibling .cod file and returns
00039 /// the packed .cod file size.  When all siblings have been read, zero is
00040 /// returned.
00041 ///
00042 /// When input stream does not contain the signature for a packed .cod file,
00043 /// it's assumed the entire stream is the .cod file.
00044 ///
00045 /// \param input stream to read from
00046 ///
00047 /// \return size of next packed .cod file, or 0 finished reading .cod files
00048 ///
00049 size_t SeekNextCod(std::istream &input);
00050 
00051 
00052 ///
00053 /// The CodFileBuilder class is used to assemble multiple .cod files into
00054 /// a single packed .cod file using the pkzip file format.
00055 ///
00056 class BXEXPORT CodFileBuilder
00057 {
00058         std::string m_module_name;
00059 
00060         size_t m_module_count;
00061         unsigned int m_current_module;
00062 
00063         std::ostringstream m_directory;
00064 
00065 public:
00066         CodFileBuilder(const std::string &module_name, size_t module_count = 1);
00067 
00068         ~CodFileBuilder();
00069 
00070         ///
00071         /// Writes packed .cod file header to the output stream, and appends
00072         /// an entry to the central directory.  If the module count used to
00073         /// create CodFileBuilder is equal to one, the call is ignored.
00074         ///
00075         /// Note: it is the caller's responsibility to write the actual
00076         /// COD file data after calling this function.
00077         ///
00078         /// \param output stream to write to
00079         ///
00080         /// \param buffer buffered .cod file data, input to CRC-32 function
00081         ///
00082         /// \param module_size total size of .cod file data
00083         ///
00084         void WriteNextHeader(std::ostream &output, const uint8_t* buffer,
00085                         uint32_t module_size);
00086 
00087         ///
00088         /// Write the central directory and central directory ending indicator
00089         /// to the output stream.
00090         ///
00091         /// \param output stream to write to
00092         ///
00093         void WriteFooter(std::ostream &output);
00094 };
00095 
00096 }
00097 
00098 #endif
00099