libsidplayfp  1.1.0
sidbuilder.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2000-2001 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef SIDBUILDER_H
24 #define SIDBUILDER_H
25 
26 #include <set>
27 #include <string>
28 
29 #include "sidplayfp/SidConfig.h"
30 
31 class sidemu;
32 class EventContext;
33 
38 {
39 private:
40  const char * const m_name;
41 
42 protected:
43  std::string m_errorBuffer;
44 
45  std::set<sidemu *> sidobjs;
46 
47  bool m_status;
48 
49 protected:
53  template<class Temu, typename Tparam>
55  {
56  protected:
57  Tparam m_param;
58  void (Temu::*m_method)(Tparam);
59 
60  public:
61  applyParameter(void (Temu::*method)(Tparam), Tparam param) :
62  m_param(param),
63  m_method(method) {}
64  void operator() (sidemu *e) { (static_cast<Temu*>(e)->*m_method)(m_param); }
65  };
66 
67 public:
68  sidbuilder(const char * const name) :
69  m_name(name),
70  m_errorBuffer("N/A"),
71  m_status (true) {}
72  virtual ~sidbuilder() {}
73 
79  unsigned int usedDevices() const { return sidobjs.size (); }
80 
86  virtual unsigned int availDevices() const = 0;
87 
93  virtual unsigned int create(unsigned int sids) = 0;
94 
102  sidemu *lock(EventContext *env, SidConfig::sid_model_t model);
103 
109  void unlock(sidemu *device);
110 
114  void remove();
115 
121  const char *name() const { return m_name; }
122 
128  const char *error() const { return m_errorBuffer.c_str(); }
129 
135  bool getStatus() const { return m_status; }
136 
142  virtual const char *credits() const = 0;
143 
149  virtual void filter(bool enable) = 0;
150 };
151 
152 #endif // SIDBUILDER_H