kviewshell
GIFFManager.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _GIFFMANAGER_H
00058 #define _GIFFMANAGER_H
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065
00066
00067 #include "IFFByteStream.h"
00068 #include "GContainer.h"
00069 #include "Arrays.h"
00070 #include "GSmartPointer.h"
00071 #include "GString.h"
00072
00073 #ifdef HAVE_NAMESPACES
00074 namespace DJVU {
00075 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00076 }
00077 #endif
00078 #endif
00079
00080
00103 class GIFFChunk : public GPEnabled
00104 {
00105 protected:
00106 GIFFChunk(void);
00107 GIFFChunk(const GUTF8String &name);
00108 GIFFChunk(const GUTF8String &name, const TArray<char> & data);
00109 public:
00111 static GP<GIFFChunk> create(void) {return new GIFFChunk();}
00112
00115 static GP<GIFFChunk> create(const GUTF8String &name)
00116 {return new GIFFChunk(name);}
00117
00119 static GP<GIFFChunk> create(const GUTF8String &name, const TArray<char> & data)
00120 { return new GIFFChunk(name,data); }
00121
00123 virtual ~GIFFChunk(void);
00124
00126 GUTF8String get_name(void) const;
00128 GUTF8String get_full_name(void) const;
00130 GUTF8String get_type(void) const;
00132 bool is_container(void) const;
00135 void set_name(GUTF8String name);
00138 bool check_name(GUTF8String name);
00139
00144 void add_chunk(const GP<GIFFChunk> & chunk, int order=-1);
00148 void del_chunk(const GUTF8String &name);
00153 GP<GIFFChunk>get_chunk(const GUTF8String &name, int * position=0);
00157 int get_chunks_number(const GUTF8String &name);
00158 int get_chunks_number(void);
00160 TArray<char> get_data(void) const;
00161
00164 void save(IFFByteStream & istr, bool use_trick=0);
00165 private:
00166 char name[5];
00167 GUTF8String type;
00168 GPList<GIFFChunk> chunks;
00169 TArray<char> data;
00170 static GUTF8String decode_name(const GUTF8String &name, int &number);
00171 };
00172
00173 inline GUTF8String
00174 GIFFChunk::get_name(void) const { return GUTF8String(name, 4); }
00175
00176 inline GUTF8String
00177 GIFFChunk::get_type(void) const { return type; }
00178
00179 inline GUTF8String
00180 GIFFChunk::get_full_name(void) const { return get_type()+":"+get_name(); }
00181
00182 inline bool
00183 GIFFChunk::is_container(void) const { return type.length()!=0; }
00184
00185 inline TArray<char>
00186 GIFFChunk::get_data(void) const { return data; }
00187
00188 inline
00189 GIFFChunk::GIFFChunk(void) { name[0]=0; }
00190
00191 inline
00192 GIFFChunk::GIFFChunk(const GUTF8String &name) { set_name(name); }
00193
00194 inline
00195 GIFFChunk::GIFFChunk(const GUTF8String &name, const TArray<char> & data_in) :
00196 data(data_in)
00197 {
00198 set_name(name);
00199 }
00200
00201
00202
00248 class GIFFManager : public GPEnabled
00249 {
00250 protected:
00251 GIFFManager(void);
00252 void init(void);
00253 void init(const GUTF8String &name);
00254 public:
00256 static GP<GIFFManager> create(void);
00257
00261 static GP<GIFFManager> create(const GUTF8String &name);
00262
00264 virtual ~GIFFManager(void);
00265
00267 void set_name(const GUTF8String &name);
00285 void add_chunk(GUTF8String parent_name, const GP<GIFFChunk> & chunk, int pos=-1);
00301 void add_chunk(GUTF8String name, const TArray<char> & data);
00315 void del_chunk(GUTF8String name);
00316 void del_chunk(void);
00330 int get_chunks_number(const GUTF8String &name);
00331 int get_chunks_number(void);
00332
00344 GP<GIFFChunk>get_chunk(GUTF8String name, int * position=0);
00345
00347 void load_chunk(IFFByteStream & istr, GP<GIFFChunk> chunk);
00349 void load_file(GP<ByteStream> str);
00351 void load_file(const TArray<char> & data);
00353 void save_file(GP<ByteStream> str);
00355 void save_file(TArray<char> & data);
00356
00357 private:
00358 GP<GIFFChunk> top_level;
00359
00360 static const char * check_leading_dot(const GUTF8String &name);
00361 private:
00362 static void save_file(ByteStream *);
00363 static void load_file(ByteStream *);
00364 };
00365
00366 inline void
00367 GIFFManager::set_name(const GUTF8String &name)
00368 {
00369 top_level->set_name(name);
00370 }
00371
00372 inline
00373 GIFFManager::GIFFManager(void) {}
00374
00375 inline void
00376 GIFFManager::init(void)
00377 {
00378 top_level=GIFFChunk::create();
00379 }
00380
00381 inline void
00382 GIFFManager::init(const GUTF8String &name)
00383 {
00384 top_level=GIFFChunk::create(name);
00385 }
00386
00387
00388 #ifdef HAVE_NAMESPACES
00389 }
00390 # ifndef NOT_USING_DJVU_NAMESPACE
00391 using namespace DJVU;
00392 # endif
00393 #endif
00394 #endif