00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00021 #include <stxxl/bits/singleton.h>
00022 #include <stxxl/bits/verbose.h>
00023
00024
00025 __STXXL_BEGIN_NAMESPACE
00026
00028
00031 class config : public singleton<config>
00032 {
00033 friend class singleton<config>;
00034
00035 struct DiskEntry
00036 {
00037 std::string path;
00038 std::string io_impl;
00039 stxxl::int64 size;
00040 bool delete_on_exit;
00041 bool autogrow;
00042 };
00043
00044 std::vector<DiskEntry> disks_props;
00045
00046
00047 unsigned first_flash;
00048
00049 config()
00050 {
00051 const char * cfg_path = getenv("STXXLCFG");
00052 if (cfg_path)
00053 init(cfg_path);
00054 else
00055 init();
00056 }
00057
00058 ~config()
00059 {
00060 for (unsigned i = 0; i < disks_props.size(); ++i) {
00061 if (disks_props[i].delete_on_exit || disks_props[i].autogrow) {
00062 if (!disks_props[i].autogrow) {
00063 STXXL_ERRMSG("Removing disk file created from default configuration: " << disks_props[i].path);
00064 }
00065 unlink(disks_props[i].path.c_str());
00066 }
00067 }
00068 }
00069
00070 void init(const char * config_path = "./.stxxl");
00071
00072 public:
00075 inline unsigned disks_number() const
00076 {
00077 return disks_props.size();
00078 }
00079
00082 inline std::pair<unsigned, unsigned> regular_disk_range() const
00083 {
00084 return std::pair<unsigned, unsigned>(0, first_flash);
00085 }
00086
00089 inline std::pair<unsigned, unsigned> flash_range() const
00090 {
00091 return std::pair<unsigned, unsigned>(first_flash, (unsigned)disks_props.size());
00092 }
00093
00097 inline const std::string & disk_path(int disk) const
00098 {
00099 return disks_props[disk].path;
00100 }
00101
00105 inline stxxl::int64 disk_size(int disk) const
00106 {
00107 return disks_props[disk].size;
00108 }
00109
00112 inline const std::string & disk_io_impl(int disk) const
00113 {
00114 return disks_props[disk].io_impl;
00115 }
00116 };
00117
00118 __STXXL_END_NAMESPACE
00119
00120 #endif // !STXXL_MNG__CONFIG_H
00121