File: intermediaterepresentation.hh

package info (click to toggle)
qdmr 0.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,420 kB
  • sloc: cpp: 95,929; xml: 10,749; python: 1,108; makefile: 78; sh: 9
file content (118 lines) | stat: -rw-r--r-- 3,437 bytes parent folder | download
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/** @defgroup ir Intermediate representation.
 * This module collects visitors applied to a codeplug before the actual encoding of the device
 * specific binary codeplug. This preprocessing step eases the encoding a lot.
 *
 * @ingroup config */

#ifndef INTERMEDIATEREPRESENTATION_HH
#define INTERMEDIATEREPRESENTATION_HH

#include "visitor.hh"
#include <QList>

class Zone;
class EncryptionKey;


/** Simple visitor that splits Zones having A and B channels into two zones with A-lists only.
 * This is a pre-processing step for many radios, where zones consists of a single list of channels
 * and a zone is selected for each VFO separately.
 * @ingroup ir */
class ZoneSplitVisitor: public Visitor
{
public:
  /** Constructor. */
  explicit ZoneSplitVisitor();

  bool processItem(ConfigItem *item, const ErrorStack &err);
};

/** Simple visitor that merges zones. This is the reverse step of the @c ZoneSplitVisitor.
 * Two subsequent zones are only merged into one, if both zones have empty B lists, the name of the
 * first zone ends on "... A" and the name of the second ends on "... B". That is, if the two zones
 * where likely split by qdmr. */
class ZoneMergeVisitor: public Visitor
{
public:
  /** Constructor. */
  explicit ZoneMergeVisitor();

  bool processList(AbstractConfigObjectList *list, const ErrorStack &err);
  bool processItem(ConfigItem *item, const ErrorStack &err);

protected:
  /** The last zone visited, @c nullptr if the first zone is processed. */
  Zone *_lastZone;
  /** Zones to be removed. */
  QList<Zone *> _mergedZones;
};



/** Filters instances by a test function.
 *
 * This visitor can be used to remove elements from the abstract codeplug, not supported by the
 * target device. Use @c ObjectFilterVisitor to remove instances of specific classes.
 */
class AbstractObjectFilterVisitor: public Visitor
{
protected:
  /** Hidden constructor. */
  explicit AbstractObjectFilterVisitor();

public:
  bool processProperty(ConfigItem *item, const QMetaProperty &prop, const ErrorStack &err);
  bool processList(AbstractConfigObjectList *list, const ErrorStack &err);

protected slots:
  /** Abstract test function. If this function returns @c true, the item will be removed. */
  virtual bool toRemove(ConfigItem *item) = 0;
};



/** Filters instance by meta object.
 *
 * This visitor can be used to remove elements from the abstract codeplug, not supported by the
 * target device. */
class ObjectFilterVisitor: public AbstractObjectFilterVisitor
{
public:
  /** Constructor from initializer list of Qt meta objects. */
  explicit ObjectFilterVisitor(const std::initializer_list<QMetaObject> &types);

protected slots:
  bool toRemove(ConfigItem *item);

protected:
  /** The list of filtered types. */
  QList<QMetaObject> _filter;
};


/** Only keeps those encryption keys, that match a specific type and size. */
class EncryptionKeyFilterVisitor: public AbstractObjectFilterVisitor
{
public:
  struct Filter {
    QMetaObject type;
    unsigned int minBits;
    unsigned int maxBits;

    Filter(const QMetaObject &type, unsigned int bits);
    Filter(const QMetaObject &type, unsigned int minBits, unsigned int maxBits);

    bool accepts(const EncryptionKey *key) const;
  };

public:
  EncryptionKeyFilterVisitor(const std::initializer_list<Filter> &filter);

protected:
  bool toRemove(ConfigItem *item);

protected:
  QList<Filter> _filter;
};

#endif // INTERMEDIATEREPRESENTATION_HH