Update of /cvsroot/pclasses/pclasses2/include/pclasses/System
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17916/include/pclasses/System
Modified Files:
Mime.h
Log Message:
major reworks
Index: Mime.h
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Mime.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Mime.h 24 Dec 2004 04:06:27 -0000 1.4
+++ Mime.h 24 Dec 2004 15:13:34 -0000 1.5
@@ -47,7 +47,13 @@
\param subType MIME sub type
\param fileExts vector of associated file extensions
*/
- MimeType(const std::string& mediaType, const std::string& subType );
+ MimeType(const std::string & mediaType, const std::string& subType );
+
+ /**
+ If media_subtype is not a valid media/subtype string
+ then this function is equivalent to the default ctor.
+ */
+ explicit MimeType( const std::string & media_subtype );
~MimeType();
@@ -93,47 +99,114 @@
class /* PIO_EXPORT */ MimeTypeDb
{
public:
- typedef std::multimap< std::string, MimeType > MimeTypeMap;
+ /**
+ Map of "media/sybtype" strings to MimeType.
+ */
+ typedef std::map< std::string, MimeType > MimeTypeMap;
typedef MimeTypeMap::const_iterator const_iterator;
- typedef std::multimap< MimeType, std::string > FileExtensionsMap;
/**
Add MIME type to database. Does not re-insert if type is
already in the db.
+
*/
bool add(const MimeType& type);
+
+ /**
+ Maps the given MimeType to the given file extension.
+
+ This function does not call add(type), though it arguably
+ should.
+
+ @fixme: should not re-insert existing file extension mappings
+ into mimeToFilesMap().
+ */
+ void mapExtension(const MimeType& type, const std::string & file_ext );
- //! Find MIME type by full name
- MimeType* findByMimeType(const std::string& mimeType) const;
+ /**
+ Find MIME type by "media/subtype" string.
- //! Find MIME type by file extension
- MimeType* findByFileExt(const std::string& fileExt) const;
+ Returns 0 if none is mapped.
+
+ */
+ const MimeType * findByMimeType(const std::string& mimeType) const;
+
+ /**
+ Find MIME type by file extension.
+
+ Returns 0 if none is mapped.
+
+ Achtung: it returns only the first of possibly multiple
+ matches.
+ */
+ const MimeType * findByFileExt(const std::string& fileExt) const;
+ /**
+ An iterator to the first string-to-mime map entry.
+ */
inline const_iterator begin() const
{ return m_types.begin(); }
+ /**
+ An iterator to the after-the-end string-to-mime map entry.
+ */
inline const_iterator end() const
{ return m_types.end(); }
- FileExtensionsMap & extensionsMap()
- { return this->m_exts; }
-
- const FileExtensionsMap & extensionsMap() const
- { return this->m_exts; }
MimeTypeDb();
~MimeTypeDb();
+ /**
+ Returns the string-to-Mime map.
+ */
MimeTypeMap & typeMap()
{ return this->m_types; }
+ /**
+ Returns the string-to-Mime map.
+ */
const MimeTypeMap & typeMap() const
{ return this->m_types; }
+ /**
+ Returns a shared instance of this object.
+ This instance reads mime types data
+ from a platform-specific database,
+ e.g. /etc/mime.types.
+ */
static MimeTypeDb & instance();
+ /**
+ Map of MimeType to file extensions (strings).
+ */
+ typedef std::multimap< MimeType, std::string > MimeToFilesMap;
+
+ /**
+ Returns the Mime-to-File extensions map.
+ */
+ const MimeToFilesMap & mimeToFilesMap() const
+ { return this->m_exts; }
+
+ /**
+ A reverse mapping of MimeToFilesMap, to ease some
+ implementation code.
+ */
+ typedef std::multimap< std::string, MimeType > FileToMimesMap;
+
+ /**
+ Returns the File extension-to-Mime map.
+ */
+ const FileToMimesMap & fileToMimesMap() const
+ { return this->m_rexts; }
+
+
private:
+ MimeTypeMap m_types;
+ MimeToFilesMap m_exts;
+ FileToMimesMap m_rexts;
+
/** For use with P::Phoenix. */
struct init_functor
{
@@ -146,10 +219,22 @@
};
/** Like add(), but this inserts regardless of duplication. */
void insert(const MimeType& type);
- MimeTypeMap m_types;
- FileExtensionsMap m_exts;
};
} } // P::System
+#include "pclasses/Factory.h"
+#include "pclasses/SharingContext.h"
+namespace P {
+
+namespace System
+{
+ template <typename InterfaceT>
+ class MimeHandlerFactory : public ::P::Factory< InterfaceT, MimeType,::P::Sharing::MimeContext >
+ {
+
+ };
+
+} } // P::System
+
#endif
|