Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * include/stxxl/bits/mng/config.h 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2002-2005 Roman Dementiev <dementiev@mpi-sb.mpg.de> 00007 * Copyright (C) 2008, 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00008 * 00009 * Distributed under the Boost Software License, Version 1.0. 00010 * (See accompanying file LICENSE_1_0.txt or copy at 00011 * http://www.boost.org/LICENSE_1_0.txt) 00012 **************************************************************************/ 00013 00014 #ifndef STXXL_MNG__CONFIG_H 00015 #define STXXL_MNG__CONFIG_H 00016 00017 #include <vector> 00018 #include <string> 00019 #include <cstdlib> 00020 #include <unistd.h> 00021 00022 #include <stxxl/bits/singleton.h> 00023 #include <stxxl/bits/verbose.h> 00024 00025 00026 __STXXL_BEGIN_NAMESPACE 00027 00028 //! \ingroup mnglayer 00029 00030 //! \brief Access point to disks properties 00031 //! \remarks is a singleton 00032 class config : public singleton<config> 00033 { 00034 friend class singleton<config>; 00035 00036 struct DiskEntry 00037 { 00038 std::string path; 00039 std::string io_impl; 00040 stxxl::int64 size; 00041 bool delete_on_exit; 00042 bool autogrow; 00043 }; 00044 00045 std::vector<DiskEntry> disks_props; 00046 00047 // in disks_props, flash devices come after all regular disks 00048 unsigned first_flash; 00049 00050 config() 00051 { 00052 const char * cfg_path = getenv("STXXLCFG"); 00053 if (cfg_path) 00054 init(cfg_path); 00055 else 00056 init(); 00057 } 00058 00059 ~config() 00060 { 00061 for (unsigned i = 0; i < disks_props.size(); ++i) { 00062 if (disks_props[i].delete_on_exit || disks_props[i].autogrow) { 00063 if (!disks_props[i].autogrow) { 00064 STXXL_ERRMSG("Removing disk file created from default configuration: " << disks_props[i].path); 00065 } 00066 unlink(disks_props[i].path.c_str()); 00067 } 00068 } 00069 } 00070 00071 void init(const char * config_path = "./.stxxl"); 00072 00073 public: 00074 //! \brief Returns number of disks available to user 00075 //! \return number of disks 00076 inline unsigned disks_number() const 00077 { 00078 return disks_props.size(); 00079 } 00080 00081 //! \brief Returns contiguous range of regular disks w/o flash devices in the array of all disks 00082 //! \return range [begin, end) of regular disk indices 00083 inline std::pair<unsigned, unsigned> regular_disk_range() const 00084 { 00085 return std::pair<unsigned, unsigned>(0, first_flash); 00086 } 00087 00088 //! \brief Returns contiguous range of flash devices in the array of all disks 00089 //! \return range [begin, end) of flash device indices 00090 inline std::pair<unsigned, unsigned> flash_range() const 00091 { 00092 return std::pair<unsigned, unsigned>(first_flash, (unsigned)disks_props.size()); 00093 } 00094 00095 //! \brief Returns path of disks 00096 //! \param disk disk's identifier 00097 //! \return string that contains the disk's path name 00098 inline const std::string & disk_path(int disk) const 00099 { 00100 return disks_props[disk].path; 00101 } 00102 00103 //! \brief Returns disk size 00104 //! \param disk disk's identifier 00105 //! \return disk size in bytes 00106 inline stxxl::int64 disk_size(int disk) const 00107 { 00108 return disks_props[disk].size; 00109 } 00110 00111 //! \brief Returns name of I/O implementation of particular disk 00112 //! \param disk disk's identifier 00113 inline const std::string & disk_io_impl(int disk) const 00114 { 00115 return disks_props[disk].io_impl; 00116 } 00117 }; 00118 00119 __STXXL_END_NAMESPACE 00120 00121 #endif // !STXXL_MNG__CONFIG_H 00122 // vim: et:ts=4:sw=4