summaryrefslogtreecommitdiffstats
path: root/src/common/common/lister.h
blob: db32c45f24c366ff5174b1fb6b2b90f5d5c44cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/***************************************************************************
 *   Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org>                  *
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/
#ifndef LISTER_H
#define LISTER_H

#include "group.h"

namespace Group
{
//-----------------------------------------------------------------------------
template <class GroupType>
class Lister
{
public:
  typedef typename TQMap<TQString, const GroupType *>::ConstIterator ConstIterator;
  ConstIterator begin() const { return ConstIterator(_groups.begin()); }
  ConstIterator end() const { return ConstIterator(_groups.end()); }

  virtual ~Lister() {
    for (ConstIterator it=begin(); it!=end(); ++it) delete it.data();
  }

  TQValueVector<TQString> supportedDevices() const {
    TQValueVector<TQString> names;
    for (ConstIterator it=begin(); it!=end(); ++it) {
      TQValueVector<TQString> gnames = it.data()->supportedDevices();
      for (uint k=0; k<uint(gnames.count()); k++) names.append(gnames[k]);
    }
    return names;
  }

  uint count() const {
    uint nb = 0;
    for (ConstIterator it=begin(); it!=end(); ++it) nb += it.data()->count();
    return nb;
  }

  bool isSupported(const TQString &device) const {
    for (ConstIterator it=begin(); it!=end(); ++it)
      if ( it.data()->isSupported(device) ) return true;
    return false;
  }

  const GroupType *group(const TQString &name) const {
    if ( _groups.contains(name) ) return _groups[name];
    return 0;
  }

protected:
  void addGroup(GroupType *group, BaseGui *gui) {
    Q_ASSERT(group);
    group->_gui = gui;
    if (gui) gui->_group = group;
    group->init();
    Q_ASSERT( !_groups.contains(group->name()) );
    _groups.insert(group->name(), group);
  }

private:
  TQMap<TQString, const GroupType *> _groups;
};

} // namespace

#endif