Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

stanzaextensionfactory.cpp

00001 /*
00002   Copyright (c) 2006-2008 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 
00014 #include "stanzaextensionfactory.h"
00015 
00016 #include "gloox.h"
00017 #include "util.h"
00018 #include "stanza.h"
00019 #include "stanzaextension.h"
00020 #include "tag.h"
00021 
00022 namespace gloox
00023 {
00024 
00025   StanzaExtensionFactory::StanzaExtensionFactory()
00026   {
00027   }
00028 
00029   StanzaExtensionFactory::~StanzaExtensionFactory()
00030   {
00031 //     util::clearList( m_extensions );
00032     // FIXME
00033     SEList::iterator it = m_extensions.begin();
00034     SEList::iterator it2;
00035     while( it != m_extensions.end() )
00036     {
00037       it2 = it++;
00038       delete (*it2);
00039       m_extensions.erase( it2 );
00040     }
00041     // ~
00042   }
00043 
00044   void StanzaExtensionFactory::registerExtension( StanzaExtension* ext )
00045   {
00046     if( !ext )
00047       return;
00048 
00049     SEList::iterator it = m_extensions.begin();
00050     SEList::iterator it2;
00051     while( it != m_extensions.end() )
00052     {
00053       it2 = it++;
00054       if( ext->extensionType() == (*it2)->extensionType() )
00055       {
00056         delete (*it2);
00057         m_extensions.erase( it2 );
00058       }
00059     }
00060     m_extensions.push_back( ext );
00061   }
00062 
00063   bool StanzaExtensionFactory::removeExtension( int ext )
00064   {
00065     SEList::iterator it = m_extensions.begin();
00066     for( ; it != m_extensions.end(); ++it )
00067     {
00068       if( (*it)->extensionType() == ext )
00069       {
00070         delete (*it);
00071         m_extensions.erase( it );
00072         return true;
00073       }
00074     }
00075     return false;
00076   }
00077 
00078   void StanzaExtensionFactory::addExtensions( Stanza& stanza, Tag* tag )
00079   {
00080     ConstTagList match;
00081     ConstTagList::const_iterator it;
00082     SEList::const_iterator ite = m_extensions.begin();
00083     for( ; ite != m_extensions.end(); ++ite )
00084     {
00085       match = tag->findTagList( (*ite)->filterString() );
00086       it = match.begin();
00087       for( ; it != match.end(); ++it )
00088       {
00089         StanzaExtension* se = (*ite)->newInstance( (*it) );
00090         if( se )
00091           stanza.addExtension( se );
00092       }
00093     }
00094   }
00095 
00096 }

Generated on Mon Jun 23 10:50:19 2008 for gloox by  doxygen 1.4.1