00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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