ROSE  0.9.9.109
MarkupPod.h
1 // WARNING: Changes to this file must be contributed back to Sawyer or else they will
2 // be clobbered by the next update from Sawyer. The Sawyer repository is at
3 // https://github.com/matzke1/sawyer.
4 
5 
6 
7 
8 #ifndef Sawyer_Markup_MarkupPod_H
9 #define Sawyer_Markup_MarkupPod_H
10 
11 #include <Sawyer/Markup.h>
12 #include <Sawyer/Sawyer.h>
13 #include <string>
14 #include <vector>
15 
16 namespace Sawyer {
17 namespace Markup {
18 
19 class SAWYER_EXPORT PodFormatter: public Formatter {
20 #include <Sawyer/WarningsOff.h>
21  std::string pageName_; // command name, usually upper case. E.g., "LS"
22  std::string chapterNumber_; // usually a number. E.g., "1" for commands
23  std::string chapterName_; // E.g., "User Commands"
24  std::string dateString_; // E.g., "April 2010"
25  std::string versionString_; // E.g., "GNU coreutils 8.5"
26  std::vector<Tag::Ptr> tagStack_; // tags currently processed
27  bool atBeginningOfLine_; // true when output cursor is at the beginning of a line
28 #include <Sawyer/WarningsRestore.h>
29 protected:
30  PodFormatter(): pageName_("Command"), chapterNumber_("1"), chapterName_("User Commands"), atBeginningOfLine_(true) {}
31 
32 public:
34 
35  static Ptr instance() { return Ptr(new PodFormatter); }
36 
37  Ptr title(const std::string &pageName, const std::string &chapterNumber="1",
38  const std::string &chapterName="User Commands");
39  Ptr version(const std::string &versionString, const std::string &dateString="");
40 
41  Ptr pageName(const std::string &s) { pageName_=s; return self(); }
42  const std::string& pageName() const { return pageName_; }
43  Ptr chapterNumber(const std::string &s) { chapterNumber_=s; return self(); }
44  Ptr chapterNumber(int i);
45  const std::string& chapterNumber() const { return chapterNumber_; }
46  Ptr chapterName(const std::string &s) { chapterName_=s; return self(); }
47  const std::string& chapterName() const { return chapterName_; }
48  Ptr dateString(const std::string &s) { dateString_=s; return self(); }
49  const std::string& dateString() const { return dateString_; }
50  Ptr versionString(const std::string &s) { versionString_=s; return self(); }
51  const std::string& versionString() const { return versionString_; }
52 
53  std::string toNroff(const ParserResult&);
54  void emit(const ParserResult&);
55 
56 protected:
57  Ptr self() { return sharedFromThis().dynamicCast<PodFormatter>(); }
58  size_t nested() const;
59  void checkArgs(const Tag::Ptr &tag, size_t nArgs, const TagArgs &args) const;
60  std::string escape(const std::string&) const;
61 
62 public: // used internally
63  virtual void beginDocument(std::ostream&) /*override*/;
64  virtual void endDocument(std::ostream&) /*override*/;
65  virtual bool beginTag(std::ostream&, const Tag::Ptr&, const TagArgs&) /*override*/;
66  virtual void endTag(std::ostream&, const Tag::Ptr&, const TagArgs&) /*override*/;
67  virtual void text(std::ostream&, const std::string &text) /*override*/;
68 };
69 
70 
71 } // namespace
72 } // namespace
73 
74 #endif
Reference-counting smart pointer.
Definition: SharedPointer.h:34
Name space for the entire library.
Definition: Access.h:11