17#include <boost/program_options.hpp>
35typedef std::set<const OksObject *, SortObjById>
ObjsSet;
42 bool printed_class(
false);
45 std::cout <<
"* processing class \'" << c->get_name() <<
"\'" << std::endl;
50 if(!objects || objects->empty()) {
52 std::cout <<
" no objects" << std::endl;
57 std::multimap<std::string, const OksObject *> vals;
59 const std::list<OksAttribute *> * alist = c->all_attributes();
60 const std::list<OksRelationship *> * rlist = c->all_relationships();
64 for(OksObject::Map::const_iterator i = objects->begin(); i != objects->end(); ++i) {
70 for(std::list<OksAttribute *>::const_iterator j = alist->begin(); j != alist->end(); ++j, ++d) {
71 s << (*j)->get_name() << *d <<
'\n';
76 for(std::list<OksRelationship *>::const_iterator j = rlist->begin(); j != rlist->end(); ++j, ++d) {
77 s << (*j)->get_name() << *d <<
'\n';
83 vals.insert(std::make_pair(s.str(), o));
89 for(std::multimap<std::string, const OksObject *>::iterator i = vals.begin(); i != vals.end(); ) {
90 if(last == i->first) {
92 equal_objs.insert(prev);
93 equal_objs.insert(i->second);
95 for(; i != vals.end(); ++i) {
96 if(last == i->first) {
97 equal_objs.insert(i->second);
101 std::cout <<
"* found equal objects in class \'" << c->get_name() <<
"\'" << std::endl;
102 printed_class =
true;
105 std::cout <<
" # the following " << equal_objs.size() <<
" objects are equal:\n";
106 for(ObjsSet::const_iterator j = equal_objs.begin(); j != equal_objs.end(); ++j) {
107 std::cout <<
" - " << (*j) <<
" from \'" << (*j)->get_file()->get_full_file_name() <<
"\'\n";
127namespace po = boost::program_options;
132 std::vector<std::string> files;
133 std::string class_name;
137 po::options_description desc(
"This program is loading OKS data files and searching for equal object.\nUsage: oks_report_equal_objects [options] [-f] file+ ");
140 (
"class,c" , po::value<std::string>(&class_name) ,
"If defined, only compare objects of this class")
141 (
"files,f" , po::value<std::vector<std::string> >(&files) ,
"Names of input OKS files")
142 (
"verbose,v" ,
"Run in verbose mode")
143 (
"help,h" ,
"Print help message")
146 po::positional_options_description p;
149 po::variables_map vm;
150 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).
run(), vm);
153 if(vm.count(
"help")) { std::cout << desc << std::endl;
return EXIT_SUCCESS; }
154 if(vm.count(
"verbose")) { verbose =
true; }
156 if(files.empty()) {
throw std::runtime_error(
"Missing application name" ); }
158 catch(std::exception& ex) {
159 std::cerr <<
"ERROR: " << ex.what() << std::endl;
168 for(std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
172 if(!class_name.empty()) {
178 std::cerr <<
"ERROR: cannot find class \'" << class_name <<
'\'' << std::endl;
183 for(OksClass::Map::const_iterator i = kernel.
classes().begin(); i != kernel.
classes().end(); ++i) {
188 std::cerr <<
"ERROR: " << ex.what() << std::endl;
Provides interface to the OKS kernel.
OksFile * load_file(const std::string &name, bool bind=true)
Load OKS database 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:
void set_test_duplicated_objects_via_inheritance_mode(const bool b)
Set status of test inherited duplicated objects mode. To switch 'On'/'Off' use the method's parameter...
OksClass * find_class(const std::string &class_name) const
Find class by name (C++ string).
OksObject describes instance of OksClass.
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 volatile sig_atomic_t run
int main(int argc, char **argv)
static void process_class(const OksClass *c, bool verbose)
std::set< const OksObject *, SortObjById > ObjsSet
bool operator()(const OksObject *o1, const OksObject *o2) const
Struct OKS data information.
the structure to pass common parameters to various read() methods of OksData and OksObject class