Flex.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2000  Dancer A.L Vesperman
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef __FLEX_H_
00020 #define __FLEX_H_
00021 
00022 #ifndef PENTAGRAM // DONT'T INCLUDE THIS IN PENTAGRAM!
00023 
00024 #include <vector>
00025 #include <string>
00026 #include <iosfwd>
00027 #include "common_types.h"
00028 #include "U7file.h"
00029 
00030 class DataSource;
00031 
00032 
00033 class Flex : public U7file
00034 {
00035 protected:
00036   char  title[80];
00037   uint32  magic1;
00038   uint32  count;
00039   uint32  magic2;
00040   uint32  padding[9];
00041   struct Reference
00042   {
00043     uint32 offset;
00044     uint32 size;
00045     Reference() : offset(0),size(0) {};
00046   };
00047   std::vector<Reference> object_list;
00048 
00049 public:
00050   Flex(const std::string &fname);
00051   Flex(const Flex &f) : magic1(f.magic1),count(f.count),magic2(f.magic2),object_list(f.object_list)
00052     { std::memcpy(title,f.title,sizeof(title));
00053       std::memcpy(padding,f.padding,sizeof(padding)); }
00054   Flex &operator=(const Flex &f)
00055     {
00056       magic1=f.magic1;
00057       count=f.count;
00058       magic2=f.magic2;
00059       object_list=f.object_list;
00060       std::memcpy(title,f.title,sizeof(title));
00061       std::memcpy(padding,f.padding,sizeof(padding));
00062       return *this;
00063     }
00064     
00065    virtual uint32 number_of_objects(void) { return object_list.size(); };
00066    virtual  char *  retrieve(uint32 objnum,std::size_t &len); // To a memory block
00067   virtual const char *get_archive_type() { return "FLEX"; };
00068           // Write header for a Flex file.
00069   static void write_header(DataSource* out, const char *title, int count);
00070 
00071   static bool is_flex(DataSource *in);
00072   static bool is_flex(const char *fname);
00073 private:
00074   Flex(); // No default constructor
00075   void IndexFlexFile(void);
00076 };
00077 
00078 /*
00079  *  This is for writing out a whole Flex file.
00080  */
00081 class Flex_writer
00082   {
00083   std::ofstream *out;   // What we're writing to.
00084   int count;      // # entries.
00085   int index;      // Current index.
00086   long cur_start;     // Start of cur. entry being written.
00087   uint8 *table;     // Table of offsets & lengths.
00088   uint8 *tptr;      // ->into table.
00089 public:
00090   Flex_writer(std::ofstream &o, const char *title, int cnt);
00091   ~Flex_writer();
00092   void mark_section_done(); // Finished writing out a section.
00093   bool close();     // All done.
00094   };
00095 
00096 #endif // PENTAGRAM
00097 
00098 #endif

Generated on Mon Jul 9 14:42:45 2007 for ExultEngine by  doxygen 1.5.1