gloox  1.0
stanzaextensionfactory.cpp
1 /*
2  Copyright (c) 2006-2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #include "stanzaextensionfactory.h"
15 
16 #include "gloox.h"
17 #include "util.h"
18 #include "stanza.h"
19 #include "stanzaextension.h"
20 #include "tag.h"
21 
22 namespace gloox
23 {
24 
26  {
27  }
28 
30  {
31  util::clearList( m_extensions );
32  }
33 
35  {
36  if( !ext )
37  return;
38 
39  SEList::iterator it = m_extensions.begin();
40  SEList::iterator it2;
41  while( it != m_extensions.end() )
42  {
43  it2 = it++;
44  if( ext->extensionType() == (*it2)->extensionType() )
45  {
46  delete (*it2);
47  m_extensions.erase( it2 );
48  }
49  }
50  m_extensions.push_back( ext );
51  }
52 
54  {
55  SEList::iterator it = m_extensions.begin();
56  for( ; it != m_extensions.end(); ++it )
57  {
58  if( (*it)->extensionType() == ext )
59  {
60  delete (*it);
61  m_extensions.erase( it );
62  return true;
63  }
64  }
65  return false;
66  }
67 
69  {
70  ConstTagList::const_iterator it;
71  SEList::const_iterator ite = m_extensions.begin();
72  for( ; ite != m_extensions.end(); ++ite )
73  {
74  const ConstTagList& match = tag->findTagList( (*ite)->filterString() );
75  it = match.begin();
76  for( ; it != match.end(); ++it )
77  {
78  StanzaExtension* se = (*ite)->newInstance( (*it) );
79  if( se )
80  stanza.addExtension( se );
81  }
82  }
83  }
84 
85 }