libsidplayfp  1.8.3
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 protected:
40  typedef std::set<sidemu*> emuset_t;
41 
42 private:
43  const char * const m_name;
44 
45 protected:
46  std::string m_errorBuffer;
47 
48  emuset_t sidobjs;
49 
50  bool m_status;
51 
52 protected:
56  template<class Temu, typename Tparam>
58  {
59  protected:
60  Tparam m_param;
61  void (Temu::*m_method)(Tparam);
62 
63  public:
64  applyParameter(void (Temu::*method)(Tparam), Tparam param) :
65  m_param(param),
66  m_method(method) {}
67  void operator() (sidemu *e) { (static_cast<Temu*>(e)->*m_method)(m_param); }
68  };
69 
70 public:
71  sidbuilder(const char * const name) :
72  m_name(name),
73  m_errorBuffer("N/A"),
74  m_status (true) {}
75  virtual ~sidbuilder() {}
76 
82  unsigned int usedDevices() const { return sidobjs.size (); }
83 
89  virtual unsigned int availDevices() const = 0;
90 
96  virtual unsigned int create(unsigned int sids) = 0;
97 
105  sidemu *lock(EventContext *env, SidConfig::sid_model_t model);
106 
112  void unlock(sidemu *device);
113 
115  void remove();
116 
122  const char *name() const { return m_name; }
123 
129  const char *error() const { return m_errorBuffer.c_str(); }
130 
136  bool getStatus() const { return m_status; }
137 
143  virtual const char *credits() const = 0;
144 
150  virtual void filter(bool enable) = 0;
151 };
152 
153 #endif // SIDBUILDER_H
sidemu * lock(EventContext *env, SidConfig::sid_model_t model)
Definition: sidbuilder.cpp:27
Definition: sidemu.h:39
virtual unsigned int availDevices() const =0
Definition: event.h:107
unsigned int usedDevices() const
Definition: sidbuilder.h:82
bool getStatus() const
Definition: sidbuilder.h:136
const char * error() const
Definition: sidbuilder.h:129
virtual const char * credits() const =0
virtual unsigned int create(unsigned int sids)=0
Definition: sidbuilder.h:57
Definition: sidbuilder.h:37
void unlock(sidemu *device)
Definition: sidbuilder.cpp:47
const char * name() const
Definition: sidbuilder.h:122
virtual void filter(bool enable)=0