File: ofoldbuf.yo

package info (click to toggle)
bobcat 6.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,960 kB
  • sloc: cpp: 18,954; fortran: 5,617; makefile: 2,787; sh: 659; perl: 401; ansic: 26
file content (212 lines) | stat: -rw-r--r-- 8,471 bytes parent folder | download | duplicates (3)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
includefile(include/header)

COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::OFoldBuf)(3bobcat)(_CurYrs_)
    (libbobcat-dev__CurVers_)(Fold long lines)

manpagename(FBB::OFoldBuf)(Folds long lines written to ostream)

manpagesynopsis()
    bf(#include <bobcat/ofoldbuf>)nl()
    Linking option: tt(-lbobcat)

manpagedescription()
    bf(FBB::OFoldBuf) is a specialization of tt(FBB::OFilterBuf)
folding long lines written to an tt(std::ostream) object. The
tt(OFoldBuf) writes the (folded) lines to a second tt(ostream) (the
em(destination stream) which is either used by or opened by the
tt(OFoldBuf) object).

    Internally the tt(OFoldBuf) defines its actions using a little
finite state automation distinguishing three states (INDENT, WS and NON_WS)
and three character categories (tt(\n), other white space characters (space),
and non-space characters). The nine combinations resulting from these two sets
are discussed below.

    tt(OFoldBuf) objects will never fold lines in the middle of series
of non-blank characters (called a `word' below) but will always break a line
at a white space character. The resulting lines will always appear to the
right of a configurable left margin and to the left of a configurable right
margin. There is a somewhat pathological exception to this: if a word is too
long to fit in between the margins then the word will exceed the right hand
margin.

    The indentation used for the left margins is configurable to either blanks
(the default) or tabs. When tabs are used the width of a tab character is
configurable, using a default of 8 positions in the destination stream.

    What follows is a description of the em(Finite State Automaton) (FSA)
defining what happens when various character types appear at its three
states. The phrase `... is written' means that the described information is
written to the tt(ostream) used or opened by the tt(OFoldBuf)
object. tt(OFoldBuf)'s initial state is tt(INDENT):

DEFINEMACRO(rw)(3)(row(cell(ARG1)cell(ARG2)cell(ARG3)))

table(3)(lll)(
rw(State)(char.)(description)
rowline()
rw(INDENT)  (\n)      (a new line character is written)
rw()        (space)   (the indentation is set;)
                rw()()(the space character is added to the indentation;)
                rw()()(next state: WS)
rw()        (non-ws)  (the character is added to the currently stored word;)
                rw()()(next state: NON_WS)
rowline()
rw(WS)      (\n)      (a new line character is written;)
                rw()()(stored white-space is erased;)
                rw()()(next state: INDENT)
rw()        (space)   (white space character is added to the currently)
                rw()()(stored space characters;)
rw()        (non-ws)  (the character is added to the currently stored word;)
                rw()()(next state: NON_WS)
rowline()
rw(NON_WS)  (\n)      (stored white space and word are written;)
                rw()()(a new line is written;)
                rw()()(next state: INDENT)
rw()        (space)   (stored white space and word are written;)
                rw()()(white space character is added to the currently)
                rw()()(stored space characters;)
                rw()()(next state: WS)
rw()        (non-ws)  (the character is added to the currently stored word;)
rowline()
)

includefile(include/namespace)

manpagesection(INHERITS FROM)
    tt(FBB::OFilterBuf)

manpagesection(ENUMERATION)
    The enumeration tt(TabsOrBlanks) is used to select tabs or blanks when
writing the indentation. The default is blanks. When tabs are selected the
display width of tabs characters can be configured as well (using the default
of 8 positions for each tab-character). The enumeration has two values:
    itemization(
    itb(BLANKS)
        The default, indicating that the left margin is specified and written
as a number of blanks;
    itb(TABS)
        Indicating that the left margin is specified and written as a number
of tab-characters.
    )

    The enumeration tt(TrailingBlanks) is used to configure the
tt(OFoldBuf) object with respect to any trailing blanks that may appear
on the final line. These trailing blanks can appear on the final line it it is
not properly terminated with a newline character but instead ends in white
space. By default these white space characters are ignored, but they may be
kept as well. The enumeration has two values:
    itemization(
    itb(IGNORE_TRAILING_BLANKS)
        This indicates that trailing blanks appearing at the final line if it
is not terminated by a newline should not be written to the destination
tt(std::ostream). This is the default used by tt(OFoldBuf) objects.
    itb(KEEP_TRAILING_BLANKS)
        This indicates that trailing blanks at the final line if it is not
terminated by a newline should be written to the destination tt(std::ostream)
    )

manpagesection(CONSTRUCTORS)
    itemization(
    itb(OFoldBuf(size_t leftIndent = 0, size_t rightMargin = 80,
                    TabsOrBlanks tob = BLANKS,
                    TrailingBlanks tb = IGNORE_TRAILING_BLANKS))
        This constructor initializes an tt(OFoldBuf) object but does not
associate it with a destination stream. It can also be used as the default
constructor.

    itb(OFoldBuf(char const *fname,
                   size_t leftIndent = 0, size_t rightMargin = 80,
                    TabsOrBlanks tob = BLANKS,
                   TrailingBlanks tb = IGNORE_TRAILING_BLANKS))
    This constructor initializes an tt(OFoldBuf) object and opens (using
tt(std::ios::out)) the destination stream using the name specified as its
tt(fname) argument.

    itb(OFoldBuf(std::ostream &stream,
                   size_t leftIndent = 0, size_t rightMargin = 80,
                    TabsOrBlanks tob = BLANKS,
                   TrailingBlanks tb = IGNORE_TRAILING_BLANKS))
    This constructor initializes an tt(OFoldBuf) object and uses as its
destination stream the tt(std::ostream stream).
    )

    The destructor writes any buffered information to the destination stream
and will then flush the destination stream.

    Copy and move constructors (and assignment operators) are not available.

manpagesection(MEMBER FUNCTIONS)
     All members of bf(FBB::OFilterBuf), in particular its tt(out()) and
tt(reset) members are available, as bf(FBB::OFoldBuf) inherits from
this class.
    itemization(
    itb(void setMargins(size_t leftMargin, size_t rightMargin))
        This member can be used to modify the left- and right folding
margins. Note that the left margin may also be modified using the tt(FBB::lm)
and tt(FBB::mlm) manipulators.

    itb(void setTrailingBlanks(TrailingBlanks tb))
        This member can be used to modify the currently used
tt(TrailingBlanks) parameter.

    itb(void useBlanks())
        This member can be used to select blanks  to be used when inserting
left margins.

    itb(void useTabs(size_t tabWidth = 8))
        This member can be used to select tab-characters to be used when
inserting left margins. The second parameter is used to specify the display
width of a tab-character.
    )

manpagesection(STATIC MEMBER FUNCTIONS)

    itemization(
    itb(size_t leftMargin(std::ostreambuf const *buffer))
        This member returns the current left margin setting of the
tt(OFoldBuf) object passed to it as its argument. The member defines a
tt(std::streambuf) parameter which is down cast to an tt(OFoldBuf) and
an tt(FBB::Exception) exception is thrown if that cast fails.
    itb(size_t rightMargin(std::ostreambuf const *buffer))
        This member returns the current right margin setting of the
tt(OFoldBuf) object passed to it as its argument. The member's parameter
is down cast in the same way as tt(leftMargin())'s argument: an
tt(FBB::Exception) exception is thrown if that cast fails.
    )

manpagesection(EXAMPLE)
        verb(
    #include <iostream>
    #include <ostream>
    #include <string>
    #include <bobcat/ofoldbuf>

    using namespace std;
    using namespace FBB;

    int main()
    {
        OFoldBuf fb(cout, 4, 40);
        ostream out(&fb);

        out << lm(4);

        string line;
        while (getline(cin, line))
            out << line << '\n';
    }
        )

manpagefiles()
    em(bobcat/ofoldbuf) - defines the class interface

manpageseealso()
    bf(bobcat)(7),  bf(lm)(3bobcat), bf(mlm)(3bobcat),
    bf(ofilterbuf)(3bobcat), bf(ofoldstream)(3bobcat)

manpagebugs()
    None Reported.

includefile(include/trailer)