storage_factory.cpp
Go to the documentation of this file.
00001 #include <megatree/storage_factory.h>
00002 
00003 #include <megatree/viz_storage.h>
00004 #include <megatree/disk_storage.h>
00005 #ifdef USE_HBASE
00006   #include <megatree/hbase_storage.h>
00007 #endif
00008 
00009 
00010 namespace megatree {
00011 
00012 enum { UNKNOWN_STORAGE, DISK_STORAGE, HBASE_STORAGE, CLIENT_STORAGE };
00013 
00014 int storageType(const boost::filesystem::path &path)
00015 {
00016   if (path.string().substr(0, 8) == std::string("hbase://"))
00017     return HBASE_STORAGE;
00018 
00019   return DISK_STORAGE;
00020 }
00021 
00022 boost::shared_ptr<Storage> openStorage(const boost::filesystem::path &path, unsigned format)
00023 {
00024   boost::shared_ptr<Storage> storage;
00025   int storage_type = storageType(path);
00026 
00027   switch (format)
00028   {
00029   case NORMAL_FORMAT:
00030     {
00031       switch (storage_type)
00032       {
00033       case DISK_STORAGE:
00034         storage.reset(new DiskStorage(path));
00035         break;
00036 
00037 #ifdef USE_HBASE 
00038       case HBASE_STORAGE:
00039         storage.reset(new HbaseStorage(path));
00040         break;
00041 #endif
00042 
00043       case UNKNOWN_STORAGE:
00044         fprintf(stderr, "Unknown storage type for format 1: %s\n", path.string().c_str());
00045         storage.reset();
00046         break;
00047       default:
00048         abort();
00049         break;
00050       }
00051     }
00052     break;
00053 
00054   case VIZ_FORMAT:
00055     {
00056       switch (storage_type)
00057       {
00058       case DISK_STORAGE:
00059         storage.reset(new VizStorage(path));
00060         break;
00061 
00062 #ifdef USE_HBASE
00063       case HBASE_STORAGE:
00064         storage.reset(new VizStorage(path));
00065         break;
00066 #endif
00067 
00068       case UNKNOWN_STORAGE:
00069         fprintf(stderr, "Unknown storage type for format 2: %s\n", path.string().c_str());
00070         storage.reset();
00071         break;
00072       default:
00073         abort();
00074         break;
00075       }
00076     }
00077     break;
00078 
00079   default:
00080     {
00081       fprintf(stderr, "Unknown storage format: %d\n", format);
00082       abort();
00083     }
00084     break;
00085   }
00086 
00087   return storage;
00088 }
00089 
00090 boost::shared_ptr<TempDir> createTempDir(const boost::filesystem::path &parent, bool remove)
00091 {
00092   boost::shared_ptr<TempDir> tempdir; 
00093   
00094   switch (storageType(parent))
00095   {
00096   case DISK_STORAGE:
00097     tempdir.reset(new DiskTempDir(parent, remove));
00098     break;
00099   case UNKNOWN_STORAGE:
00100     fprintf(stderr, "Unknown storage type: %s\n", parent.string().c_str());
00101     tempdir.reset();
00102     break;
00103   default:
00104     abort();
00105     break;
00106   }
00107 
00108   return tempdir;
00109 }
00110 
00111 
00112 void removePath(const boost::filesystem::path &path)
00113 {
00114   switch (storageType(path))
00115   {
00116   case DISK_STORAGE:
00117     boost::filesystem::remove_all(path);
00118     break;
00119 #ifdef USE_HBASE
00120   case HBASE_STORAGE:
00121     removeHbasePath(path);
00122     break;
00123 #endif
00124   case UNKNOWN_STORAGE:
00125     fprintf(stderr, "Unknown storage type: %s\n", path.string().c_str());
00126     break;
00127   default:
00128     abort();
00129     break;
00130   }
00131 }
00132 
00133 }


megatree_storage
Author(s): Wim Meeussen
autogenerated on Mon Dec 2 2013 13:01:19