libsidplayfp 1.0.3
sidbuilder.h
00001 /*
00002  * This file is part of libsidplayfp, a SID player engine.
00003  *
00004  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
00005  * Copyright 2007-2010 Antti Lankila
00006  * Copyright 2000-2001 Simon White
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021  */
00022 
00023 #ifndef SIDBUILDER_H
00024 #define SIDBUILDER_H
00025 
00026 #include <set>
00027 #include <string>
00028 
00029 #include "sidplayfp/SidConfig.h"
00030 
00031 class sidemu;
00032 class EventContext;
00033 
00037 class sidbuilder
00038 {
00039 private:
00040     const char * const m_name;
00041 
00042 protected:
00043     std::string m_errorBuffer;
00044 
00045     std::set<sidemu *> sidobjs;
00046 
00047     bool m_status;
00048 
00049 protected:
00053     template<class Temu, typename Tparam>
00054     class applyParameter
00055     {
00056     protected:
00057         Tparam m_param;
00058         void (Temu::*m_method)(Tparam);
00059 
00060     public:
00061         applyParameter(void (Temu::*method)(Tparam), Tparam param) :
00062             m_param(param),
00063             m_method(method) {}
00064         void operator() (sidemu *e) { (static_cast<Temu*>(e)->*m_method)(m_param); }
00065     };
00066 
00067 public:
00068     sidbuilder(const char * const name) :
00069         m_name(name),
00070         m_errorBuffer("N/A"),
00071         m_status (true) {}
00072     virtual ~sidbuilder() {}
00073 
00079     unsigned int usedDevices() const { return sidobjs.size (); }
00080 
00086     virtual unsigned int availDevices() const = 0;
00087 
00093     virtual unsigned int create(unsigned int sids) = 0;
00094 
00102     sidemu *lock(EventContext *env, SidConfig::sid_model_t model);
00103 
00109     void unlock(sidemu *device);
00110 
00114     void remove();
00115 
00121     const char *name() const { return m_name; }
00122 
00128     const char *error() const { return m_errorBuffer.c_str(); }
00129 
00135     bool getStatus() const { return m_status; }
00136 
00142     virtual const char *credits() const = 0;
00143 
00149     virtual void filter(bool enable) = 0;
00150 };
00151 
00152 #endif // SIDBUILDER_H