TPIE

2362a60
posix.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2009, 2010, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
23 
24 #ifndef _TPIE_FILE_ACCESSOR_POSIX_H
25 #define _TPIE_FILE_ACCESSOR_POSIX_H
26 
28 namespace tpie {
29 namespace file_accessor {
30 
34 
35 class posix {
36 private:
37  int m_fd;
38  cache_hint m_cacheHint;
39 
40 public:
41  inline posix();
42  inline ~posix() {close_i();}
43 
44  inline void open_ro(const std::string & path);
45  inline void open_wo(const std::string & path);
46  inline bool try_open_rw(const std::string & path);
47  inline void open_rw_new(const std::string & path);
48 
49  inline void read_i(void * data, memory_size_type size);
50  inline void write_i(const void * data, memory_size_type size);
51  inline void seek_i(stream_size_type offset);
52  inline stream_size_type file_size_i();
53  inline void close_i();
54  inline void truncate_i(stream_size_type bytes);
55  inline bool is_open() const;
56 
61  static inline void throw_errno(std::string path = std::string());
62 
63  inline void set_cache_hint(cache_hint cacheHint);
64 
65 private:
66  inline void _open(const std::string & path, int flags, mode_t mode);
67  inline void give_advice();
68 };
69 
70 }
71 }
72 
73 #include <tpie/file_accessor/posix.inl>
74 
75 #endif //_TPIE_FILE_ACCESSOR_POSIX_H
cache_hint
Definition: cache_hint.h:28
static void throw_errno(std::string path=std::string())
Check the global errno variable and throw an exception that matches its value.
Reads and writes stream headers, user data and blocks from TPIE streams.
POSIX-style file accessor.
Definition: posix.h:35