Added clarifying comment to CodFileBuilder
[barry.git] / src / cod.h
blobbf932d014f5264148a05f4198cbc069b014a0a2c
1 ///
2 /// \file cod.h
3 /// COD file API
4 ///
6 /*
7 Copyright (C) 2009, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_COD_H__
23 #define __BARRY_COD_H__
25 #include "dll.h"
26 #include "data.h"
27 #include <sys/types.h>
28 #include <iostream>
29 #include <sstream>
31 namespace Barry {
35 // SeekNextCod
37 /// Seeks the input stream to the next packed sibling .cod file and returns
38 /// the packed .cod file size. When all siblings have been read, zero is
39 /// returned.
40 ///
41 /// When input stream does not contain the signature for a packed .cod file,
42 /// it's assumed the entire stream is the .cod file.
43 ///
44 /// \param input stream to read from
45 ///
46 /// \return size of next packed .cod file, or 0 finished reading .cod files
47 ///
48 size_t SeekNextCod(std::istream &input);
51 ///
52 /// The CodFileBuilder class is used to assemble multiple .cod files into
53 /// a single packed .cod file using the pkzip file format.
54 ///
55 class BXEXPORT CodFileBuilder
57 std::string m_module_name;
59 size_t m_module_count;
60 unsigned int m_current_module;
62 std::ostringstream m_directory;
64 public:
65 CodFileBuilder(const std::string &module_name, size_t module_count = 1);
67 ~CodFileBuilder();
69 ///
70 /// Writes packed .cod file header to the output stream, and appends
71 /// an entry to the central directory. If the module count used to
72 /// create CodFileBuilder is equal to one, the call is ignored.
73 ///
74 /// Note: it is the caller's responsibility to write the actual
75 /// COD file data after calling this function.
76 ///
77 /// \param output stream to write to
78 ///
79 /// \param buffer buffered .cod file data, input to CRC-32 function
80 ///
81 /// \param module_size total size of .cod file data
82 ///
83 void WriteNextHeader(std::ostream &output, const uint8_t* buffer,
84 uint32_t module_size);
86 ///
87 /// Write the central directory and central directory ending indicator
88 /// to the output stream.
89 ///
90 /// \param output stream to write to
91 ///
92 void WriteFooter(std::ostream &output);
97 #endif