File: ostream.hpp

package info (click to toggle)
aspell 0.60.8.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,336 kB
  • sloc: cpp: 24,378; sh: 12,340; perl: 1,924; ansic: 1,661; makefile: 852; sed: 16
file content (69 lines) | stat: -rw-r--r-- 1,573 bytes parent folder | download | duplicates (2)
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
// This file is part of The New Aspell
// Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license
// version 2.0 or 2.1.  You should have received a copy of the LGPL
// license along with this library if you did not you can find
// it at http://www.gnu.org/.

#ifndef ASPELL_OSTREAM__HPP
#define ASPELL_OSTREAM__HPP

#define _INTL_NO_DEFINE_MACRO_PRINTF

#include <stdarg.h>

#include "parm_string.hpp"

namespace acommon {

  // FIXME: Add Print Method compatible with printf and friends.
  //   Than avoid code bloat by using it in many places instead of
  //   out << "Bla " << something << " djdkdk " << something else << "\n"

  class OStream {
  public:
    virtual void write (char c) = 0;
    virtual void write (ParmStr) = 0;
    virtual void write (const void *, unsigned int) = 0;

    virtual int vprintf(const char *format, va_list ap) = 0;

#ifdef __GNUC__
    __attribute__ ((format (printf,2,3)))
#endif
      int printf(const char * format, ...)
    {
      va_list ap;
      va_start(ap, format);
      int res = vprintf(format, ap);
      va_end(ap);
      return res;
    }

    void put (char c) {write(c);}
    void put (ParmStr str) {write(str);}

    virtual void printl(ParmStr l) 
    {
      write(l);
      write('\n');
    }

    void write16(unsigned short v) {write(&v, 2);}
    void write32(unsigned int v) {write(&v, 4);}

    OStream & operator << (char c) {
      write(c);
      return *this;
    }

    OStream & operator << (ParmStr in) {
      write(in);
      return *this;
    }

    virtual ~OStream() {}
  };
  
}

#endif