compressiondefault.cpp

00001 /*
00002  * Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
00003  * This file is part of the gloox library. http://camaya.net/gloox
00004  *
00005  * This software is distributed under a license. The full license
00006  * agreement can be found in the file LICENSE in this distribution.
00007  * This software may not be copied, modified, sold or distributed
00008  * other than expressed in the named license agreement.
00009  *
00010  * This software is distributed without any warranty.
00011  */
00012 
00013 #include "compressiondefault.h"
00014 
00015 #include "compressiondatahandler.h"
00016 
00017 #include "config.h"
00018 
00019 #if defined( HAVE_ZLIB )
00020 # define HAVE_COMPRESSION
00021 # include "compressionzlib.h"
00022 #endif
00023 
00024 // #if defined( HAVE_LZW )
00025 // # define HAVE_COMPRESSION
00026 // # include "compressionlzw.h"
00027 // #endif
00028 
00029 namespace gloox
00030 {
00031 
00032   CompressionDefault::CompressionDefault( CompressionDataHandler* cdh, Method method )
00033     : CompressionBase( cdh ), m_impl( 0 )
00034   {
00035     switch( method )
00036     {
00037       case MethodZlib:
00038 #ifdef HAVE_ZLIB
00039         m_impl = new CompressionZlib( cdh );
00040 #endif
00041         break;
00042       case MethodLZW:
00043 #ifdef HAVE_LZW
00044         m_impl = new CompressionLZW( cdh );
00045 #endif
00046         break;
00047       default:
00048         break;
00049     }
00050   }
00051 
00052   CompressionDefault::~CompressionDefault()
00053   {
00054     delete m_impl;
00055   }
00056 
00057   bool CompressionDefault::init()
00058   {
00059     return m_impl ? m_impl->init() : false;
00060   }
00061 
00062   int CompressionDefault::types()
00063   {
00064     int types = 0;
00065 #ifdef HAVE_ZLIB
00066     types |= MethodZlib;
00067 #endif
00068 #ifdef HAVE_LZW
00069     types |= MethodLZW;
00070 #endif
00071     return types;
00072   }
00073 
00074   void CompressionDefault::compress( const std::string& data )
00075   {
00076     if( m_impl )
00077       m_impl->compress( data );
00078   }
00079 
00080   void CompressionDefault::decompress( const std::string& data )
00081   {
00082     if( m_impl )
00083       m_impl->decompress( data );
00084   }
00085 
00086   void CompressionDefault::cleanup()
00087   {
00088     if( m_impl )
00089       m_impl->cleanup();
00090   }
00091 
00092 }
Generated on Tue Jun 8 23:37:53 2010 for gloox by  doxygen 1.6.3