| 46 | // ============================================================================ |
| 47 | |
| 48 | class ifstream { |
| 49 | private: |
| 50 | filebuf_ptr mHandle; |
| 51 | fl::size_t mLastRead; |
| 52 | bool mGood; |
| 53 | bool mEof; |
| 54 | bool mFail; |
| 55 | |
| 56 | void updateState() { |
| 57 | if (mHandle && mHandle->is_open()) { |
| 58 | mEof = mHandle->is_eof(); |
| 59 | mFail = mHandle->has_error(); |
| 60 | mGood = !mEof && !mFail; |
| 61 | } else { |
| 62 | mGood = false; |
| 63 | mEof = false; |
| 64 | mFail = true; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public: |
| 69 | ifstream() FL_NOEXCEPT : mLastRead(0), mGood(false), mEof(false), mFail(true) {} |
| 70 | |
| 71 | explicit ifstream(const char* path, ios::openmode mode = ios::in); |
| 72 | |
| 73 | explicit ifstream(filebuf_ptr handle); |
| 74 | |
| 75 | ~ifstream() FL_NOEXCEPT; |
| 76 | |
| 77 | // Non-copyable |
| 78 | ifstream(const ifstream&) FL_NOEXCEPT = delete; |
| 79 | ifstream& operator=(const ifstream&) = delete; |
| 80 | |
| 81 | // Moveable |
| 82 | ifstream(ifstream&& other) FL_NOEXCEPT |
| 83 | : mHandle(other.mHandle), mLastRead(other.mLastRead), |
| 84 | mGood(other.mGood), mEof(other.mEof), mFail(other.mFail) { |
| 85 | other.mHandle.reset(); |
| 86 | other.mLastRead = 0; |
| 87 | other.mGood = false; |
| 88 | other.mEof = false; |
| 89 | other.mFail = true; |
| 90 | } |
| 91 | |
| 92 | ifstream& operator=(ifstream&& other) FL_NOEXCEPT { |
| 93 | if (this != &other) { |
| 94 | close(); |
| 95 | mHandle = other.mHandle; |
| 96 | mLastRead = other.mLastRead; |
| 97 | mGood = other.mGood; |
| 98 | mEof = other.mEof; |
| 99 | mFail = other.mFail; |
| 100 | other.mHandle.reset(); |
| 101 | other.mLastRead = 0; |
| 102 | other.mGood = false; |
| 103 | other.mEof = false; |
| 104 | other.mFail = true; |
| 105 | } |