blob: f9874e430fe36910c609b249c1d19b4b2a7da1f3 (
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/***************************************************************************
* Copyright (C) 2005-2007 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 DEVICE_XML_TO_DATA_H
#define DEVICE_XML_TO_DATA_H
#include <tqmap.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include "common/common/misc.h"
#include "common/common/streamer.h"
#include "devices/base/generic_device.h"
#include "xml_to_data.h"
namespace Device
{
class XmlToDataBase : public ::XmlToData
{
public:
XmlToDataBase() : _data(0) {}
protected:
mutable Data *_data;
TQMap<TQString, Data *> _map; // device -> data
virtual void parse();
virtual TQString currentDevice() const { return (_data ? _data->name() : TQString()); }
virtual TQString namespaceName() const = 0;
virtual Data *createData() const = 0;
virtual void processDevice(TQDomElement device);
virtual void checkPins(const TQMap<TQString, uint> &pinLabels) const = 0;
private:
TQMap<TQString, TQString> _documents; // document -> device
TQMap<TQString, TQStringList> _alternatives; // device -> alternatives
bool getFrequencyRange(OperatingCondition oc, Special special, TQDomElement element);
bool getMemoryTechnology(TQDomElement element);
Device::Package processPackage(TQDomElement element);
};
template <class DataType>
class XmlToData : public XmlToDataBase, public DataStreamer<DataType>
{
public:
virtual Device::Data *createData() const { return new DataType; }
DataType *data() { return static_cast<DataType *>(_data); }
const DataType *data() const { return static_cast<DataType *>(_data); }
virtual void output() {
TQFile dfile("deps.mak");
if ( !dfile.open(IO_WriteOnly) ) return;
TQTextStream dts(&dfile);
dts << "noinst_DATA = ";
uint i = 0;
TQMap<TQString, Data *>::const_iterator it;
for (it=_map.begin(); it!=_map.end(); ++it) {
if ( (i%10)==0 ) dts << "\\" << endl << " ";
dts << " " << it.key() << ".xml";
i++;
}
dts << endl;
dfile.close();
TQFile file(namespaceName().lower() + "_data.cpp");
if ( !file.open(IO_WriteOnly) ) return;
TQTextStream ts(&file);
ts << "#include \"devices/" << namespaceName().lower() << "/"
<< namespaceName().lower() << "/" << namespaceName().lower() << "_group.h\"" << endl << endl;
ts << "const char *" << namespaceName() << "::DATA_STREAM =" << endl;
TQValueList<DataType *> list;
for (it=_map.begin(); it!=_map.end(); ++it)
list.append(static_cast<const DataType *>(it.data()));
uint size = toCppString(list, ts);
ts << ";" << endl;
ts << "const uint " << namespaceName() << "::DATA_SIZE = " << size << ";" << endl;
file.close();
}
};
} // namespace
#endif
|