cWebshots.h

Go to the documentation of this file.
00001 /*
00002     cWebshots - Webshots files handling classes
00003     Copyright (C) 2005  Hervé "Setaou" BRY <uwc at apinc dot org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 
00025 #ifndef __CWEBSHOTS_H
00026 #define __CWEBSHOTS_H
00027 
00028 
00029 #include <vector>
00030 #include <string>
00031 #include <fstream>
00032 
00036 namespace cWebshots
00037 {
00038 
00039         using namespace std;
00040 
00041         //----------------------------------------------------------
00042         // Constants
00043         //----------------------------------------------------------
00044 
00045         // File type marker
00046         const unsigned long WBC_File_Marker    = 0x95FA16AB;    
00047         const unsigned long WBC_Unit_Marker    = 0xF071CDE2;    
00048         const unsigned long WBZ_File_Marker    = 0x6791AB43;    
00049         const unsigned long WBZ_Element_Marker = 0x1082CDE1;    
00050         const unsigned long JFIF_File_Marker   = 0xE0FFD8FF;    
00051         const unsigned long EXIF_File_Marker   = 0xE1FFD8FF;    
00052         const unsigned long WB1_File_Marker    = 0x42425757;    
00053         const unsigned long TXT_File_Marker    = 0x6E756F63;    
00054 
00056         enum Webshots_Formats
00057         {
00058                 WB1,            
00059                 WBC,            
00060                 WBZ,            
00061                 JPG,            
00062                 Folder,         
00063                 Unknown         
00064         };
00065 
00066         // ----------------------------------------------------------
00067         //  Class cWebshotsPicture          
00068         //  ~~~~~~~~~~~~~~~~~~~~~~
00069         //  Members are defined in cWebshotsPicture.cpp
00070         // ----------------------------------------------------------
00071 
00075         class cWebshotsPicture
00076         {
00077         private:
00078                 char *JPGFile;                          
00079                 long JPGFile_Size;                      
00080                 char *BMPThumbnail;                     
00081                 long BMPThumbnail_Size;         
00082 
00083                 void LoadWB1(ifstream &in_file);
00084 
00085                 void LoadMetaDataTXT(string file);
00086 
00087         public:
00088                 ~cWebshotsPicture(void);
00089                 cWebshotsPicture(void);
00090                 cWebshotsPicture(const cWebshotsPicture& source);
00091 
00092                 cWebshotsPicture& operator=(const cWebshotsPicture& source);
00093 
00094                 void Clear();
00095 
00096                 void LoadFromFile(string File);
00097                 void LoadFromMemory(const char *data, long size);
00098                 void SaveToFile(string file, Webshots_Formats format = JPG) const;
00099 
00100                 char *PicturePtr() const;
00101                 long PictureSize() const;
00102                 char *ThumbnailPtr() const;
00103                 long ThumbnailSize() const;
00104 
00105                 long ID;                                        
00106                 string Original_Filename;       
00107                 string Title;                           
00108                 string Caption;                         
00109                 string Credits;                         
00110 
00111                 string Category;                        
00112                 string Album;                           
00113                 string AlbumID;                         
00114 
00115                 string Source;                          
00116                 long DailyDate;                         
00117                 long AdditionDate;                      
00118         };
00119 
00120 
00121         // ----------------------------------------------------------
00122         //  Class cWebshotsTXT
00123         //  ~~~~~~~~~~~~~~~~~~~~~~
00124         //  Members are defined in cWebshotsTXT.cpp
00125         // ----------------------------------------------------------
00126 
00128         struct sPhotosTXT
00129         {
00130                 long id;                                        
00131                 string position;                        
00132                 string title;                           
00133                 string caption;                         
00134                 string credit;                          
00135                 string url_photo;                       
00136                 string url_thumb;                       
00137                 string source;                          
00138         };
00139 
00141         struct sAlbumTXT
00142         {
00143                 string id;                                      
00144                 string title;                           
00145                 int photo_count;                        
00146                 bool in_use;                            
00147                 string description;                     
00148                 string topic_name;                      
00149                 long create_date;                       
00150                 long edit_date;                         
00151         };
00152 
00156         class cWebshotsTXT
00157         {
00158         private:
00159                 sPhotosTXT *Pictures;           
00160                 int Count;                                      
00161 
00162         public:
00163                 cWebshotsTXT(void);
00164                 cWebshotsTXT(string directory);
00165                 ~cWebshotsTXT(void);
00166 
00167                 void Load(string directory);
00168 
00169                 sPhotosTXT& Picture(int index);
00170                 int PictureCount();
00171 
00172                 int IndexFromFileName(string filename, bool case_sensitive = false);
00173 
00174                 sAlbumTXT Album;                        
00175 
00176                 static const int IndexNotFound = -1;    
00177         };
00178 
00179 
00180         // ----------------------------------------------------------
00181         //  Class cWesbshotsCollection
00182         //  ~~~~~~~~~~~~~~~~~~~~~~
00183         //  Members are defined in cWebshotsCollection.cpp
00184         // ----------------------------------------------------------
00185 
00189         class cWebshotsCollection
00190         {
00191         private:
00192                 vector<cWebshotsPicture*> Pictures;             
00193 
00194                 void LoadWBCFile(ifstream &in_file);
00195                 void LoadWBZFile(ifstream &in_file);
00196 
00197                 void SaveWBCFile(ofstream &out_file) const;
00198                 void SaveWBZFile(ofstream &out_file) const;
00199 
00200         public:
00201                 cWebshotsCollection(const cWebshotsCollection& source);
00202                 cWebshotsCollection();
00203 
00204                 cWebshotsCollection& operator=(const cWebshotsCollection& source);
00205                 cWebshotsCollection& operator+=(const cWebshotsCollection& source);
00206                 cWebshotsCollection& operator=(const cWebshotsPicture& source);
00207                 cWebshotsCollection& operator+=(const cWebshotsPicture& source);
00208 
00209                 cWebshotsPicture& operator[](const int Index);
00210                 const cWebshotsPicture& operator[](const int Index) const;
00211 
00212                 friend cWebshotsCollection operator+(const cWebshotsCollection& col1, const cWebshotsCollection& col2);
00213                 friend cWebshotsCollection operator+(const cWebshotsPicture& pic, const cWebshotsCollection& col);
00214                 friend cWebshotsCollection operator+(const cWebshotsCollection& col, const cWebshotsPicture& pic);
00215                 friend cWebshotsCollection operator+(const cWebshotsPicture& pic1, const cWebshotsPicture& pic2);
00216 
00217                 string Title;                   
00218                 string Description;             
00219                 string Topic;                   
00220                 string ID;                              
00221                 bool In_Use;                    
00222                 long CreateDate;                
00223                 long EditDate;                  
00224 
00225                 void LoadFromFile(const string File);
00226                 void LoadFromFolder(const string Path);
00227 
00228                 void SaveToFile(const string File, Webshots_Formats Format) const;
00229                 void SaveToFolder(const string Path) const;
00230 
00231                 cWebshotsPicture& Picture(int Index);
00232                 const cWebshotsPicture& Picture(int Index) const;
00233 
00234                 cWebshotsPicture& AddPicture();
00235                 cWebshotsPicture& AddPicture(const cWebshotsPicture& Picture);
00236 
00237                 void RemovePicture(const int Index);
00238                 void Clear();
00239 
00240                 int PictureCount() const;
00241         };
00242 
00243         //----------------------------------------------------------
00244         // Structures
00245         //----------------------------------------------------------
00246 
00248         struct sWBC_Header
00249         {
00250                 long File_Marker;                       
00251                 long Header_Size;                       
00252                 long unknown;                           
00253                 char File_Title[256];           
00254         };
00255 
00257         struct sWBC_Index
00258         {
00259                 long Unit_Position;                     
00260                 long Unit_Size;                         
00261                 long unknown;                           
00262                 long Addition_TimeStamp;        
00263                 char unknown2[24];                      
00264         };
00265 
00267         struct sWBC_Unit_Header
00268         {
00269                 long Unit_Marker;                       
00270                 long Header_Size;                       
00271                 long Unit_Size;                         
00272                 char Original_Filename[256];    
00273                 char Title[128];                        
00274                 char Description[256];          
00275                 char Credits[256];                      
00276                 char Extension[8];                      
00277                 long JPG_File_Size;                     
00278                 long BMP_Thumbnail_Size;        
00279                 char Unknown[140];                      
00280                 long Daily_Date;                        
00281                 long Addition_Timestamp;        
00282                 long Fit_To_Screen;                     
00283                 char ID[128];                           
00284                 char Album[96];                         
00285                 char Category[256];                     
00286                 char Unknown2[532];                     
00287         };
00288 
00290         struct sWBZ_Header
00291         {
00292                 long File_Marker;                       
00293                 long Header_Size;                       
00294                 long unknown1;                          
00295                 long Header_Version;            
00296                 long unknown3;                          
00297                 long Element_Count;                     
00298                 char unknown4[128];                     
00299         };
00300 
00302         struct sWBZ_Element_Header
00303         {
00304                 long Element_Marker;            
00305                 long Header_Size;                       
00306                 long Header_Version;            
00307                 char File_Name[256];            
00308                 long File_Size;                         
00309                 long unknown2;                          
00310                 long File_Size2;                        
00311                 char unknown4[256];                     
00312         };
00313 
00314         //----------------------------------------------------------
00315         // Exceptions
00316         //----------------------------------------------------------
00317         
00319         namespace Exceptions
00320         {
00322                 class Exception
00323                 {
00324                 private:
00325                         string strDescription;
00326 
00327                 public:
00328                         Exception()
00329                         {
00330                                 strDescription = "Unknown error !";
00331                         };
00332 
00333                         Exception(string _Description)
00334                         {
00335                                 strDescription = _Description;
00336                         };
00337 
00338                         string Description()
00339                         {
00340                                 return strDescription;
00341                         };
00342                 };
00343 
00345                 class FileSystemError : public Exception
00346                 {
00347                 public:
00348                         FileSystemError(string _Description) : Exception(_Description) {};
00349                 };
00350 
00352                 class DataError : public Exception
00353                 {
00354                 public:
00355                         DataError(string _Description) : Exception(_Description) {};
00356                 };
00357 
00359                 class UnknownFormat : public DataError
00360                 {
00361                 public:
00362                         UnknownFormat(string _Description) : DataError(_Description) {};
00363                 };
00364 
00366                 class CorruptedData : public DataError
00367                 {
00368                 public:
00369                         CorruptedData(string _Description) : DataError(_Description) {};
00370                 };
00371 
00373                 class OutOfRange : public Exception
00374                 {
00375                 public:
00376                         OutOfRange(string _Description) : Exception(_Description) {};
00377                 };
00378         }
00379 
00380         //----------------------------------------------------------
00381         // Misc
00382         //----------------------------------------------------------
00383 
00384         string GetFileName(string path);
00385         string GetDirectory(string path);
00386 
00387         Webshots_Formats IdentifyFile(string File);
00388         Webshots_Formats IdentifyFile(ifstream &in_file);
00389 
00390         void Tokenize(const string& str, vector<string>& tokens, const string& delimiters);
00391         string GetINI(const string &Data, const string &Section, const string &Field);
00392         string IntToStr(const int &i);
00393         long StrToLong(const string &s);
00394 }
00395 
00396 
00397 #endif

Generated on Tue Oct 25 14:36:29 2005 for cWebshots by  doxygen 1.4.5