TPIE

2362a60
file_manager.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 //
4 // Copyright 2011, The TPIE development team
5 //
6 // This file is part of TPIE.
7 //
8 // TPIE is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License as published by the
10 // Free Software Foundation, either version 3 of the License, or (at your
11 // option) any later version.
12 //
13 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
14 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 // License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
20 
24 
25 #ifndef __TPIE_FILE_MANAGER_H__
26 #define __TPIE_FILE_MANAGER_H__
27 
28 #include <tpie/config.h>
29 #include <tpie/util.h>
30 #include <tpie/resource_manager.h>
31 #include <mutex>
32 #include <unordered_map>
33 #include <type_traits>
34 #include <utility>
35 #include <atomic>
36 
37 namespace tpie {
38 
42 class file_manager final : public resource_manager {
43 public:
48  file_manager();
49 
50  void increment_open_file_count() {
51  register_increased_usage(1);
52  }
53 
54  void decrement_open_file_count() {
55  register_decreased_usage(1);
56  }
57 
58  std::string amount_with_unit(size_t amount) const override {
59  std::ostringstream os;
60  if (amount == 1) {
61  os << "a file";
62  } else {
63  os << amount << " files";
64  }
65  return os.str();
66  }
67 
68 protected:
69  void throw_out_of_resource_error(const std::string & s) override {
70  throw out_of_files_error(s);
71  }
72 };
73 
77 void init_file_manager();
78 
82 void finish_file_manager();
83 
90 
91 } //namespace tpie
92 
93 #endif //__TPIE_MEMORY_H__
Resource management object used to track resource usage.
file_manager & get_file_manager()
Return a reference to the file manager.
Miscellaneous utility functions.
File management object used to track file usage.
Definition: file_manager.h:42
void finish_file_manager()
Used by tpie_finish to deinitialize the file manager.
void init_file_manager()
Used by tpie_init to initialize the file manager.