File: sfstream.hpp

package info (click to toggle)
libsdsl 2.1.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,020 kB
  • sloc: cpp: 42,286; makefile: 1,171; ansic: 318; sh: 201; python: 27
file content (79 lines) | stat: -rw-r--r-- 2,264 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*!\file sfstream.hpp
   \brief sfstream.hpp contains a two stream class which can be used to read/write from/to files or strings.
   \author Simon Gog
*/
#ifndef INCLUDED_SDSL_SFSTREAM
#define INCLUDED_SDSL_SFSTREAM

#include <fstream>
#include <sstream>
#include <string>
#include "sdsl/ram_fs.hpp"
#include "sdsl/ram_filebuf.hpp"

namespace sdsl
{

class osfstream : public std::ostream
{
    public:
        typedef std::streambuf* buf_ptr_type;
    private:
        buf_ptr_type m_streambuf = nullptr;
        std::string  m_file      = "";
    public:
        typedef void* voidptr;
        //! Standard constructor.
        osfstream();
        //! Constructor taking a file name and open mode.
        osfstream(const std::string& file, std::ios_base::openmode mode = std::ios_base::out);
        //! Open the stream.
        buf_ptr_type
        open(const std::string& file, std::ios_base::openmode mode = std::ios_base::out);
        //! Is the stream close?
        bool is_open();
        //! Close the stream.
        void close();
        //! Standard destructor
        ~osfstream();
        //! Cast to void*
        operator  voidptr() const;

        osfstream& seekp(pos_type pos);
        osfstream& seekp(off_type off, ios_base::seekdir way);
        std::streampos tellp();
};


class isfstream : public std::istream
{
        typedef std::streambuf* buf_ptr_type;
    private:
        buf_ptr_type m_streambuf = nullptr;
        std::string  m_file      = "";
    public:
        typedef void* voidptr;
        //! Standard constructor.
        isfstream();
        //! Constructor taking a file name and open mode.
        isfstream(const std::string& file, std::ios_base::openmode mode = std::ios_base::in);
        //! Open the stream.
        buf_ptr_type
        open(const std::string& file, std::ios_base::openmode mode = std::ios_base::in);
        //! Is the stream close?
        bool is_open();
        //! Close the stream.
        void close();
        //! Standard destructor
        ~isfstream();
        //! Cast to void*
        operator  voidptr() const;

        isfstream& seekg(pos_type pos);
        isfstream& seekg(off_type off, ios_base::seekdir way);
        std::streampos tellg();
};

} // end namespace

#endif