From: stephan b. <sg...@us...> - 2004-12-24 16:23:35
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31114/include/pclasses/System Modified Files: Mime.h Log Message: added readDatabase(istream) and writeDatabase(ostream). Index: Mime.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Mime.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Mime.h 24 Dec 2004 15:13:34 -0000 1.5 +++ Mime.h 24 Dec 2004 16:23:24 -0000 1.6 @@ -121,6 +121,8 @@ @fixme: should not re-insert existing file extension mappings into mimeToFilesMap(). + + @fixme: allow file_ext to e ba space-separated list of extensions. */ void mapExtension(const MimeType& type, const std::string & file_ext ); @@ -143,6 +145,54 @@ const MimeType * findByFileExt(const std::string& fileExt) const; /** + UNTESTED. + + For each file extension mapping for key, the extension is + push_back()'d to target. + + Returns the number of items added to target. + + ListT must be compatible with std::list<std::string>. + */ + template <typename ListT> + size_t extensionsForMimeType( const MimeType & key, ListT & target ) const + { + MimeToFilesMap::const_iterator it = mimeToFilesMap().lower_bound( key ), + et = mimeToFilesMap().upper_bound( key ); + size_t count = 0; + for( ; et != it; ++it ) + { + ++count; + target.push_back( (*it).second ); + } + return count; + } + + /** + UNTESTED. + + For each mime type associated with the given extension, the mime type is + push_back()'d to target. + + Returns the number of items added to target. + + ListT must be compatible with std::list<MimeType>. + */ + template <typename ListT> + size_t mimeTypesForExtension( const std::string & ext, ListT & target ) const + { + FileToMimesMap::const_iterator it = fileToMimesMap().lower_bound( ext ), + et = mimeToFilesMap().upper_bound( ext ); + size_t count = 0; + for( ; et != it; ++it ) + { + ++count; + target.push_back( (*it).second ); + } + return count; + } + + /** An iterator to the first string-to-mime map entry. */ inline const_iterator begin() const @@ -201,6 +251,20 @@ const FileToMimesMap & fileToMimesMap() const { return this->m_rexts; } + /** + Writes the current database state to the given ostream, + using the conventional mime.types db format. + */ + void writeDatabase( std::ostream & ); + + /** + Parses in a mime.types-format file from the given stream. + Returns the number of mime type entries parsed from the + stream. + */ + size_t readDatabase( std::istream & ); + + void clear(); private: MimeTypeMap m_types; |