File: string-format.hh

package info (click to toggle)
pdf2djvu 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,388 kB
  • ctags: 771
  • sloc: cpp: 5,869; sh: 4,283; xml: 780; makefile: 160; python: 24
file content (59 lines) | stat: -rw-r--r-- 1,261 bytes parent folder | download | duplicates (4)
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
/* Copyright © 2009 Jakub Wilk
 *
 * This package is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 dated June, 1991.
 */

#include <map>

namespace string_format
{
  typedef unsigned long uint_tp;

  class Bindings : public std::map<std::string, uint_tp>
  {
  public:
    uint_tp get(const std::string &value) const
    {
      const_iterator it = this->find(value);
      if (it == this->end())
        return 0;
      return it->second;
    }
  };

  class Chunk
  {
  public:
    virtual void format(const Bindings &bindings, std::ostream &stream) const
    = 0;
    virtual ~Chunk() throw ()
    { }
  };

  class Template
  {
  private:
    Template(const Template &); // not defined
    Template & operator=(const Template &); // not defined
  protected:
    std::vector<Chunk*> chunks;
  public:
    explicit Template(const std::string &);
    ~Template() throw ();
    void format(const Bindings &, std::ostream &) const;
    std::string format(const Bindings &) const;
  };

  class ParseError : public std::runtime_error
  {
  public:
    explicit ParseError()
    : std::runtime_error("")
    { }
  };

}

// vim:ts=2 sw=2 et