00001
00007 #ifndef INCL_SHAPEFILE
00008 #define INCL_SHAPEFILE 1
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00041
00042 class Shape_file_info
00043 {
00044 protected:
00045 std::string basename;
00046 std::string pathname;
00047 Shape_group_file *groups;
00048 bool modified;
00049 Object_browser *browser;
00050 public:
00051 friend class Shape_file_set;
00052
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
00069 virtual Object_browser *create_browser(Shape_file_info *vgafile,
00070 unsigned char *palbuf, Shape_group *g)
00071 { return 0; }
00072
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()
00080 { modified = false; }
00081 virtual bool revert()
00082 { return false; }
00083 };
00084
00085
00086
00087
00088 class Image_file_info : public Shape_file_info
00089 {
00090 Vga_file *ifile;
00091 public:
00092
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();
00103 virtual bool revert();
00104 static void write_file(const char *pathname, Shape **shapes,
00105 int nshapes, bool single);
00106 };
00107
00108
00109
00110
00111 class Chunks_file_info : public Shape_file_info
00112 {
00113 std::ifstream *file;
00114 public:
00115
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();
00126 };
00127
00128
00129
00130
00131 class Flex_file_info : public Shape_file_info
00132 {
00133
00134 Flex *flex;
00135 std::vector<char *> entries;
00136 std::vector<int> lengths;
00137 bool write_flat;
00138 public:
00139
00140 Flex_file_info(const char *bnm, const char *pnm,
00141 Flex *fl, Shape_group_file *g);
00142
00143 Flex_file_info(const char *bnm, const char *pnm, int size);
00144 int size()
00145 { return entries.size(); }
00146 char *get(int i, size_t& len);
00147
00148 void set(int i, char *newentry, int entlen);
00149 void swap(int i);
00150 void remove(int i);
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();
00157 virtual bool revert();
00158 };
00159
00160
00161
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
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();
00178 bool is_modified();
00179 };
00180
00181 #endif