summaryrefslogtreecommitdiffstats
path: root/utils/regtools/qeditor/analyser.h
blob: 4f9830ac4c283cce93d708a0a71e93e3b293ab92 (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
#ifndef _ANALYSER_H_
#define _ANALYSER_H_

#include <QObject>
#include <QVector>
#include <QString>
#include "backend.h"
#include "regtab.h"

class Analyser : public RegTabPanel
{
public:
    Analyser(const SocRef& soc, IoBackend *backend);
    virtual ~Analyser();
    virtual void AllowWrite(bool en) { Q_UNUSED(en); }
    virtual QWidget *GetWidget() = 0;

protected:
    const SocRef& m_soc;
    IoBackend *m_io_backend;
};

class AnalyserFactory
{
public:
    AnalyserFactory(bool _register);
    virtual ~AnalyserFactory();

    virtual QString GetName() = 0;
    virtual bool SupportSoc(const QString& soc_name) = 0;
    // return NULL of soc is not handled by the analyser
    virtual Analyser *Create(const SocRef& soc, IoBackend *backend) = 0;
private:
    QString m_name;

public:
    static QStringList GetAnalysersForSoc(const QString& soc_name);
    static AnalyserFactory *GetAnalyserByName(const QString& name);
    static void RegisterAnalyser(AnalyserFactory *factory);

private:
    static QVector< AnalyserFactory * > m_factories;
};

template< typename T >
class TmplAnalyserFactory : public AnalyserFactory
{
public:
    TmplAnalyserFactory(bool _register, const QString& name) :AnalyserFactory(_register) { m_name = name; }
    virtual ~TmplAnalyserFactory() {}

    virtual QString GetName() { return m_name; }
    virtual bool SupportSoc(const QString& soc_name) { return T::SupportSoc(soc_name); }
    // return NULL of soc is not handled by the analyser
    virtual T *Create(const SocRef& soc, IoBackend *backend)
    {
        if(!T::SupportSoc(soc.GetSoc().name.c_str()))
            return 0;
        return new T(soc, backend);
    }
private:
    QString m_name;
};

#endif /* _ANALYSER_H_ */