util.cc

Go to the documentation of this file.
00001 ///
00002 /// \file       util.cc
00003 ///             Misc. utility functions for command line tools.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2012, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #include "util.h"
00023 
00024 #include <barry/barry.h>
00025 #ifdef __BARRY_SYNC_MODE__
00026 #include <barry/barrysync.h>
00027 #endif
00028 
00029 #include <iostream>
00030 
00031 using namespace std;
00032 using namespace Barry;
00033 
00034 void ShowParsers(bool show_fields, bool show_mime_support)
00035 {
00036         cout << "Supported Database parsers:\n";
00037 
00038 #ifdef __BARRY_SYNC_MODE__
00039         if( show_mime_support )
00040                 cout << " (* = can display in vformat MIME mode)\n";
00041 
00042 #define MIME_DOT(tname) (MimeDump<tname>::Supported() && show_mime_support ? " *" : "")
00043 
00044 #else
00045 #define MIME_DOT(tname) ""
00046 #endif
00047 
00048 #undef HANDLE_PARSER
00049 #define HANDLE_PARSER(tname) \
00050         { \
00051                 cout << "   " << tname::GetDBName() << MIME_DOT(tname) << "\n"; \
00052                 if( show_fields ) { \
00053                         cout << "      "; \
00054                         FieldHandle<tname>::ListT::const_iterator \
00055                                         fhi = tname::GetFieldHandles().begin(), \
00056                                         fhe = tname::GetFieldHandles().end(); \
00057                         for( int count = 0, len = 6; fhi != fhe; ++fhi, ++count ) { \
00058                                 if( count ) { \
00059                                         cout << ", "; \
00060                                         len += 2; \
00061                                 } \
00062                                 std::string name = fhi->GetIdentity().Name; \
00063                                 if( len + name.size() >= 75 ) { \
00064                                         cout << "\n      "; \
00065                                         len = 6; \
00066                                 } \
00067                                 cout << name; \
00068                                 len += name.size(); \
00069                         } \
00070                         cout << "\n"; \
00071                 } \
00072         }
00073 
00074         ALL_KNOWN_PARSER_TYPES
00075 
00076         cout << endl;
00077 }
00078 
00079 void ShowBuilders()
00080 {
00081         cout << "Supported Database builders:\n";
00082 
00083 #undef HANDLE_BUILDER
00084 #define HANDLE_BUILDER(tname) cout << "   " << tname::GetDBName() << "\n";
00085         ALL_KNOWN_BUILDER_TYPES
00086 
00087         cout << endl;
00088 }
00089