150{
151 appTitle =
"OKS data files comparer. OKS kernel version ";
153
154 bool printAttributeDifferences = false;
155 bool printRelationshipDifferences = false;
156 bool printCompositeParentsMode = false;
157 bool verboseMode = false;
158
159 const char * appName = "oks_diff_data";
160
161 if(argc == 1) {
163 return 1;
164 }
165
166
167
168
169 const char ** schemaFiles = new const char * [argc];
170 schemaFiles[0] = 0;
171
172 const char * dataFile1 = 0;
173 const char * dataFile2 = 0;
174
175 const char * class_name = 0;
176 const char * object_id = 0;
177
178 for(int i = 1; i < argc; i++) {
179 if(!strcmp(argv[i], "-a") || !strcmp(argv[i], "--attributes"))
180 printAttributeDifferences = true;
181 else if(!strcmp(argv[i], "-r") || !strcmp(argv[i], "--relationships"))
182 printRelationshipDifferences = true;
183 else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--composite-parents"))
184 printCompositeParentsMode = true;
185 else if(!strcmp(argv[i], "-all") || !strcmp(argv[i], "--all")) {
186 printAttributeDifferences = true;
187 printRelationshipDifferences = true;
188 printCompositeParentsMode = true;
189 }
190 else if(!strcmp(argv[i], "-b") || !strcmp(argv[i], "--verbose"))
191 verboseMode = true;
192 else if(!strcmp(argv[i], "-h")) {
194 return 0;
195 }
196 else if(!strcmp(argv[i], "--help")) {
198 return 0;
199 }
200 else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
202 return 0;
203 }
204 else if(!strcmp(argv[i], "-s") || !strcmp(argv[i], "--schema-files")) {
205 for(int j = 0; j < argc - i - 1; ++j) {
206 if(argv[i+1+j][0] != '-') schemaFiles[j] = argv[i+1+j];
207 else {
208 schemaFiles[j]=0;
209 i+=j;
210 break;
211 }
212 }
213 }
214 else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--class-name")) {
215 if(argv[i+1][0] != '-') class_name=argv[++i];
216 }
217 else if(!strcmp(argv[i], "-o") || !strcmp(argv[i], "--object-id")) {
218 if(argv[i+1][0] != '-') object_id=argv[++i];
219 }
220 else if(!strcmp(argv[i], "-d1") || !strcmp(argv[i], "--data-file1")) {
221 if(argv[i+1][0] != '-') dataFile1=argv[++i];
222 }
223 else if(!strcmp(argv[i], "-d2") || !strcmp(argv[i], "--data-file2")) {
224 if(argv[i+1][0] != '-') dataFile2=argv[++i];
225 }
226 else {
227 std::cerr << "ERROR: Unknown parameter: \"" << argv[i] << "\"\n\n";
229 return 1;
230 }
231 }
232
233
234
235
236 if(dataFile1 == 0) {
237 std::cerr << "ERROR: First data file is not defined.\n\n";
239 return 1;
240 }
241
242 if(dataFile2 == 0) {
243 std::cerr << "ERROR: Second data file is not defined.\n\n";
245 return 1;
246 }
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
258 int return_status = 0;
259
260
261
262
265
266 try {
267
268 if(!verboseMode) {
271 }
272
273 for(int i=0; schemaFiles[i] != 0; ++i) {
274 const char *s_file = schemaFiles[i];
275
278 }
279
282
284 OksClass::Map::const_iterator class_iterator = classes.begin();
285
286 if(classes.empty()) {
287 std::cerr << "ERROR: No classes were found in loaded schema file(s), exiting ...\n";
288 return 4;
289 }
290
291 std::cout << std::endl;
292
294
296 for(;class_iterator != classes.end(); ++class_iterator) {
297 c1 = class_iterator->second;
298 std::string className(c1->
get_name());
299
300 if(class_name && className != class_name) {
301 continue;
302 }
303
305
306 if(verboseMode) {
307 std::cout << "TESTING IN CLASS \"" << className << "\"... ";
308 std::cout.flush();
309 }
310
314 " Database \'" << dataFile2 << "\' does not have class \"" << className << "\", skip testing ...\n";
315 continue;
316 }
317
318 if(*c1 != *c2) {
321 " Class \"" << className << "\" is different in \"" << dataFile1 << "\" and \"" << dataFile2 << "\", skip testing ...\n";
322 continue;
323 }
324
327 OksObject::Map::const_iterator object_iterator = objects1->begin();
328
329 for(;object_iterator != objects1->end(); ++object_iterator) {
330 const std::string * objUID = (*object_iterator).first;
331 OksObject * o1 = (*object_iterator).second;
332
333 if(object_id && o1->
GetId() != object_id) {
334 continue;
335 }
336
338
339 if(!o2) {
342 " There is no object " << o1 << " in the \"" << dataFile2 << "\" database file.\n";
343 continue;
344 }
345
346 if(*o1 == *o2) continue;
347
349 std::cout <<
" DIFFERENCE " << ++
classDiffsCount <<
". The OBJECTS " << o1 <<
" differed:\n";
350
351 int objDiffsCount = 0;
352
353
356
357 if(alist) {
358 for(std::list<OksAttribute *>::const_iterator ai = alist->begin(); ai != alist->end(); ++ai) {
362
363 if(!(*d1 == *d2)) {
364 ++objDiffsCount;
365
366 if(printAttributeDifferences) {
368 <<
" The ATTRIBUTE \"" << a->
get_name() <<
"\" values differed:\n"
369 " the value in the FILE \"" << dataFile1 << "\" is: " << *d1 << "\n"
370 " the value in the FILE \"" << dataFile2 << "\" is: " << *d2 << std::endl;
371 }
372 }
373 }
374 }
375
376
377 if(rlist) {
378 for(std::list<OksRelationship *>::const_iterator ri = rlist->begin(); ri != rlist->end(); ++ri) {
380 OksData * d1(o1->GetRelationshipValue(
r->get_name()));
382
383 if(!(*d1 == *d2)) {
384 ++objDiffsCount;
385
386 if(printRelationshipDifferences) {
388 <<
" The RELATIONSHIP \"" <<
r->get_name() <<
"\" values differed:\n"
389 " the value in the FILE \"" << dataFile1 << "\" is: " << *d1 << "\n"
390 " the value in the FILE \"" << dataFile2 << "\" is: " << *d2 << std::endl;
391 }
392 }
393 }
394 }
395
396 if(objDiffsCount && printCompositeParentsMode) {
397 std::cout << " COMPOSITE PARENT(S) of the OBJECTS " << o1 << ":\n";
400 }
401 }
402
403
404 object_iterator = objects2->begin();
405
406 for(;object_iterator != objects2->end(); ++object_iterator) {
407 const std::string * objUID = (*object_iterator).first;
409
410 if(!o1 && (!object_id || *objUID == object_id)) {
413 " There is no object " << (*object_iterator).second << " in the \"" << dataFile1 << "\" database file.\n";
414 }
415 }
416
418 std::cout << " no differences were found\n";
419 }
420 }
421 }
422
423 catch (oks::exception & ex) {
424 std::cerr << "Caught oks exception:\n" << ex << std::endl;
425 return_status = 10;
426 }
427
428 catch (std::exception & e) {
429 std::cerr << "Caught standard C++ exception: " << e.what() << std::endl;
430 return_status = 10;
431 }
432
433 catch (...) {
434 std::cerr << "Caught unknown exception" << std::endl;
435 return_status = 10;
436 }
437
438 delete [] schemaFiles;
439
440 if(verboseMode)
441 std::cout << "\nExiting " << appName << "...\n";
442
443 return return_status;
444}
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.
std::unordered_map< const std::string *, OksObject *, oks::hash_str, oks::equal_str > Map
OksData * GetRelationshipValue(const std::string &) const
Get value of relationship by name.
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