Drizzled Public API Documentation

catalog_writer.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
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 int main(int argc, char* argv[])
00029 {
00030   GOOGLE_PROTOBUF_VERIFY_VERSION;
00031 
00032   string file_name;
00033   message::Catalog catalog;
00034 
00035   if (argc < 2) 
00036   {
00037     cerr << "Usage:  " << argv[0] << " CATALOG" << endl;
00038     return -1;
00039   }
00040 
00041   if (argc == 3)
00042     file_name= argv[2];
00043   else
00044     file_name= argv[1];
00045 
00046   catalog.set_name(argv[1]);
00047   catalog.mutable_engine()->set_name("filesystem");
00048   catalog.set_creation_timestamp(time(NULL));
00049   catalog.set_update_timestamp(time(NULL));
00050   catalog.set_uuid("catalog_writer");
00051   catalog.set_version(1);
00052 
00053   fstream output(file_name.c_str(), ios::out | ios::trunc | ios::binary);
00054 
00055   if (not catalog.SerializeToOstream(&output))
00056   {
00057     cerr << "Failed to write catalog." << endl;
00058     return -1;
00059   }
00060 
00061   return 0;
00062 }