gloox  1.0.10
jingleplugin.h
1 /*
2  Copyright (c) 2008-2013 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 #ifndef JINGLEPLUGIN_H__
15 #define JINGLEPLUGIN_H__
16 
17 #include "macros.h"
18 #include "util.h"
19 
20 #include <string>
21 #include <list>
22 
23 namespace gloox
24 {
25 
26  class Tag;
27 
28  namespace Jingle
29  {
30 
31  class Plugin;
32  class PluginFactory;
33 
35  {
44  };
45 
49  typedef std::list<const Plugin*> PluginList;
50 
64  class GLOOX_API Plugin
65  {
66 
67  friend class PluginFactory;
68 
69  public:
73  Plugin( JinglePluginType type ) : m_factory( 0 ), m_pluginType( type ) {}
74 
78  virtual ~Plugin() { util::clearList( m_plugins ) ; }
79 
84  void addPlugin( const Plugin* plugin ) { if( plugin ) m_plugins.push_back( plugin ); }
85 
91  const Plugin* findPlugin( int type ) const
92  {
93  PluginList::const_iterator it = m_plugins.begin();
94  for( ; it != m_plugins.end() && (*it)->pluginType() != type; ++it ) ;
95  return it != m_plugins.end() ? (*it) : 0;
96  }
97 
107  template< class T >
108  inline const T* findPlugin( int type ) const
109  {
110  return static_cast<const T*>( findPlugin( type ) );
111  }
112 
117  const PluginList& plugins() const { return m_plugins; }
118 
124  virtual const StringList features() const { return StringList(); }
125 
133  virtual const std::string& filterString() const = 0;
134 
139  virtual Tag* tag() const = 0;
140 
147  virtual Plugin* newInstance( const Tag* tag ) const = 0;
148 
153  virtual Plugin* clone() const = 0;
154 
159  JinglePluginType pluginType() const { return m_pluginType; }
160 
161  protected:
162  PluginList m_plugins;
163  PluginFactory* m_factory;
164 
165  private:
166  void setFactory( PluginFactory* factory ) { m_factory = factory; }
167 
168  JinglePluginType m_pluginType;
169 
170  };
171 
172  }
173 
174 }
175 
176 #endif // JINGLEPLUGIN_H__