Drizzled Public API Documentation

catalog_reader.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <iostream>
00021 #include <fstream>
00022 #include <string>
00023 #include <drizzled/message/catalog.pb.h>
00024 
00025 using namespace std;
00026 using namespace drizzled;
00027 
00028 
00029 /*
00030   Written from Google proto example
00031 */
00032 
00033 static void printCatalog(const message::Catalog *catalog)
00034 {
00035   cout << "CREATE CATALOG `" << catalog->name() << "` ";
00036 
00037   for (int option_nr=0; option_nr < catalog->engine().options_size(); option_nr++)
00038   {
00039     cout << " " << catalog->engine().options(option_nr).name() << " = "
00040          << "'" << catalog->engine().options(option_nr).state() << "'";
00041   }
00042 
00043   cout << ";" << endl;
00044 }
00045 
00046 int main(int argc, char* argv[])
00047 {
00048   GOOGLE_PROTOBUF_VERIFY_VERSION;
00049 
00050   if (argc != 2) {
00051     cerr << "Usage:  " << argv[0] << " CATALOG" << endl;
00052     return -1;
00053   }
00054 
00055   message::Catalog catalog;
00056 
00057   {
00058     // Read the existing address book.
00059     fstream input(argv[1], ios::in | ios::binary);
00060     if (!catalog.ParseFromIstream(&input))
00061     {
00062       cerr << "Failed to parse catalog." << endl;
00063       return -1;
00064     }
00065   }
00066 
00067   printCatalog(&catalog);
00068 
00069   return 0;
00070 }