SAGA Adaptor CPI v.1.0
|
00001 #ifndef SAGA_PACKAGES_DATA_FILESYSTEM_FILE_HPP 00002 #define SAGA_PACKAGES_DATA_FILESYSTEM_FILE_HPP 00003 00004 #if defined(__WAVE__) && defined(SAGA_CREATE_PREPROCESSED_FILES) 00005 #pragma wave option(preserve: 2, line: 1, output: "preprocessed/file.hpp") 00006 #endif 00007 // Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) 00008 // Copyright (c) 2005-2009 Hartmut Kaiser 00009 // Copyright (c) 2007 Ole Weidner (oweidner@cct.lsu.edu) 00010 // 00011 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00012 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00013 00014 #if defined(__WAVE__) && defined(SAGA_CREATE_PREPROCESSED_FILES) 00015 #pragma wave option(output: null) 00016 #endif 00017 00018 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 00019 #pragma once 00020 #endif 00021 00022 #include <string> 00023 00024 // include dependent spec sections 00025 #include <saga/saga/util.hpp> 00026 #include <saga/saga/base.hpp> 00027 #include <saga/saga/types.hpp> 00028 #include <saga/saga/session.hpp> 00029 #include <saga/saga/call.hpp> 00030 00031 #include <saga/saga/packages/namespace/namespace_entry.hpp> 00032 #include <saga/saga/packages/filesystem/config.hpp> 00033 #include <saga/saga/packages/filesystem/iovec.hpp> 00034 00035 // suppress warnings about dependent classes not being exported from the dll 00036 #if defined(BOOST_MSVC) 00037 #pragma warning(push) 00038 #pragma warning(disable: 4251 4231 4275 4660) 00039 #endif 00040 00041 #ifdef SAGA_DEBUG 00042 #include <saga/saga/packages/filesystem/preprocessed/file.hpp> 00043 #else 00044 00045 #if defined(__WAVE__) && defined(SAGA_CREATE_PREPROCESSED_FILES) 00046 #pragma wave option(preserve: 2, line: 1, output: "preprocessed/file.hpp") 00047 #endif 00048 00049 namespace saga 00050 { 00057 namespace filesystem { 00064 enum flags 00065 { 00066 Unknown = /* -1, */ saga::name_space::Unknown , 00067 None = /* 0, */ saga::name_space::None , 00068 Overwrite = /* 1, */ saga::name_space::Overwrite , 00069 Recursive = /* 2, */ saga::name_space::Recursive , 00070 Dereference = /* 4, */ saga::name_space::Dereference, 00071 Create = /* 8, */ saga::name_space::Create , 00072 Exclusive = /* 16, */ saga::name_space::Exclusive , 00073 Lock = /* 32, */ saga::name_space::Lock , 00074 CreateParents = /* 64, */ saga::name_space::CreateParents , 00075 Truncate = 128, 00076 Append = 256, 00077 Read = /* 512, */ saga::name_space::Read, 00078 Write = /*1024, */ saga::name_space::Write, 00079 ReadWrite = /*Read | Write, */ saga::name_space::ReadWrite, 00080 Binary = 2048 00081 }; 00082 00087 enum seek_mode 00088 { 00089 Start = 1, 00090 Current = 2, 00091 End = 3 00092 }; 00093 00103 class SAGA_FILESYSTEM_PACKAGE_EXPORT file 00104 : public saga::name_space::entry 00105 { 00106 00107 private: 00109 // factory 00110 SAGA_CALL_CREATE_PRIV_3(session const&, saga::url, int) 00111 00112 00113 SAGA_CALL_PRIV_0 (get_size) 00114 SAGA_CALL_PRIV_2 (read, saga::mutable_buffer, saga::ssize_t) 00115 SAGA_CALL_PRIV_2 (write, saga::const_buffer, saga::ssize_t) 00116 SAGA_CALL_PRIV_2 (seek, saga::off_t, seek_mode) 00117 00118 // scattered I/O 00119 SAGA_CALL_PRIV_1 (read_v, std::vector<saga::filesystem::iovec>) 00120 SAGA_CALL_PRIV_1 (write_v, std::vector<saga::filesystem::const_iovec>) 00121 00122 // pattern based I/O 00123 SAGA_CALL_PRIV_1 (size_p, std::string) 00124 SAGA_CALL_PRIV_2 (read_p, std::string, saga::mutable_buffer) 00125 SAGA_CALL_PRIV_2 (write_p, std::string, saga::const_buffer) 00126 00127 // extended based I/O 00128 SAGA_CALL_PRIV_0 (modes_e) 00129 SAGA_CALL_PRIV_2 (size_e, std::string, std::string) 00130 SAGA_CALL_PRIV_3 (read_e, std::string, std::string, saga::mutable_buffer) 00131 SAGA_CALL_PRIV_3 (write_e, std::string, std::string, saga::const_buffer) 00133 00134 protected: 00136 00137 TR1::shared_ptr <saga::impl::file> get_impl_sp (void) const; 00138 saga::impl::file* get_impl (void) const; 00139 friend class saga::impl::file; 00140 explicit file (saga::impl::file * init); 00141 file (session const& s, saga::url url, int mode, saga::off_t pointer); 00143 00144 public: 00149 file (session const& s, saga::url url, int mode = Read); 00150 00155 explicit file (saga::url url, int mode = Read); 00156 00161 explicit file (saga::object const& o); 00162 00167 file (void); 00168 00173 ~file (void); 00174 00178 static file create(session const & s, saga::url url, int mode = Read) 00179 { 00180 return file(s, url, mode); 00181 } 00182 SAGA_CALL_CREATE_3_DEF_1(session const&, saga::url, int, Read) 00183 00184 00186 static file create(saga::url url, int mode = Read) 00187 { 00188 return file(url, mode); 00189 } 00190 template <typename Tag> 00191 static saga::task create(saga::url url, int mode = Read) 00192 { 00193 return create<Tag>(detail::get_the_session(), url, mode); 00194 } 00195 00200 file &operator= (saga::object const& o); 00201 00206 saga::off_t get_size(void) 00207 { 00208 saga::task t = get_sizepriv(saga::task_base::Sync()); 00209 return t.get_result<saga::off_t>(); 00210 } 00211 SAGA_CALL_PUB_0_DEF_0(get_size) 00212 00213 00222 saga::ssize_t read(saga::mutable_buffer buffer, 00223 saga::ssize_t length = 0) 00224 { 00225 saga::task t = readpriv(buffer, length, saga::task_base::Sync()); 00226 return t.get_result<saga::ssize_t>(); 00227 } 00228 SAGA_CALL_PUB_2_DEF_1(read, saga::mutable_buffer, saga::ssize_t, 0) 00229 00230 00239 saga::ssize_t write(saga::const_buffer buffer, 00240 saga::ssize_t length = 0) 00241 { 00242 saga::task t = writepriv(buffer, length, saga::task_base::Sync()); 00243 return t.get_result<saga::ssize_t>(); 00244 } 00245 SAGA_CALL_PUB_2_DEF_1(write, saga::const_buffer, saga::ssize_t, 0) 00246 00247 00255 saga::off_t seek(saga::off_t offset, seek_mode mode) 00256 { 00257 saga::task t = seekpriv(offset, mode, saga::task_base::Sync()); 00258 return t.get_result<saga::off_t>(); 00259 } 00260 SAGA_CALL_PUB_2_DEF_0(seek, saga::off_t, seek_mode) 00261 00262 00271 void read_v(std::vector<saga::filesystem::iovec> buffer_vec) 00272 { 00273 saga::task t = read_vpriv(buffer_vec, saga::task_base::Sync()); 00274 t.get_result (); 00275 } 00276 SAGA_CALL_PUB_1_DEF_0(read_v, std::vector<saga::filesystem::iovec>) 00277 00278 00286 void write_v(std::vector<saga::filesystem::const_iovec> buffer_vec) 00287 { 00288 saga::task t = write_vpriv(buffer_vec, saga::task_base::Sync()); 00289 t.get_result (); 00290 } 00291 SAGA_CALL_PUB_1_DEF_0(write_v, std::vector<saga::filesystem::const_iovec>) 00292 00293 00299 saga::ssize_t size_p(std::string pattern) 00300 { 00301 saga::task t = size_ppriv(pattern, saga::task_base::Sync()); 00302 return t.get_result<saga::ssize_t>(); 00303 } 00304 SAGA_CALL_PUB_1_DEF_0(size_p, std::string) 00305 00306 00314 saga::ssize_t read_p(std::string pattern, saga::mutable_buffer buffer) 00315 { 00316 saga::task t = read_ppriv(pattern, buffer, saga::task_base::Sync()); 00317 return t.get_result<saga::ssize_t>(); 00318 } 00319 SAGA_CALL_PUB_2_DEF_0(read_p, std::string, saga::mutable_buffer) 00320 00321 00329 saga::ssize_t write_p(std::string pattern, saga::const_buffer buffer) 00330 { 00331 saga::task t = write_ppriv(pattern, buffer, saga::task_base::Sync()); 00332 return t.get_result<saga::ssize_t>(); 00333 } 00334 SAGA_CALL_PUB_2_DEF_0(write_p, std::string, saga::const_buffer) 00335 00336 00344 std::vector<std::string> modes_e() 00345 { 00346 saga::task t = modes_epriv(saga::task_base::Sync()); 00347 return t.get_result<std::vector<std::string> >(); 00348 } 00349 SAGA_CALL_PUB_0_DEF_0(modes_e) 00350 00351 00356 saga::size_t size_e(std::string ext_mode, std::string specification) 00357 { 00358 saga::task t = size_epriv(ext_mode, specification, saga::task_base::Sync()); 00359 return t.get_result<saga::ssize_t>(); 00360 } 00361 SAGA_CALL_PUB_2_DEF_0(size_e, std::string, std::string) 00362 00363 00371 saga::ssize_t read_e(std::string ext_mode, std::string specification, 00372 saga::mutable_buffer buffer) 00373 { 00374 saga::task t = read_epriv(ext_mode, specification, buffer, 00375 saga::task_base::Sync()); 00376 return t.get_result<saga::ssize_t>(); 00377 } 00379 SAGA_CALL_PUB_3_DEF_0(read_e, std::string, std::string, 00380 saga::mutable_buffer) 00382 00392 saga::ssize_t write_e(std::string ext_mode, std::string specification, 00393 saga::const_buffer buffer) 00394 { 00395 saga::task t = write_epriv(ext_mode, specification, buffer, 00396 saga::task_base::Sync()); 00397 return t.get_result<saga::ssize_t>(); 00398 } 00400 SAGA_CALL_PUB_3_DEF_0(write_e, std::string, std::string, 00401 saga::const_buffer) 00403 00404 00405 }; // class file 00406 00407 } // namespace file 00408 } // namespace saga 00409 00410 #if defined(__WAVE__) && defined(SAGA_CREATE_PREPROCESSED_FILES) 00411 #pragma wave option(output: null) 00412 #endif 00413 #endif // !defined(SAGA_DEBUG) 00414 00415 // re-enable warnings about dependent classes not being exported from the dll 00416 #if defined(BOOST_MSVC) 00417 #pragma warning(pop) 00418 #endif 00419 00420 #endif // !defined(SAGA_PACKAGES_DATA_FILESYSTEM_FILE_HPP) 00421