43 s <<
"Usage: oks_dump\n"
44 " [--files-only | --files-stat-only | --schema-files-only | --schema-files-stat-only | --data-files-only | "
45 "--data-files-stat-only]\n"
46 " [--class name-of-class [--query query [--print-references recursion-depth [class-name*] [--]] "
47 "[--print-referenced_by [name] [--]]]]\n"
48 " [--path object-from object-to query]\n"
49 " [--allow-duplicated-objects-via-inheritance]\n"
52 " [--input-from-files] database-file [database-file(s)]\n"
55 " -f | --files-only print list of oks files names\n"
56 " -F | --files-stat-only print list of oks files with statistic details (size, "
58 " -s | --schema-files-only print list of schema oks files names\n"
59 " -S | --schema-files-stat-only print list of oks schema files with statistic details\n"
60 " -d | --data-files-only print list of data oks files names\n"
61 " -D | --data-files-stat-only print list of oks data files with statistic details\n"
62 " -c | --class class_name dump given class (all objects or matching some query)\n"
63 " -q | --query query print objects matching query (can only be used with "
65 " -r | --print-references N C1 C2 ... CX print objects referenced by found objects (can only be "
66 "used with query), where:\n"
67 " * the parameter N defines recursion depth for "
68 "referenced objects (> 0)\n"
69 " * the optional set of names {C1 .. CX} defines "
70 "[sub-]classes for above objects\n"
71 " -b | --print-referenced_by [name] print objects referencing found objects (can only be "
72 "used with query), where:\n"
73 " * the optional parameter name defines name of "
75 " -p | --path obj query print path from object \'obj\' to object of query "
77 " -i | --input-from-files read oks files to be loaded from file(s) instead of "
79 " (to avoid problems with long command line, when there is "
80 "huge number of files)\n"
81 " -a | --allow-duplicated-objects-via-inheritance do not stop if there are duplicated object via "
82 "inheritance hierarchy\n"
83 " -v | --version print version\n"
84 " -h | --help print this text\n"
87 " Dumps contents of the OKS database.\n"
90 " 0 - no problems found\n"
91 " 1 - bad command line parameter\n"
92 " 2 - bad oks file(s)\n"
93 " 3 - bad query passed via -q or -p options\n"
94 " 4 - cannot find class passed via -c option\n"
95 " 5 - loaded objects have dangling references\n"
96 " 6 - caught an exception\n"
103 Oks::error_msg(
"oks_dump") <<
"no parameter(s) for command line argument \'" << s <<
"\' provided\n\n";
112 if ((s = strchr(
id,
'@')) == 0)
122 Oks::error_msg(
"oks_dump::find_object()") <<
"cannot find object \"" <<
id <<
'@' << s <<
"\"\n";
125 Oks::error_msg(
"oks_dump::find_object()") <<
"cannot find class \"" << s <<
"\"\n";
144 int dump_files_only = 0;
145 const char* class_name = 0;
146 const char* query = 0;
147 const char* object_from = 0;
148 const char* path_query = 0;
149 long recursion_depth = 0;
150 bool print_referenced_by =
false;
151 const char* ref_by_rel_name =
"*";
152 std::vector<std::string> ref_classes;
153 bool input_from_files =
false;
154 bool print_files_stat =
false;
156 for (
int i = 1; i < argc; i++) {
157 const char* cp = argv[i];
159 if (!strcmp(cp,
"-h") || !strcmp(cp,
"--help")) {
162 }
else if (!strcmp(cp,
"-v") || !strcmp(cp,
"--version")) {
165 }
else if (!strcmp(cp,
"-a") || !strcmp(cp,
"--allow-duplicated-objects-via-inheritance")) {
167 }
else if (!strcmp(cp,
"-f") || !strcmp(cp,
"--files-only")) {
169 }
else if (!strcmp(cp,
"-F") || !strcmp(cp,
"--files-stat-only")) {
171 print_files_stat =
true;
172 }
else if (!strcmp(cp,
"-s") || !strcmp(cp,
"--schema-files-only")) {
174 }
else if (!strcmp(cp,
"-S") || !strcmp(cp,
"--schema-files-stat-only")) {
176 print_files_stat =
true;
177 }
else if (!strcmp(cp,
"-d") || !strcmp(cp,
"--data-files-only")) {
178 dump_files_only = 12;
179 }
else if (!strcmp(cp,
"-D") || !strcmp(cp,
"--data-files-stat-only")) {
180 dump_files_only = 12;
181 print_files_stat =
true;
182 }
else if (!strcmp(cp,
"-c") || !strcmp(cp,
"--class")) {
186 class_name = argv[i];
188 }
else if (!strcmp(cp,
"-q") || !strcmp(cp,
"--query")) {
194 }
else if (!strcmp(cp,
"-i") || !strcmp(cp,
"--input-from-files")) {
195 input_from_files =
true;
196 }
else if (!strcmp(cp,
"-r") || !strcmp(cp,
"--print-references")) {
200 recursion_depth = atol(argv[i]);
203 for (; j < argc - i - 1; ++j) {
204 if (argv[i + 1 + j][0] !=
'-') {
205 ref_classes.push_back(argv[i + 1 + j]);
211 }
else if (!strcmp(cp,
"-b") || !strcmp(cp,
"--print-referenced_by")) {
212 print_referenced_by =
true;
213 if ((i + 1) < argc && argv[i + 1][0] !=
'-') {
214 ref_by_rel_name = argv[++i];
216 }
else if (!strcmp(cp,
"-p") || !strcmp(cp,
"--path")) {
217 if (++i > argc - 1) {
220 object_from = argv[i];
221 path_query = argv[++i];
223 }
else if (strcmp(cp,
"--")) {
224 if (input_from_files) {
227 while (f.good() && !f.eof()) {
228 std::string file_name;
229 std::getline(f, file_name);
230 if (!file_name.empty() && kernel.
load_file(file_name) == 0) {
231 Oks::error_msg(
"oks_dump") <<
"\tCan not load file \"" << file_name <<
"\", exiting...\n";
236 Oks::error_msg(
"oks_dump") <<
"\tCan not open file \"" << cp <<
"\" for reading, exiting...\n";
241 Oks::error_msg(
"oks_dump") <<
"\tCan not load file \"" << cp <<
"\", exiting...\n";
249 Oks::error_msg(
"oks_dump") <<
"\tAt least one oks file have to be provided, exiting...\n";
253 if (query && !class_name) {
255 <<
"\tQuery can only be executed when class name is provided (use -c option), exiting...\n";
259 if (dump_files_only) {
261 long total_items = 0;
263 for (
int j = (dump_files_only / 10); j < (dump_files_only % 10); ++j) {
264 if (!files[j]->empty()) {
265 for (OksFile::Map::const_iterator i = files[j]->begin(); i != files[j]->end(); ++i) {
266 if (print_files_stat) {
267 total_size += i->second->get_size();
268 total_items += i->second->get_number_of_items();
269 std::cout << *(i->first) <<
" (" << i->second->get_number_of_items() <<
" items, "
270 << i->second->get_size() <<
" bytes)" << std::endl;
272 std::cout << *(i->first) << std::endl;
278 if (print_files_stat) {
279 std::cout <<
"Total number of items: " << total_items
281 "Total size of files: "
282 << total_size <<
" bytes" << std::endl;
284 }
else if (class_name && *class_name) {
286 if (query && *query) {
290 size_t num = (objs ? objs->size() : 0);
291 std::cout <<
"Found " << num <<
" matching query \"" << query <<
"\" in class \"" << class_name <<
"\"";
293 std::cout <<
':' << std::endl;
294 while (!objs->empty()) {
298 if (recursion_depth > 0 || print_referenced_by) {
299 if (recursion_depth) {
303 o->
references(refs, recursion_depth,
false, &all_ref_classes);
304 std::cout << o <<
" references " << refs.size() <<
" object(s)" << std::endl;
305 for (OksObject::FSet::const_iterator i = refs.begin(); i != refs.end(); ++i) {
306 std::cout <<
" - " << *i << std::endl;
309 if (print_referenced_by) {
311 std::cout << o <<
" is referenced by " << ref_by_objs->size() <<
" object(s) via relationship \""
312 << ref_by_rel_name <<
"\":" << std::endl;
314 for (OksObject::FList::const_iterator i = ref_by_objs->begin(); i != ref_by_objs->end(); ++i) {
315 std::cout <<
" - " << *i << std::endl;
320 std::cout << o <<
" is not referenced by any object via relationship \"" << ref_by_rel_name
321 <<
'\"' << std::endl;
325 std::cout << *o << std::endl;
330 std::cout << std::endl;
333 Oks::error_msg(
"oks_dump") <<
"\tFailed to parse query \"" << query <<
"\" in class \"" << class_name
339 std::cout << *c << std::endl;
342 Oks::error_msg(
"oks_dump") <<
"\tCan not find class \"" << class_name <<
"\"\n";
345 }
else if (object_from && *object_from && path_query && *path_query) {
351 size_t num = (objs ? objs->size() : 0);
352 std::cout <<
"Found " << num <<
" objects in the path \"" << q <<
"\" from object " << obj_from <<
":"
356 while (!objs->empty()) {
359 std::cout << *o << std::endl;
372 Oks::error_msg(
"oks_dump") <<
"The schema contains dangling references to non-loaded classes:\n"
377 Oks::error_msg(
"oks_dump") <<
"\tThe data contain dangling references to non-loaded objects\n";
384 std::cerr <<
"Caught oks exception:\n" << ex << std::endl;
386 }
catch (std::exception& e) {
387 std::cerr <<
"Caught standard C++ exception: " << e.what() << std::endl;
390 std::cerr <<
"Caught unknown exception" << std::endl;
std::map< const std::string *, OksFile *, SortByName > Map
Provides interface to the OKS kernel.
OksFile * load_file(const std::string &name, bool bind=true)
Load OKS database file.
const OksFile::Map & data_files() const
Get all data files.
const std::string & get_bind_classes_status() const noexcept
Return status of oks classes binding.
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...
const std::string & get_bind_objects_status() const noexcept
Return status of oks objects binding.
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).
const OksFile::Map & schema_files() const
Get all schema files.
void get_all_classes(const std::vector< std::string > &names_in, ClassSet &classes_out) const
The method searches all classes including subclasses for given names.
OksObject describes instance of OksClass.
std::unordered_set< OksObject *, oks::hash_obj_ptr, oks::equal_obj_ptr > FSet
std::list< OksObject * > List
void references(OksObject::FSet &refs, unsigned long recursion_depth, bool add_self=false, oks::ClassSet *classes=0) const
FList * get_all_rels(const std::string &name="*") const
Return objects referencing this one via relationship with given name.
std::list< OksObject *, boost::fast_pool_allocator< OksObject * > > FList
OksObject::List * find_path(const oks::QueryPath &query) const
OksQuery(bool b, OksQueryExpression *q=0)
static std::ostream & error_msg(const char *)
virtual const char * what() const noexcept
int main(int argc, char *argv[])
std::unordered_set< const OksClass *, oks::hash_class_ptr, oks::equal_class_ptr > ClassSet
OksObject * find_object(char *s, OksKernel &k)
static void no_param(const char *s)
static void printUsage(std::ostream &s)
@ __FoundDanglingReferences__