Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
eea45fccd20bb3624431de92385aec398ee10360
[simgrid.git] / src / surf / FileImpl.hpp
1 /* Copyright (c) 2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SRC_SURF_FILEIMPL_HPP_
8 #define SRC_SURF_FILEIMPL_HPP_
9
10 #include "surf/surf.h"
11 #include <string>
12
13 namespace simgrid {
14 namespace surf {
15
16 class FileImpl {
17 public:
18   FileImpl(const char* path, const char* mount, sg_size_t size) : path_(path), mount_point_(mount), size_(size) {}
19   ~FileImpl() = default;
20
21   std::string name() { return path_; }
22   const char* cname() { return path_.c_str(); }
23   const char* mount() { return mount_point_.c_str(); }
24   sg_size_t size() { return size_; }
25   void setSize(sg_size_t size) { size_ = size; }
26   void setPosition(sg_size_t size) { current_position_ = size; }
27   void incrPosition(sg_size_t incr) { current_position_ += incr; }
28   sg_size_t tell() { return current_position_; }
29   int seek(sg_offset_t offset, int origin)
30   {
31     switch (origin) {
32       case SEEK_SET:
33         current_position_ = offset;
34         return 0;
35       case SEEK_CUR:
36         current_position_ += offset;
37         return 0;
38       case SEEK_END:
39         current_position_ = size_ + offset;
40         return 0;
41       default:
42         return -1;
43     }
44   }
45
46 private:
47   std::string path_;
48   std::string mount_point_;
49   sg_size_t size_;
50   sg_size_t current_position_ = SEEK_SET;
51 };
52 }
53 }
54 #endif /* SRC_SURF_FILEIMPL_HPP_ */