]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/source-file.hh
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / include / source-file.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef SOURCE_FILE_HH
21 #define SOURCE_FILE_HH
22
23 #include "std-vector.hh"
24 #include "lily-proto.hh"
25 #include "smobs.hh"
26
27 #include <iostream>
28
29 /**
30    class for reading and mapping a file.
31
32    duplicates a lot of Data_file and Text_stream.
33    should look at including Data_file's functionality:
34    get_line (), get_word () here.
35 */
36
37 class Source_file : public Smob<Source_file>
38 {
39 public:
40   int print_smob (SCM, scm_print_state *) const;
41   SCM mark_smob () const;
42   static const char type_p_name_[];
43   virtual ~Source_file ();
44 private:
45   std::vector<char const *> newline_locations_;
46   std::istream *istream_;
47   std::vector<char> characters_;
48   SCM str_port_;
49
50   void load_stdin ();
51   void init_port ();
52   void init ();
53
54 public:
55   Source_file (const std::string &fn);
56   Source_file (const std::string&, const std::string&);
57
58   char const *c_str () const;
59   virtual std::string quote_input (char const *pos_str0) const;
60   std::istream *get_istream ();
61   bool contains (char const *pos_str0) const;
62   int length () const;
63   virtual int get_line (char const *pos_str0) const;
64   void set_line (char const *pos_str0, int i);
65   std::string name_string () const;
66   std::string file_line_column_string (char const *str0) const;
67
68   Slice line_slice (char const *pos_str0) const;
69   std::string line_string (char const *pos_str0) const;
70   void get_counts (char const *pos_str0, int *, int *, int *, int *) const;
71
72   SCM get_port () const;
73   std::string name_;
74
75 protected:
76   int line_offset_;
77 };
78
79 std::vector<char> gulp_file (const std::string &fn, int desired);
80
81 #endif /* SOURCE_FILE_HH */