File: visitor.cc

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 (229 lines) | stat: -rw-r--r-- 7,818 bytes parent folder | download | duplicates (2)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include "visitor.hh"
#include "config.hh"
#include "configobject.hh"
#include "configreference.hh"
#include "logger.hh"

Visitor::Visitor()
{
  // Pass...
}

Visitor::~Visitor() {
  // pass...
}

bool
Visitor::process(Config *config, const ErrorStack &err) {
  return this->processItem(config, err);
}

bool
Visitor::processItem(ConfigItem *item, const ErrorStack &err) {
  // Process all properties
  const QMetaObject *meta = item->metaObject();
  for (int p=QObject::staticMetaObject.propertyCount(); p<meta->propertyCount(); p++) {
    QMetaProperty prop = meta->property(p);
    if (! prop.isValid()) {
      logWarn() << "Found invalid property at index " << p << " in an instance of '"
                << meta->className() << "'. Skip.";
      continue;
    }

    if (! this->processProperty(item, prop, err)) {
      errMsg(err) << "While processing property '" << prop.name() << "' of '"
                  << meta->className() << "'.";
      return false;
    }
  }
  return true;
}

bool
Visitor::processProperty(ConfigItem *item, const QMetaProperty &prop, const ErrorStack &err) {
  if (prop.isEnumType()) {
    if (! this->processEnum(item, prop, err)) {
      errMsg(err) << "While processing enum '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("bool") == prop.typeName()) {
    if (! this->processBool(item, prop, err)) {
      errMsg(err) << "While processing boolean '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("int") == prop.typeName()) {
    if (! this->processInt(item, prop, err)) {
      errMsg(err) << "While processing integer '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("uint") == prop.typeName()) {
    if (! this->processUInt(item, prop, err)) {
      errMsg(err) << "While processing unsigned integer '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("double") == prop.typeName()) {
    if (! this->processDouble(item, prop, err)) {
      errMsg(err) << "While processing double '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("QString") == prop.typeName()) {
    if (! this->processString(item, prop, err)) {
      errMsg(err) << "While processing string '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("Frequency") == prop.typeName()) {
    if (! this->processFrequency(item, prop, err)) {
      errMsg(err) << "While processing frequency '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("Interval") == prop.typeName()) {
    if (! this->processInterval(item, prop, err)) {
      errMsg(err) << "While processing frequency '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (QString("SelectiveCall") == prop.typeName()) {
    if (! this->processSelectiveCall(item, prop, err)) {
      errMsg(err) << "While processing frequency '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (ConfigObjectReference *ref = prop.read(item).value<ConfigObjectReference *>()) {
    if (! this->processReference(ref, err)) {
      errMsg(err) << "While processing reference '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (ConfigObjectRefList *refs = prop.read(item).value<ConfigObjectRefList *>()) {
    if (! this->processList(refs, err)) {
      errMsg(err) << "While processing reference list '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (propIsInstance<ConfigItem>(prop)) {
    ConfigItem *pitem = prop.read(item).value<ConfigItem *>();
    // Some items, held as writeable properties might be null (e.g., extensions)
    if (prop.isWritable() && (nullptr == pitem))
      return true;
    // Go for it
    if (! this->processItem(pitem, err)) {
      errMsg(err) << "While processing item '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else if (ConfigObjectList *lst = prop.read(item).value<ConfigObjectList *>()) {
    if (! this->processList(lst, err)) {
      errMsg(err) << "While processing reference list '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "'.";
      return false;
    }
  } else {
    if (! this->processUnknownType(item, prop, err)) {
      errMsg(err) << "While processing property '" << prop.name() << "' of '"
                  << item->metaObject()->className() << "' of unknown type.";
      return false;

    }
  }

  return true;
}

bool
Visitor::processBool(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processEnum(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processInt(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processUInt(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processDouble(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processString(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processFrequency(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processInterval(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processSelectiveCall(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  Q_UNUSED(parent); Q_UNUSED(prop); Q_UNUSED(err)
  // Does nothing, return true;
  return true;
}

bool
Visitor::processUnknownType(ConfigItem *parent, const QMetaProperty &prop, const ErrorStack &err) {
  errMsg(err) << "Cannot handle property '" << prop.name() << "' of '"
              << parent->metaObject()->className() << "': Unknown type '"
              << prop.typeName()  << "'.";
  return false;
}

bool
Visitor::processReference(ConfigObjectReference* ref, const ErrorStack &err) {
  Q_UNUSED(ref); Q_UNUSED(err)
  // Does nothing, returns true;
  return true;
}

bool
Visitor::processList(AbstractConfigObjectList *list, const ErrorStack &err) {
  if (ConfigObjectList *objList = qobject_cast<ConfigObjectList *>(list)) {
    for (int i=0; i<objList->count(); i++) {
      if (! this->processItem(objList->get(i), err)) {
        errMsg(err) << "While processing object list.";
        return false;
      }
    }
  }
  return true;
}