shapefile.h

Go to the documentation of this file.
00001 
00007 #ifndef INCL_SHAPEFILE
00008 #define INCL_SHAPEFILE  1
00009 
00010 /*
00011 Copyright (C) 2002 The Exult Team
00012 
00013 This program is free software; you can redistribute it and/or
00014 modify it under the terms of the GNU General Public License
00015 as published by the Free Software Foundation; either version 2
00016 of the License, or (at your option) any later version.
00017 
00018 This program is distributed in the hope that it will be useful,
00019 but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 GNU General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; if not, write to the Free Software
00025 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00026 */
00027 
00028 #include <fstream>
00029 #include <string>
00030 #include <vector>
00031 
00032 class Vga_file;
00033 class Shape_group_file;
00034 class Object_browser;
00035 class Shape_group;
00036 class Shape;
00037 class Flex;
00038 
00039 /*
00040  *  A shape file:
00041  */
00042 class Shape_file_info
00043   {
00044 protected:
00045   std::string basename;   // Base filename.
00046   std::string pathname;   // Full pathname.
00047   Shape_group_file *groups; // Groups within ifile.
00048   bool modified;      // Ifile was modified.
00049   Object_browser *browser;  // Widget for seeing this file.
00050 public:
00051   friend class Shape_file_set;
00052           // We will own files and groups.
00053   Shape_file_info(const char *bnm, const char *pnm, Shape_group_file *g)
00054     : basename(bnm), pathname(pnm), groups(g), modified(false),
00055       browser(0)
00056     {  }
00057   virtual ~Shape_file_info();
00058   const char *get_basename()
00059     { return basename.c_str(); }
00060   const char *get_pathname()
00061     { return pathname.c_str(); }
00062   Shape_group_file *get_groups()
00063     { return groups; }
00064   void set_modified()
00065     { modified = true; }
00066   virtual Vga_file *get_ifile()
00067     { return 0; }
00068           // Call this to create group browser.
00069   virtual Object_browser *create_browser(Shape_file_info *vgafile,
00070         unsigned char *palbuf, Shape_group *g)
00071     { return 0; }
00072           // Call for main browser.
00073   virtual Object_browser *get_browser(Shape_file_info *vgafile,
00074         unsigned char *palbuf);
00075   virtual std::ifstream *get_file()
00076     { return 0; }
00077   virtual Flex *get_flex()
00078     { return 0; }
00079   virtual void flush()    // Write if modified.
00080     { modified = false; }
00081   virtual bool revert()
00082     { return false; } // Means 'not supported'.
00083   };
00084 
00085 /*
00086  *  Image file:
00087  */
00088 class Image_file_info : public Shape_file_info
00089   {
00090   Vga_file *ifile;    // Contains the images.
00091 public:
00092           // We will own ifile.
00093   Image_file_info(const char *bnm, const char *pnm, Vga_file *i, 
00094               Shape_group_file *g)
00095     : Shape_file_info(bnm, pnm, g), ifile(i)
00096     {  }
00097   virtual ~Image_file_info();
00098   virtual Vga_file *get_ifile()
00099     { return ifile; }
00100   virtual Object_browser *create_browser(Shape_file_info *vgafile,
00101         unsigned char *palbuf, Shape_group *g = 0);
00102   virtual void flush();   // Write if modified.
00103   virtual bool revert();
00104   static void write_file(const char *pathname, Shape **shapes,
00105             int nshapes, bool single);
00106   };
00107 
00108 /*
00109  *  Chunks file:
00110  */
00111 class Chunks_file_info : public Shape_file_info
00112   {
00113   std::ifstream *file;    // For 'chunks'; ifile is NULL.
00114 public:
00115           // We will own file.
00116   Chunks_file_info(const char *bnm, const char *pnm,
00117       std::ifstream *f, Shape_group_file *g)
00118     : Shape_file_info(bnm, pnm, g), file(f)
00119     {  }
00120   virtual ~Chunks_file_info();
00121   virtual std::ifstream *get_file()
00122     { return file; }
00123   virtual Object_browser *create_browser(Shape_file_info *vgafile,
00124         unsigned char *palbuf, Shape_group *g = 0);
00125   virtual void flush();   // Write if modified.
00126   };
00127 
00128 /*
00129  *  Flex file (used for combos, palettes):
00130  */
00131 class Flex_file_info : public Shape_file_info
00132   {
00133 
00134   Flex *flex;     // NULL if just 1 entry.
00135   std::vector<char *> entries;  // Entries are stored here.
00136   std::vector<int> lengths; // Lengths here.
00137   bool write_flat;    // Write flat file if just 1 entry.
00138 public:
00139           // We will own flex.
00140   Flex_file_info(const char *bnm, const char *pnm,
00141         Flex *fl, Shape_group_file *g);
00142           // Create for single-palette.
00143   Flex_file_info(const char *bnm, const char *pnm, int size);
00144   int size()      // Get # flex entries.
00145     { return entries.size(); }
00146   char *get(int i, size_t& len);  // Get i'th entry.
00147           // Set i'th entry.
00148   void set(int i, char *newentry, int entlen);
00149   void swap(int i);   // Swap entries i, i+1.
00150   void remove(int i);   // Remove i'th entry.
00151   virtual ~Flex_file_info();
00152   virtual Object_browser *create_browser(Shape_file_info *vgafile,
00153         unsigned char *palbuf, Shape_group *g = 0);
00154   virtual Flex *get_flex()
00155     { return flex; }
00156   virtual void flush();   // Write if modified.
00157   virtual bool revert();
00158   };
00159 
00160 /*
00161  *  A set of Shape_file's.
00162  */
00163 class Shape_file_set
00164   {
00165   std::vector<Shape_file_info *> files;
00166   Shape_file_info *append(Shape_file_info *fi)
00167     { files.push_back(fi); return fi; }
00168 public:
00169   Shape_file_set() {  }
00170   ~Shape_file_set();
00171           // Create, or return existing one.
00172   Shape_file_info *create(const char *basename);
00173   int size()
00174     { return files.size(); }
00175   Shape_file_info *operator[](int i)
00176     { return files[i]; }
00177   void flush();     // Write if modified.
00178   bool is_modified();   // Any modified?
00179   };
00180 
00181 #endif

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