157{
158 appTitle =
"OKS data files comparer. OKS kernel version ";
160
161 bool printAttributeDifferences = false;
162 bool printRelationshipDifferences = false;
163 bool printCompositeParentsMode = false;
164 bool verboseMode = false;
165
166 const char* appName = "oks_diff_data";
167
168 if (argc == 1) {
170 return 1;
171 }
172
173
174
175 const char** schemaFiles = new const char*[argc];
176 schemaFiles[0] = 0;
177
178 const char* dataFile1 = 0;
179 const char* dataFile2 = 0;
180
181 const char* class_name = 0;
182 const char* object_id = 0;
183
184 for (int i = 1; i < argc; i++) {
185 if (!strcmp(argv[i], "-a") || !strcmp(argv[i], "--attributes"))
186 printAttributeDifferences = true;
187 else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--relationships"))
188 printRelationshipDifferences = true;
189 else if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--composite-parents"))
190 printCompositeParentsMode = true;
191 else if (!strcmp(argv[i], "-all") || !strcmp(argv[i], "--all")) {
192 printAttributeDifferences = true;
193 printRelationshipDifferences = true;
194 printCompositeParentsMode = true;
195 } else if (!strcmp(argv[i], "-b") || !strcmp(argv[i], "--verbose"))
196 verboseMode = true;
197 else if (!strcmp(argv[i], "-h")) {
199 return 0;
200 } else if (!strcmp(argv[i], "--help")) {
202 return 0;
203 } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
205 return 0;
206 } else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--schema-files")) {
207 for (int j = 0; j < argc - i - 1; ++j) {
208 if (argv[i + 1 + j][0] != '-')
209 schemaFiles[j] = argv[i + 1 + j];
210 else {
211 schemaFiles[j] = 0;
212 i += j;
213 break;
214 }
215 }
216 } else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--class-name")) {
217 if (argv[i + 1][0] != '-')
218 class_name = argv[++i];
219 } else if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--object-id")) {
220 if (argv[i + 1][0] != '-')
221 object_id = argv[++i];
222 } else if (!strcmp(argv[i], "-d1") || !strcmp(argv[i], "--data-file1")) {
223 if (argv[i + 1][0] != '-')
224 dataFile1 = argv[++i];
225 } else if (!strcmp(argv[i], "-d2") || !strcmp(argv[i], "--data-file2")) {
226 if (argv[i + 1][0] != '-')
227 dataFile2 = argv[++i];
228 } else {
229 std::cerr << "ERROR: Unknown parameter: \"" << argv[i] << "\"\n\n";
231 return 1;
232 }
233 }
234
235
236
237 if (dataFile1 == 0) {
238 std::cerr << "ERROR: First data file is not defined.\n\n";
240 return 1;
241 }
242
243 if (dataFile2 == 0) {
244 std::cerr << "ERROR: Second data file is not defined.\n\n";
246 return 1;
247 }
248
249
250
251 if (object_id && !class_name) {
252 std::cerr << "ERROR: object ID cannot be used without class name.\n\n";
254 return 1;
255 }
256
257 int return_status = 0;
258
259
260
263
264 try {
265
266 if (!verboseMode) {
269 }
270
271 for (int i = 0; schemaFiles[i] != 0; ++i) {
272 const char* s_file = schemaFiles[i];
273
276 }
277
280
282 OksClass::Map::const_iterator class_iterator = classes.begin();
283
284 if (classes.empty()) {
285 std::cerr << "ERROR: No classes were found in loaded schema file(s), exiting ...\n";
286 return 4;
287 }
288
289 std::cout << std::endl;
290
292
294 for (; class_iterator != classes.end(); ++class_iterator) {
295 c1 = class_iterator->second;
296 std::string className(c1->
get_name());
297
298 if (class_name && className != class_name) {
299 continue;
300 }
301
302 if (verboseMode)
304
305 if (verboseMode) {
306 std::cout << "TESTING IN CLASS \"" << className << "\"... ";
307 std::cout.flush();
308 }
309
312 std::cout << std::endl;
314 << "."
315 " Database \'"
316 << dataFile2 << "\' does not have class \"" << className << "\", skip testing ...\n";
317 continue;
318 }
319
320 if (*c1 != *c2) {
322 std::cout << std::endl;
324 << "."
325 " Class \""
326 << className << "\" is different in \"" << dataFile1 << "\" and \"" << dataFile2
327 << "\", skip testing ...\n";
328 continue;
329 }
330
333 OksObject::Map::const_iterator object_iterator = objects1->begin();
334
335 for (; object_iterator != objects1->end(); ++object_iterator) {
336 const std::string* objUID = (*object_iterator).first;
337 OksObject* o1 = (*object_iterator).second;
338
339 if (object_id && o1->
GetId() != object_id) {
340 continue;
341 }
342
344
345 if (!o2) {
347 std::cout << std::endl;
349 << "."
350 " There is no object "
351 << o1 << " in the \"" << dataFile2 << "\" database file.\n";
352 continue;
353 }
354
355 if (*o1 == *o2)
356 continue;
357
359 std::cout << std::endl;
360 std::cout <<
" DIFFERENCE " << ++
classDiffsCount <<
". The OBJECTS " << o1 <<
" differed:\n";
361
362 int objDiffsCount = 0;
363
366
367 if (alist) {
368 for (std::list<OksAttribute*>::const_iterator ai = alist->begin(); ai != alist->end(); ++ai) {
372
373 if (!(*d1 == *d2)) {
374 ++objDiffsCount;
375
376 if (printAttributeDifferences) {
378 << "\" values differed:\n"
379 " the value in the FILE \""
380 << dataFile1 << "\" is: " << *d1
381 << "\n"
382 " the value in the FILE \""
383 << dataFile2 << "\" is: " << *d2 << std::endl;
384 }
385 }
386 }
387 }
388
389 if (rlist) {
390 for (std::list<OksRelationship*>::const_iterator ri = rlist->begin(); ri != rlist->end(); ++ri) {
392 OksData* d1(o1->GetRelationshipValue(
r->get_name()));
394
395 if (!(*d1 == *d2)) {
396 ++objDiffsCount;
397
398 if (printRelationshipDifferences) {
399 std::cout <<
" " <<
classDiffsCount <<
'.' << objDiffsCount <<
" The RELATIONSHIP \"" <<
r->get_name()
400 << "\" values differed:\n"
401 " the value in the FILE \""
402 << dataFile1 << "\" is: " << *d1
403 << "\n"
404 " the value in the FILE \""
405 << dataFile2 << "\" is: " << *d2 << std::endl;
406 }
407 }
408 }
409 }
410
411 if (objDiffsCount && printCompositeParentsMode) {
412 std::cout << " COMPOSITE PARENT(S) of the OBJECTS " << o1 << ":\n";
413 std::cout << " In the FILE \"" << dataFile1 << "\"\n";
415 std::cout << " In the FILE \"" << dataFile2 << "\"\n";
417 }
418 }
419
420 object_iterator = objects2->begin();
421
422 for (; object_iterator != objects2->end(); ++object_iterator) {
423 const std::string* objUID = (*object_iterator).first;
425
426 if (!o1 && (!object_id || *objUID == object_id)) {
428 std::cout << std::endl;
430 << "."
431 " There is no object "
432 << (*object_iterator).second << " in the \"" << dataFile1 << "\" database file.\n";
433 }
434 }
435
437 std::cout << " no differences were found\n";
438 }
439 }
440 }
441
442 catch (oks::exception& ex) {
443 std::cerr << "Caught oks exception:\n" << ex << std::endl;
444 return_status = 10;
445 }
446
447 catch (std::exception& e) {
448 std::cerr << "Caught standard C++ exception: " << e.what() << std::endl;
449 return_status = 10;
450 }
451
452 catch (...) {
453 std::cerr << "Caught unknown exception" << std::endl;
454 return_status = 10;
455 }
456
457 delete[] schemaFiles;
458
459 if (verboseMode)
460 std::cout << "\nExiting " << appName << "...\n";
461
462 return return_status;
463}
const std::string & get_name() const noexcept
out stream operator
const OksObject::Map * objects() const noexcept
const std::list< OksAttribute * > * all_attributes() const noexcept
const std::string & get_name() const noexcept
OksObject * get_object(const std::string &id) const noexcept
Get object by ID.
std::map< const char *, OksClass *, SortStr > Map
const std::list< OksRelationship * > * all_relationships() const noexcept
Provides interface to the OKS kernel.
OksFile * load_data(const std::string &name, bool bind=true)
Load OKS data file.
const OksClass::Map & classes() const
Get classes.
void set_silence_mode(const bool b)
Set status of silence mode. To switch 'On'/'Off' use the method's parameter:
static const char * GetVersion()
Get OKS version. The method returns string containing CVS tag and date of OKS build.
OksClass * find_class(const std::string &class_name) const
Find class by name (C++ string).
OksFile * load_schema(const std::string &name, const OksFile *parent=0)
Load OKS schema file.
OksObject describes instance of OksClass.
OksData * GetRelationshipValue(const std::string &) const
Get value of relationship by name.
std::unordered_map< const std::string *, OksObject *, oks::hash_str, oks::equal_str > Map
const std::string & GetId() const
OksData * GetAttributeValue(const std::string &name) const
Get value of attribute by name.
static void printUsage(const char *appName, std::ostream &s)
static void ReportCompositeParents(OksObject *o, int recursionLevel=-1)
static void printShortUsage(const char *appName, std::ostream &s)