121{
122 if(argc == 1) {
125 }
126
129
130 try {
131
132 int dump_files_only = 0;
133 const char * class_name = 0;
134 const char * query = 0;
135 const char * object_from = 0;
136 const char * path_query = 0;
137 long recursion_depth = 0;
139 const char * ref_by_rel_name = "*";
140 std::vector<std::string> ref_classes;
141 bool input_from_files = false;
142 bool print_files_stat = false;
143
144 for(int i = 1; i < argc; i++) {
145 const char * cp = argv[i];
146
147 if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
150 }
151 else if(!strcmp(cp, "-v") || !strcmp(cp, "--version")) {
154 }
155 else if(!strcmp(cp, "-a") || !strcmp(cp, "--allow-duplicated-objects-via-inheritance")) {
157 }
158 else if(!strcmp(cp, "-f") || !strcmp(cp, "--files-only")) {
159 dump_files_only = 2;
160 }
161 else if(!strcmp(cp, "-F") || !strcmp(cp, "--files-stat-only")) {
162 dump_files_only = 2;
163 print_files_stat = true;
164 }
165 else if(!strcmp(cp, "-s") || !strcmp(cp, "--schema-files-only")) {
166 dump_files_only = 1;
167 }
168 else if(!strcmp(cp, "-S") || !strcmp(cp, "--schema-files-stat-only")) {
169 dump_files_only = 1;
170 print_files_stat = true;
171 }
172 else if(!strcmp(cp, "-d") || !strcmp(cp, "--data-files-only")) {
173 dump_files_only = 12;
174 }
175 else if(!strcmp(cp, "-D") || !strcmp(cp, "--data-files-stat-only")) {
176 dump_files_only = 12;
177 print_files_stat = true;
178 }
179 else if(!strcmp(cp, "-c") || !strcmp(cp, "--class")) {
180 if(++i == argc) {
no_param(cp); }
else { class_name = argv[i]; }
181 }
182 else if(!strcmp(cp, "-q") || !strcmp(cp, "--query")) {
183 if(++i == argc) {
no_param(cp); }
else { query = argv[i]; }
184 }
185 else if(!strcmp(cp, "-i") || !strcmp(cp, "--input-from-files")) {
186 input_from_files = true;
187 }
188 else if(!strcmp(cp, "-r") || !strcmp(cp, "--print-references")) {
189 if(++i == argc) {
no_param(cp); }
else { recursion_depth = atol(argv[i]); }
190 int j = 0;
191 for(; j < argc - i - 1; ++j) {
192 if(argv[i+1+j][0] != '-') { ref_classes.push_back(argv[i+1+j]); } else { break; }
193 }
194 i += j;
195 }
196 else if(!strcmp(cp, "-b") || !strcmp(cp, "--print-referenced_by")) {
198 if((i+1) < argc && argv[i+1][0] != '-') {
199 ref_by_rel_name = argv[++i];
200 }
201 }
202 else if(!strcmp(cp, "-p") || !strcmp(cp, "--path")) {
203 if(++i > argc - 1) {
no_param(cp); }
else { object_from = argv[i]; path_query = argv[++i];}
204 }
205 else if(strcmp(cp, "--")) {
206 if(input_from_files) {
209 while(
f.good() && !
f.eof()) {
210 std::string file_name;
211 std::getline(f, file_name);
212 if(!file_name.empty() && kernel.
load_file(file_name) == 0) {
213 Oks::error_msg(
"oks_dump") <<
"\tCan not load file \"" << file_name <<
"\", exiting...\n";
215 }
216 }
217 }
218 else {
219 Oks::error_msg(
"oks_dump") <<
"\tCan not open file \"" << cp <<
"\" for reading, exiting...\n";
221 }
222 }
223 else {
225 Oks::error_msg(
"oks_dump") <<
"\tCan not load file \"" << cp <<
"\", exiting...\n";
227 }
228 }
229 }
230 }
231
233 Oks::error_msg(
"oks_dump") <<
"\tAt least one oks file have to be provided, exiting...\n";
235 }
236
237 if(query && !class_name) {
238 Oks::error_msg(
"oks_dump") <<
"\tQuery can only be executed when class name is provided (use -c option), exiting...\n";
240 }
241
242 if(dump_files_only) {
243 long total_size = 0;
244 long total_items = 0;
246 for(int j = (dump_files_only / 10); j < (dump_files_only % 10); ++j) {
247 if(!files[j]->empty()) {
248 for(OksFile::Map::const_iterator i = files[j]->begin(); i != files[j]->end(); ++i) {
249 if(print_files_stat) {
250 total_size += i->second->get_size();
251 total_items += i->second->get_number_of_items();
252 std::cout << *(i->first) << " (" << i->second->get_number_of_items() << " items, " << i->second->get_size() << " bytes)" << std::endl;
253 }
254 else {
255 std::cout << *(i->first) << std::endl;
256 }
257 }
258 }
259 }
260
261 if(print_files_stat) {
262 std::cout << "Total number of items: " << total_items << "\n"
263 "Total size of files: " << total_size << " bytes" << std::endl;
264 }
265 }
266 else if(class_name && *class_name) {
268 if(query && *query) {
272 size_t num = (objs ? objs->size() : 0);
273 std::cout << "Found " << num << " matching query \"" << query << "\" in class \"" << class_name << "\"";
274 if(num) {
275 std::cout << ':' << std::endl;
276 while(!objs->empty()) {
278 objs->pop_front();
279
281 if(recursion_depth) {
285 o->
references(refs, recursion_depth,
false, &all_ref_classes);
286 std::cout << o << " references " << refs.size() << " object(s)" << std::endl;
287 for(OksObject::FSet::const_iterator i = refs.begin(); i != refs.end(); ++i) {
288 std::cout << " - " << *i << std::endl;
289 }
290 }
293 std::cout << o << " is referenced by " << ref_by_objs->size() << " object(s) via relationship \"" << ref_by_rel_name << "\":" << std::endl;
294
295 for(OksObject::FList::const_iterator i = ref_by_objs->begin(); i != ref_by_objs->end(); ++i) {
296 std::cout << " - " << *i << std::endl;
297 }
298
299 delete ref_by_objs;
300 }
301 else {
302 std::cout << o << " is not referenced by any object via relationship \"" << ref_by_rel_name << '\"' << std::endl;
303 }
304 }
305 }
306 else {
307 std::cout << *o << std::endl;
308 }
309 }
310 delete objs;
311 }
312 else {
313 std::cout << std::endl;
314 }
315 }
316 else {
317 Oks::error_msg(
"oks_dump") <<
"\tFailed to parse query \"" << query <<
"\" in class \"" << class_name <<
"\"\n";
319 }
320 delete q;
321 }
322 else {
323 std::cout << *
c << std::endl;
324 }
325 }
326 else {
327 Oks::error_msg(
"oks_dump") <<
"\tCan not find class \"" << class_name <<
"\"\n";
329 }
330 }
331 else if(object_from && *object_from && path_query && *path_query) {
333 try {
336
337 size_t num = (objs ? objs->size() : 0);
338 std::cout << "Found " << num << " objects in the path \"" << q << "\" from object " << obj_from << ":" << std::endl;
339
340 if(num) {
341 while(!objs->empty()) {
343 objs->pop_front();
344 std::cout << *o << std::endl;
345 }
346 delete objs;
347 }
348 }
352 }
353 }
354 else {
355 std::cout << kernel;
356 }
357
359 {
361 }
362
364 {
365 Oks::error_msg(
"oks_dump") <<
"\tThe data contain dangling references to non-loaded objects\n";
366 }
367
369 {
371 }
372 }
374 std::cerr << "Caught oks exception:\n" << ex << std::endl;
376 }
377 catch (std::exception & e) {
378 std::cerr << "Caught standard C++ exception: " << e.what() << std::endl;
380 }
381 catch (...) {
382 std::cerr << "Caught unknown exception" << std::endl;
384 }
385
387}
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.
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.
std::list< OksObject * > List
void references(OksObject::FSet &refs, unsigned long recursion_depth, bool add_self=false, oks::ClassSet *classes=0) const
std::unordered_set< OksObject *, oks::hash_obj_ptr, oks::equal_obj_ptr > FSet
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
virtual const char * what() const noexcept
static void print_referenced_by(const ConfigObject &obj, const char *prefix)
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)