Stxxl  1.3.2
config.h
1 /***************************************************************************
2  * include/stxxl/bits/mng/config.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002-2005 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008, 2009 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef STXXL_MNG__CONFIG_H
15 #define STXXL_MNG__CONFIG_H
16 
17 #include <vector>
18 #include <string>
19 #include <cstdlib>
20 
21 #include <stxxl/bits/singleton.h>
22 #include <stxxl/bits/verbose.h>
23 
24 
25 __STXXL_BEGIN_NAMESPACE
26 
28 
31 class config : public singleton<config>
32 {
33  friend class singleton<config>;
34 
35  struct DiskEntry
36  {
37  std::string path;
38  std::string io_impl;
39  stxxl::int64 size;
40  bool delete_on_exit;
41  bool autogrow;
42  };
43 
44  std::vector<DiskEntry> disks_props;
45 
46  // in disks_props, flash devices come after all regular disks
47  unsigned first_flash;
48 
49  config()
50  {
51  const char * cfg_path = getenv("STXXLCFG");
52  if (cfg_path)
53  init(cfg_path);
54  else
55  init();
56  }
57 
58  ~config()
59  {
60  for (unsigned i = 0; i < disks_props.size(); ++i) {
61  if (disks_props[i].delete_on_exit || disks_props[i].autogrow) {
62  if (!disks_props[i].autogrow) {
63  STXXL_ERRMSG("Removing disk file created from default configuration: " << disks_props[i].path);
64  }
65  unlink(disks_props[i].path.c_str());
66  }
67  }
68  }
69 
70  void init(const char * config_path = "./.stxxl");
71 
72 public:
75  inline unsigned disks_number() const
76  {
77  return disks_props.size();
78  }
79 
82  inline std::pair<unsigned, unsigned> regular_disk_range() const
83  {
84  return std::pair<unsigned, unsigned>(0, first_flash);
85  }
86 
89  inline std::pair<unsigned, unsigned> flash_range() const
90  {
91  return std::pair<unsigned, unsigned>(first_flash, (unsigned)disks_props.size());
92  }
93 
97  inline const std::string & disk_path(int disk) const
98  {
99  return disks_props[disk].path;
100  }
101 
105  inline stxxl::int64 disk_size(int disk) const
106  {
107  return disks_props[disk].size;
108  }
109 
112  inline const std::string & disk_io_impl(int disk) const
113  {
114  return disks_props[disk].io_impl;
115  }
116 };
117 
118 __STXXL_END_NAMESPACE
119 
120 #endif // !STXXL_MNG__CONFIG_H
121 // vim: et:ts=4:sw=4
const std::string & disk_io_impl(int disk) const
Returns name of I/O implementation of particular disk.
Definition: config.h:112
stxxl::int64 disk_size(int disk) const
Returns disk size.
Definition: config.h:105
const std::string & disk_path(int disk) const
Returns path of disks.
Definition: config.h:97
std::pair< unsigned, unsigned > regular_disk_range() const
Returns contiguous range of regular disks w/o flash devices in the array of all disks.
Definition: config.h:82
std::pair< unsigned, unsigned > flash_range() const
Returns contiguous range of flash devices in the array of all disks.
Definition: config.h:89
unsigned disks_number() const
Returns number of disks available to user.
Definition: config.h:75
Access point to disks properties.
Definition: config.h:31