Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

pmime.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2004  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library 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 GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _pmime_h_
00021 #define _pmime_h_
00022 
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/psingleton.h>
00025 #include <vector>
00026 #include <string>
00027 #include <map>
00028 
00029 namespace P {
00030 
00032 
00036 class PIO_EXPORT MimeType {
00037   public:
00039     typedef std::vector<std::string> FileExtVector;
00040   
00042 
00047     MimeType(const std::string& mediaType, const std::string& subType,
00048              const FileExtVector& fileExts);
00049              
00050     ~MimeType();
00051     
00053     inline const std::string mimeType() const
00054     { return m_mediaType + "/" + m_subType; }
00055     
00057     inline const std::string& mediaType() const
00058     { return m_mediaType; }
00059     
00061     inline const std::string& subType() const
00062     { return m_subType; }
00063     
00065     inline const FileExtVector& fileExts() const
00066     { return m_fileExts; }
00067     
00068   private:
00069     std::string    m_mediaType;
00070     std::string    m_subType;
00071     FileExtVector  m_fileExts;
00072 };
00073 
00074 
00076 
00081 class PIO_EXPORT MimeTypeDb: 
00082   public Singleton<MimeTypeDb, CriticalSection> 
00083 {
00084   public:
00085     typedef std::multimap<
00086       std::string,MimeType
00087     >::const_iterator const_iterator;
00088   
00090     bool add(const MimeType& type);
00091     
00093     MimeType* findByMimeType(const std::string& mimeType) const;
00094 
00096     MimeType* findByFileExt(const std::string& fileExt) const;
00097 
00098     inline const_iterator begin() const
00099     { return m_types.begin(); }
00100 
00101     inline const_iterator end() const
00102     { return m_types.end(); }
00103 
00104   protected:
00105     friend class Singleton<MimeTypeDb, CriticalSection>;
00106 
00107     MimeTypeDb();
00108     ~MimeTypeDb();
00109 
00110   private:
00111     void insert(const MimeType& type);
00112     void readMimeTypes();
00113 
00114     std::multimap<
00115       std::string,
00116       MimeType>      m_types;
00117 };
00118 
00119 }
00120 
00121 #endif

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3