Update of /cvsroot/pclasses/pclasses2/include/pclasses/System
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15318/include/pclasses/System
Added Files:
Mime.h
Log Message:
initial go at a mime rewrite
--- NEW FILE: Mime.h ---
/*
* P::Classes - Portable C++ Application Framework
* Copyright (C) 2000-2004 Christian Prochnow <cp...@se...>
* Copyright (C) 2004-2005 stephan beal <st...@s1...>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _pmime_h_
#define _pmime_h_
#include <pclasses/Phoenix.h>
#include <list>
#include <string>
#include <map>
namespace P { namespace System {
//! MIME type
/*!
\author Christian Prochnow <cp...@se...>
\author stephan beal <st...@s1...>
\ingroup System
*/
class /* PIO_EXPORT */ MimeType {
public:
//! Constructor
/*!
\param mediaType MIME media type
\param subType MIME sub type
\param fileExts vector of associated file extensions
*/
MimeType(const std::string& mediaType, const std::string& subType );
~MimeType();
/**
For compatibility with containers.
Returns false if rhs is this object
or if this object's media- and sub-types
both compare less than those of rhs.
*/
bool operator<( const MimeType & rhs ) const;
/**
For compatibility with containers.
Returns true if this object's media- and sub-types are the
same as rhs'.
*/
bool operator==( const MimeType & rhs ) const;
//! Return the full MIME type
inline const std::string mimeType() const
{ return m_mediaType + "/" + m_subType; }
//! Returns the MIME media type
inline const std::string& mediaType() const
{ return m_mediaType; }
//! Returns the MIME sub type
inline const std::string& subType() const
{ return m_subType; }
private:
std::string m_mediaType;
std::string m_subType;
};
//! MIME type database
/*!
The class is used as an application wide MIME type registry.
\author Christian Prochnow <cp...@se...>
\author stephan beal <st...@s1...>
\ingroup System
*/
class /* PIO_EXPORT */ MimeTypeDb
{
public:
typedef std::multimap<
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);
//! Find MIME type by full name
MimeType* findByMimeType(const std::string& mimeType) const;
//! Find MIME type by file extension
MimeType* findByFileExt(const std::string& fileExt) const;
inline const_iterator begin() const
{ return m_types.begin(); }
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();
MimeTypeMap & typeMap()
{ return this->m_types; }
const MimeTypeMap & typeMap() const
{ return this->m_types; }
MimeTypeDb & instance()
{
typedef ::P::Phoenix< MimeTypeDb, MimeTypeDb, MimeTypeDb::init_functor > PHX;
return PHX::instance();
}
private:
/** For use with P::Phoenix. */
struct init_functor
{
/**
Gets called when instance() creates a new instance.
If db is empty thent this function tries to populate
it using the system-wise mime db.
*/
void operator()( MimeTypeDb & db ) const;
};
/** Like add(), but this inserts regardless of duplication. */
void insert(const MimeType& type);
MimeTypeMap m_types;
FileExtensionsMap m_exts;
};
} } // P::System
#endif
|