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
176 const char ** schemaFiles = new const char * [argc];
177 schemaFiles[0] = 0;
178
179 const char * dataFile1 = 0;
180 const char * dataFile2 = 0;
181
182 const char * class_name = 0;
183 const char * object_id = 0;
184
185 for(int i = 1; i < argc; i++) {
186 if(!strcmp(argv[i], "-a") || !strcmp(argv[i], "--attributes"))
187 printAttributeDifferences = true;
188 else if(!strcmp(argv[i], "-r") || !strcmp(argv[i], "--relationships"))
189 printRelationshipDifferences = true;
190 else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--composite-parents"))
191 printCompositeParentsMode = true;
192 else if(!strcmp(argv[i], "-all") || !strcmp(argv[i], "--all")) {
193 printAttributeDifferences = true;
194 printRelationshipDifferences = true;
195 printCompositeParentsMode = true;
196 }
197 else if(!strcmp(argv[i], "-b") || !strcmp(argv[i], "--verbose"))
198 verboseMode = true;
199 else if(!strcmp(argv[i], "-h")) {
201 return 0;
202 }
203 else if(!strcmp(argv[i], "--help")) {
205 return 0;
206 }
207 else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
209 return 0;
210 }
211 else if(!strcmp(argv[i], "-s") || !strcmp(argv[i], "--schema-files")) {
212 for(int j = 0; j < argc - i - 1; ++j) {
213 if(argv[i+1+j][0] != '-') schemaFiles[j] = argv[i+1+j];
214 else {
215 schemaFiles[j]=0;
216 i+=j;
217 break;
218 }
219 }
220 }
221 else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--class-name")) {
222 if(argv[i+1][0] != '-') class_name=argv[++i];
223 }
224 else if(!strcmp(argv[i], "-o") || !strcmp(argv[i], "--object-id")) {
225 if(argv[i+1][0] != '-') object_id=argv[++i];
226 }
227 else if(!strcmp(argv[i], "-d1") || !strcmp(argv[i], "--data-file1")) {
228 if(argv[i+1][0] != '-') dataFile1=argv[++i];
229 }
230 else if(!strcmp(argv[i], "-d2") || !strcmp(argv[i], "--data-file2")) {
231 if(argv[i+1][0] != '-') dataFile2=argv[++i];
232 }
233 else {
234 std::cerr << "ERROR: Unknown parameter: \"" << argv[i] << "\"\n\n";
236 return 1;
237 }
238 }
239
240
241
242
243 if(dataFile1 == 0) {
244 std::cerr << "ERROR: First data file is not defined.\n\n";
246 return 1;
247 }
248
249 if(dataFile2 == 0) {
250 std::cerr << "ERROR: Second data file is not defined.\n\n";
252 return 1;
253 }
254
255
256
257
258 if(object_id && !class_name) {
259 std::cerr << "ERROR: object ID cannot be used without class name.\n\n";
261 return 1;
262 }
263
264
265 int return_status = 0;
266
267
268
269
272
273 try {
274
275 if(!verboseMode) {
278 }
279
280 for(int i=0; schemaFiles[i] != 0; ++i) {
281 const char *s_file = schemaFiles[i];
282
285 }
286
289
291 OksClass::Map::const_iterator class_iterator = classes.begin();
292
293 if(classes.empty()) {
294 std::cerr << "ERROR: No classes were found in loaded schema file(s), exiting ...\n";
295 return 4;
296 }
297
298 std::cout << std::endl;
299
301
303 for(;class_iterator != classes.end(); ++class_iterator) {
304 c1 = class_iterator->second;
305 std::string className(c1->
get_name());
306
307 if(class_name && className != class_name) {
308 continue;
309 }
310
312
313 if(verboseMode) {
314 std::cout << "TESTING IN CLASS \"" << className << "\"... ";
315 std::cout.flush();
316 }
317
321 " Database \'" << dataFile2 << "\' does not have class \"" << className << "\", skip testing ...\n";
322 continue;
323 }
324
325 if(*c1 != *c2) {
328 " Class \"" << className << "\" is different in \"" << dataFile1 << "\" and \"" << dataFile2 << "\", skip testing ...\n";
329 continue;
330 }
331
334 OksObject::Map::const_iterator object_iterator = objects1->begin();
335
336 for(;object_iterator != objects1->end(); ++object_iterator) {
337 const std::string * objUID = (*object_iterator).first;
338 OksObject * o1 = (*object_iterator).second;
339
340 if(object_id && o1->
GetId() != object_id) {
341 continue;
342 }
343
345
346 if(!o2) {
349 " There is no object " << o1 << " in the \"" << dataFile2 << "\" database file.\n";
350 continue;
351 }
352
353 if(*o1 == *o2) continue;
354
356 std::cout <<
" DIFFERENCE " << ++
classDiffsCount <<
". The OBJECTS " << o1 <<
" differed:\n";
357
358 int objDiffsCount = 0;
359
360
363
364 if(alist) {
365 for(std::list<OksAttribute *>::const_iterator ai = alist->begin(); ai != alist->end(); ++ai) {
369
370 if(!(*d1 == *d2)) {
371 ++objDiffsCount;
372
373 if(printAttributeDifferences) {
375 <<
" The ATTRIBUTE \"" << a->
get_name() <<
"\" values differed:\n"
376 " the value in the FILE \"" << dataFile1 << "\" is: " << *d1 << "\n"
377 " the value in the FILE \"" << dataFile2 << "\" is: " << *d2 << std::endl;
378 }
379 }
380 }
381 }
382
383
384 if(rlist) {
385 for(std::list<OksRelationship *>::const_iterator ri = rlist->begin(); ri != rlist->end(); ++ri) {
387 OksData * d1(o1->GetRelationshipValue(
r->get_name()));
389
390 if(!(*d1 == *d2)) {
391 ++objDiffsCount;
392
393 if(printRelationshipDifferences) {
395 <<
" The RELATIONSHIP \"" <<
r->get_name() <<
"\" values differed:\n"
396 " the value in the FILE \"" << dataFile1 << "\" is: " << *d1 << "\n"
397 " the value in the FILE \"" << dataFile2 << "\" is: " << *d2 << std::endl;
398 }
399 }
400 }
401 }
402
403 if(objDiffsCount && printCompositeParentsMode) {
404 std::cout << " COMPOSITE PARENT(S) of the OBJECTS " << o1 << ":\n";
407 }
408 }
409
410
411 object_iterator = objects2->begin();
412
413 for(;object_iterator != objects2->end(); ++object_iterator) {
414 const std::string * objUID = (*object_iterator).first;
416
417 if(!o1 && (!object_id || *objUID == object_id)) {
420 " There is no object " << (*object_iterator).second << " in the \"" << dataFile1 << "\" database file.\n";
421 }
422 }
423
425 std::cout << " no differences were found\n";
426 }
427 }
428 }
429
430 catch (oks::exception & ex) {
431 std::cerr << "Caught oks exception:\n" << ex << std::endl;
432 return_status = 10;
433 }
434
435 catch (std::exception & e) {
436 std::cerr << "Caught standard C++ exception: " << e.what() << std::endl;
437 return_status = 10;
438 }
439
440 catch (...) {
441 std::cerr << "Caught unknown exception" << std::endl;
442 return_status = 10;
443 }
444
445 delete [] schemaFiles;
446
447 if(verboseMode)
448 std::cout << "\nExiting " << appName << "...\n";
449
450 return return_status;
451}
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)
the structure to pass common parameters to various read() methods of OksData and OksObject class