]> git.donarmstrong.com Git - lilypond.git/blob - lib/include/file-storage.hh
release: 0.1.11
[lilypond.git] / lib / include / file-storage.hh
1 /*
2   file-storage.hh -- declare File_storage, Mapped_file_storage, Simple_file_storage
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #ifndef FILE_STORAGE_HH
11 #define FILE_STORAGE_HH
12
13 #include "proto.hh"
14
15 /**
16   store a file in-memory.
17  */
18 class File_storage
19 {
20 public:
21     virtual char const* ch_C() const=0;
22     virtual int length_i() const=0;
23     virtual ~File_storage(){}
24 };
25
26 /**
27   Use mmap to "copy"  a file into memory
28  */
29 class Mapped_file_storage:public File_storage
30 {
31 public:
32     Mapped_file_storage(String);    
33 protected:
34     virtual char const* ch_C() const;
35     virtual int length_i() const;
36     virtual ~Mapped_file_storage();
37 private:
38     void open(String name);
39     void close();
40
41     void map();
42     void unmap();
43     int fildes_i_;
44     off_t size_off_;
45     caddr_t data_caddr_;
46 };
47
48 /**
49   read file char by char and copy into a malloc array.
50  */
51 class Simple_file_storage  : public File_storage
52 {
53     char * data_p_;
54     int len_i_;
55 protected:    
56     virtual char const*ch_C() const;
57     virtual int length_i() const;
58     virtual ~Simple_file_storage();
59 public:
60     Simple_file_storage(String);
61 };
62 #endif // FILE_STORAGE_HH