1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1999, 2002, 2005, 2006, 2008, 2011 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #ifndef LIBAEGIS_OUTPUT_FILTER_INDENT_H
20 #define LIBAEGIS_OUTPUT_FILTER_INDENT_H
21 
22 #include <libaegis/output/filter.h>
23 
24 /**
25   * The output_filter_indent class is used to represent an output stream
26   * which automatically indents its C-like input.
27   */
28 class output_filter_indent:
29     public output_filter
30 {
31 public:
32     typedef aegis_shared_ptr<output_filter_indent> ipointer;
33 
34     /**
35       * The destructor.
36       */
37     virtual ~output_filter_indent();
38 
39     /**
40       * The create class method is used to create new dynamically
41       * allocated instances of this class.
42       *
43       * @param deeper
44       *     the deeper output stream on which this filter writes to.
45       */
46     static ipointer create(const output::pointer &deeper);
47 
48     /**
49       * The indent_more method is used to increase the indenting
50       * beyond the automatically calculated indent.
51       *
52       * @note
53       *     There must be a matching indent_less call.
54       */
55     void indent_more(void);
56 
57     /**
58       * The indent_less function is used to decrease the indenting
59       * to less than the automatically calculated indent.
60       *
61       * @note
62       *     There must be a matching indent_more call.
63       */
64     void indent_less(void);
65 
66 protected:
67     // See base class for documentation.
68     nstring type_name(void) const;
69 
70     // See base class for documentation.
71     long ftell_inner(void) const;
72 
73     // See base class for documentation.
74     void write_inner(const void *data, size_t length);
75 
76     // See base class for documentation.
77     void end_of_line_inner(void);
78 
79 private:
80     /**
81       * The constructor.  It is private on purpose, use the "create"
82       * class method instead.
83       *
84       * @param deeper
85       *     the deeper output stream on which this filter writes to.
86       */
87     output_filter_indent(const output::pointer &deeper);
88 
89     enum {
90         /**
91           * This defines the width of a tab on output.
92           */
93         INDENT = 8
94     };
95 
96     /**
97       * The depth instance variable is used to remember the current
98       * level of indenting.  Will never be negative.
99       */
100     int depth;
101 
102     /**
103       * The in_col instance variable is used to remember the current
104       * input column.  This can differe from the output column when
105       * white space is being optimized.
106       */
107     int in_col;
108 
109     /**
110       * The out_col instance variable is used to remember the current
111       * output column.
112       */
113     int out_col;
114 
115     /**
116       * The continuation_line instance variable is used to remember
117       * whether or not the current line is a continuation line.
118       *
119       * State 0 means that it is not, state 1 means that a backslash (\)
120       * has been seen, and state 2 means that "\\\n" has been seen.
121       */
122     int continuation_line;
123 
124     /**
125       * The pos instance variable is used to remember the current output
126       * position.
127       */
128     long pos;
129 
130     /**
131       * The default constructor.  Do not use.
132       */
133     output_filter_indent();
134 
135     /**
136       * The copy constructor.  Do not use.
137       */
138     output_filter_indent(const output_filter_indent &);
139 
140     /**
141       * The assignment operator.  Do not use.
142       */
143     output_filter_indent &operator=(const output_filter_indent &);
144 };
145 
146 #endif // LIBAEGIS_OUTPUT_FILTER_INDENT_H
147