source: XMLIO_V2/external/include/Poco/Util/HelpFormatter.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1//
2// HelpFormatter.h
3//
4// $Id: //poco/1.3/Util/include/Poco/Util/HelpFormatter.h#2 $
5//
6// Library: Util
7// Package: Options
8// Module:  HelpFormatter
9//
10// Definition of the HelpFormatter class.
11//
12// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Util_HelpFormatter_INCLUDED
40#define Util_HelpFormatter_INCLUDED
41
42
43#include "Poco/Util/Util.h"
44#include <ostream>
45
46
47namespace Poco {
48namespace Util {
49
50
51class OptionSet;
52class Option;
53
54
55class Util_API HelpFormatter
56        /// This class formats a help message from an OptionSet.
57{
58public:
59        HelpFormatter(const OptionSet& options);
60                /// Creates the HelpFormatter, using the given
61                /// options.
62                ///
63                /// The HelpFormatter just stores a reference
64                /// to the given OptionSet, so the OptionSet must not
65                /// be destroyed during the lifetime of the HelpFormatter.
66
67        ~HelpFormatter();
68                /// Destroys the HelpFormatter.
69
70        void setCommand(const std::string& command);
71                /// Sets the command name.
72               
73        const std::string& getCommand() const;
74                /// Returns the command name.
75               
76        void setUsage(const std::string& usage);
77                /// Sets the usage string.
78               
79        const std::string& getUsage() const;
80                /// Returns the usage string.
81               
82        void setHeader(const std::string& header);
83                /// Sets the header string.
84               
85        const std::string& getHeader() const;
86                /// Returns the header string.
87               
88        void setFooter(const std::string& footer);
89                /// Sets the footer string.
90               
91        const std::string& getFooter() const;
92                /// Returns the footer string.
93
94        void format(std::ostream& ostr) const;
95                /// Writes the formatted help text to the given stream.
96       
97        void setWidth(int width);
98                /// Sets the line width for the formatted help text.
99               
100        int getWidth() const;
101                /// Returns the line width for the formatted help text.
102                ///
103                /// The default width is 72.
104
105        void setIndent(int indent);
106                /// Sets the indentation for description continuation lines.
107
108        int getIndent() const;
109                /// Returns the indentation for description continuation lines.
110               
111        void setAutoIndent();
112                /// Sets the indentation for description continuation lines so that
113                /// the description text is left-aligned.
114
115        void setUnixStyle(bool flag);
116                /// Enables Unix-style options. Both short and long option names
117                /// are printed if Unix-style is set. Otherwise, only long option
118                /// names are printed.
119                ///
120                /// After calling setUnixStyle(), setAutoIndent() should be called
121                /// as well to ensure proper help text formatting.
122               
123        bool isUnixStyle() const;
124                /// Returns if Unix-style options are set.
125
126        std::string shortPrefix() const;
127                /// Returns the platform-specific prefix for short options.
128                /// "-" on Unix, "/" on Windows and OpenVMS.
129       
130        std::string longPrefix() const;
131                /// Returns the platform-specific prefix for long options.
132                /// "--" on Unix, "/" on Windows and OpenVMS.
133
134protected:
135        int calcIndent() const;
136                /// Calculates the indentation for the option descriptions
137                /// from the given options.
138
139        void formatOptions(std::ostream& ostr) const;
140                /// Formats all options.
141
142        void formatOption(std::ostream& ostr, const Option& option, int width) const;
143                /// Formats an option, using the platform-specific
144                /// prefixes.
145
146        void formatText(std::ostream& ostr, const std::string& text, int indent) const;
147                /// Formats the given text.
148
149        void formatText(std::ostream& ostr, const std::string& text, int indent, int firstIndent) const;
150                /// Formats the given text.
151
152        void formatWord(std::ostream& ostr, int& pos, const std::string& word, int indent) const;
153                /// Formats the given word.
154       
155        void clearWord(std::ostream& ostr, int& pos, std::string& word, int indent) const;
156                /// Formats and then clears the given word.
157       
158private:
159        HelpFormatter(const HelpFormatter&);
160        HelpFormatter& operator = (const HelpFormatter&);
161
162        const OptionSet& _options;
163        int _width;
164        int _indent;
165        std::string _command;
166        std::string _usage;
167        std::string _header;
168        std::string _footer;
169        bool _unixStyle;
170       
171        static const int TAB_WIDTH;
172        static const int LINE_WIDTH;
173};
174
175
176//
177// inlines
178//
179inline int HelpFormatter::getWidth() const
180{
181        return _width;
182}
183
184
185inline int HelpFormatter::getIndent() const
186{
187        return _indent;
188}
189
190
191inline const std::string& HelpFormatter::getCommand() const
192{
193        return _command;
194}
195
196
197inline const std::string& HelpFormatter::getUsage() const
198{
199        return _usage;
200}
201
202
203inline const std::string& HelpFormatter::getHeader() const
204{
205        return _header;
206}
207
208
209inline const std::string& HelpFormatter::getFooter() const
210{
211        return _footer;
212}
213
214
215inline bool HelpFormatter::isUnixStyle() const
216{
217        return _unixStyle;
218}
219
220
221} } // namespace Poco::Util
222
223
224#endif // Util_HelpFormatter_INCLUDED
Note: See TracBrowser for help on using the repository browser.