kviewshell
DjVmDir.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 _DJVMDIR_H
00058 #define _DJVMDIR_H
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065
00066
00116
00117
00118
00119 #include "GString.h"
00120 #include "GThreads.h"
00121
00122 #ifdef HAVE_NAMESPACES
00123 namespace DJVU {
00124 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00125 }
00126 #endif
00127 #endif
00128
00129 class ByteStream;
00130
00152 class DjVmDir : public GPEnabled
00153 {
00154 protected:
00157 DjVmDir(void) { } ;
00158 public:
00159 class File;
00160
00161 static const int version;
00162
00165 static GP<DjVmDir> create(void) {return new DjVmDir; } ;
00166
00168 void decode(const GP<ByteStream> &stream);
00170 void encode(const GP<ByteStream> &stream, const bool do_rename=false) const;
00172 void encode(const GP<ByteStream> &stream, const bool bundled, const bool do_rename) const;
00174 bool is_indirect(void) const;
00176 bool is_bundled(void) const;
00178 GP<File> page_to_file(int page_num) const;
00180 GP<File> name_to_file(const GUTF8String & name) const;
00182 GP<File> id_to_file(const GUTF8String &id) const;
00184 GP<File> title_to_file(const GUTF8String &title) const;
00186 int get_file_pos(const File * f) const;
00188 int get_page_pos(int page_num) const;
00190 GPList<File> resolve_duplicates(const bool save_as_bundled);
00192 GPList<File> get_files_list(void) const;
00194 int get_files_num(void) const;
00196 int get_pages_num(void) const;
00200 GP<File> get_shared_anno_file(void) const;
00202 void set_file_title(const GUTF8String &id, const GUTF8String &title);
00204 void set_file_name(const GUTF8String &id, const GUTF8String &name);
00208 int insert_file(const GP<File> & file, int pos=-1);
00210 void delete_file(const GUTF8String &id);
00211 private:
00212 GCriticalSection class_lock;
00213 GPList<File> files_list;
00214 GPArray<File> page2file;
00215 GPMap<GUTF8String, File> name2file;
00216 GPMap<GUTF8String, File> id2file;
00217 GPMap<GUTF8String, File> title2file;
00218 private:
00219 static void decode(ByteStream *);
00220 static void encode(ByteStream *);
00221 };
00222
00223 class DjVmDir::File : public GPEnabled
00224 {
00225 public:
00226
00227
00228
00229
00244 enum FILE_TYPE { INCLUDE=0, PAGE=1, THUMBNAILS=2, SHARED_ANNO=3 };
00245 protected:
00247 File(void);
00248
00249 public:
00250 static GP<File> create(void) { return new File(); }
00251 static GP<File> create(const GUTF8String &load_name,
00252 const GUTF8String &save_name, const GUTF8String &title,
00253 const FILE_TYPE file_type);
00254
00257 const GUTF8String &check_save_name(const bool as_bundled);
00258
00266 const GUTF8String &get_save_name(void) const;
00267
00272 const GUTF8String &get_load_name(void) const;
00273 void set_load_name(const GUTF8String &id);
00274
00278 const GUTF8String &get_title() const;
00279 void set_title(const GUTF8String &id);
00280
00282 GUTF8String get_str_type(void) const;
00283
00287 int offset;
00288
00292 int size;
00293
00296 bool valid_name;
00297
00299 bool is_page(void) const
00300 {
00301 return (flags & TYPE_MASK)==PAGE;
00302 }
00303
00306 bool is_include(void) const
00307 {
00308 return (flags & TYPE_MASK)==INCLUDE;
00309 }
00310
00312 bool is_thumbnails(void) const
00313 {
00314 return (flags & TYPE_MASK)==THUMBNAILS;
00315 }
00316
00319 bool is_shared_anno(void) const
00320 { return (flags & TYPE_MASK)==SHARED_ANNO; }
00321
00322 int get_page_num(void) const
00323 { return page_num; }
00324 protected:
00325 GUTF8String name;
00326 GUTF8String oldname;
00327 GUTF8String id;
00328 GUTF8String title;
00329 void set_save_name(const GUTF8String &name);
00330 private:
00331 friend class DjVmDir;
00332 enum FLAGS_0 { IS_PAGE_0=1, HAS_NAME_0=2, HAS_TITLE_0=4 };
00333 enum FLAGS_1 { HAS_NAME=0x80, HAS_TITLE=0x40, TYPE_MASK=0x3f };
00334 unsigned char flags;
00335 int page_num;
00336 };
00337
00338 inline const GUTF8String &
00339 DjVmDir::File::get_load_name(void) const
00340 { return id; }
00341
00342 inline const GUTF8String &
00343 DjVmDir::File::get_title() const
00344 { return *(title.length()?&title:&id); }
00345
00346 inline void
00347 DjVmDir::File::set_title(const GUTF8String &xtitle) { title=xtitle; }
00348
00421
00422
00423
00424
00425
00426
00427 inline bool
00428 DjVmDir::is_bundled(void) const
00429 {
00430 return ! is_indirect();
00431 }
00432
00433 inline bool
00434 DjVmDir::is_indirect(void) const
00435 {
00436 GCriticalSectionLock lock((GCriticalSection *) &class_lock);
00437 return ( files_list.size() && files_list[files_list] != 0 &&
00438 files_list[files_list]->offset==0 );
00439 }
00440
00441
00442
00443
00444
00445 #ifdef HAVE_NAMESPACES
00446 }
00447 # ifndef NOT_USING_DJVU_NAMESPACE
00448 using namespace DJVU;
00449 # endif
00450 #endif
00451 #endif