vmime/src/encoderFactory.cpp

111 lines
2.8 KiB
C++
Raw Normal View History

2004-10-05 10:28:21 +00:00
//
2005-03-18 21:33:11 +00:00
// VMime library (http://www.vmime.org)
2006-02-05 10:22:59 +00:00
// Copyright (C) 2002-2006 Vincent Richard <vincent@vincent-richard.net>
2004-10-05 10:28:21 +00:00
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program 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
// General Public License for more details.
//
2005-09-17 10:10:29 +00:00
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// Linking this library statically or dynamically with other modules is making
// a combined work based on this library. Thus, the terms and conditions of
// the GNU General Public License cover the whole combination.
2004-10-05 10:28:21 +00:00
//
#include "vmime/encoderFactory.hpp"
#include "vmime/exception.hpp"
#include "vmime/encoderB64.hpp"
#include "vmime/encoderQP.hpp"
#include "vmime/encoderUUE.hpp"
#include "vmime/encoderBinary.hpp"
#include "vmime/encoder7bit.hpp"
#include "vmime/encoder8bit.hpp"
2004-10-05 10:28:21 +00:00
namespace vmime
{
encoderFactory::encoderFactory()
{
// Register some default encoders
registerName <encoderB64>("base64");
registerName <encoderQP>("quoted-printable");
registerName <encoderUUE>("uuencode");
registerName <encoder7bit>("7bit");
registerName <encoder8bit>("8bit");
registerName <encoderBinary>("binary");
}
encoderFactory::~encoderFactory()
{
}
encoderFactory* encoderFactory::getInstance()
{
static encoderFactory instance;
return (&instance);
}
2004-10-05 10:28:21 +00:00
2005-07-12 22:28:02 +00:00
ref <encoder> encoderFactory::create(const string& name)
2004-10-05 10:28:21 +00:00
{
2004-10-21 15:05:47 +00:00
return (getEncoderByName(name)->create());
}
2005-07-12 22:28:02 +00:00
const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderByName(const string& name) const
2004-10-21 15:05:47 +00:00
{
const string lcName(utility::stringUtils::toLower(name));
2004-10-05 10:28:21 +00:00
2005-07-12 22:28:02 +00:00
for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
2004-10-21 15:05:47 +00:00
it != m_encoders.end() ; ++it)
2004-10-05 10:28:21 +00:00
{
2004-10-21 15:05:47 +00:00
if ((*it)->getName() == lcName)
return (*it);
2004-10-05 10:28:21 +00:00
}
2004-10-21 15:05:47 +00:00
throw exceptions::no_encoder_available(name);
2004-10-21 15:05:47 +00:00
}
const int encoderFactory::getEncoderCount() const
{
return (m_encoders.size());
}
2005-07-12 22:28:02 +00:00
const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderAt(const int pos) const
2004-10-21 15:05:47 +00:00
{
return (m_encoders[pos]);
}
2005-07-12 22:28:02 +00:00
const std::vector <ref <const encoderFactory::registeredEncoder> > encoderFactory::getEncoderList() const
2004-10-21 15:05:47 +00:00
{
2005-07-12 22:28:02 +00:00
std::vector <ref <const registeredEncoder> > res;
2004-10-21 15:05:47 +00:00
2005-07-12 22:28:02 +00:00
for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
2004-10-21 15:05:47 +00:00
it != m_encoders.end() ; ++it)
2004-10-05 10:28:21 +00:00
{
2004-10-21 15:05:47 +00:00
res.push_back(*it);
2004-10-05 10:28:21 +00:00
}
2004-10-21 15:05:47 +00:00
return (res);
2004-10-05 10:28:21 +00:00
}
} // vmime