~ubuntu-branches/ubuntu/gutsy/grhino/gutsy

« back to all changes in this revision

Viewing changes to gtstream.h

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2007-04-02 20:38:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070402203809-fxyqqtkhj9ou03dy
Tags: upstream-0.16.0
ImportĀ upstreamĀ versionĀ 0.16.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        gtstream.h      C++ Stream Supporting gettext Usage
 
3
        Copyright (c) 2000, 2001, 2002, 2004, 2005 Kriang Lerdsuwanakij
 
4
        email:          lerdsuwa@users.sourceforge.net
 
5
 
 
6
        This program is free software; you can redistribute it and/or modify
 
7
        it under the terms of the GNU General Public License as published by
 
8
        the Free Software Foundation; either version 2 of the License, or
 
9
        (at your option) any later version.
 
10
 
 
11
        This program is distributed in the hope that it will be useful,
 
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
        GNU General Public License for more details.
 
15
 
 
16
        You should have received a copy of the GNU General Public License
 
17
        along with this program; if not, write to the Free Software
 
18
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
*/
 
20
 
 
21
#ifndef __K_GTSTREAM_H
 
22
#define __K_GTSTREAM_H
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include <string>
 
27
#include <vector>
 
28
#include <iostream>
 
29
#include <sstream>
 
30
 
 
31
typedef std::ostringstream gtstream;
 
32
 
 
33
class gtout {
 
34
                gtout(const gtout &);
 
35
        private:
 
36
                std::vector<std::string>        str_vec;
 
37
                std::vector<bool>               str_flag;
 
38
                std::ostream                    &os;
 
39
                std::string                     format;
 
40
                bool                            need_flush;
 
41
 
 
42
                void finish();
 
43
        public:
 
44
                gtout(std::ostream &os_, const std::string &fmt);
 
45
                gtout(std::ostream &os_, const char *fmt);
 
46
 
 
47
                ~gtout() { finish(); }
 
48
 
 
49
                int opfx() { return 1; }
 
50
                void osfx() {}
 
51
 
 
52
                gtout& flush() { need_flush = true; return *this; }
 
53
 
 
54
                gtout& put(char c) { return *this << c; }
 
55
                gtout& write(const char *s, std::streamsize n) { return *this << std::string(s, n); }
 
56
 
 
57
                template <class T> gtout& operator<<(T t);
 
58
 
 
59
                gtout& operator<<(gtout& (*f)(gtout&)) {
 
60
                        return (*f)(*this);
 
61
                }
 
62
                gtout& operator<<(std::ios& (*f)(std::ios&)) {
 
63
                        (*f)(os); return *this;
 
64
                }
 
65
};
 
66
 
 
67
template <class T> gtout& gtout::operator<<(T t)
 
68
{
 
69
        gtstream        buffer;
 
70
 
 
71
                                        // Do not copy locale for speed reason
 
72
//      buffer.copyfmt(*this);          // Transfer states to buffer
 
73
//      buffer.clear(rdstate());
 
74
        buffer << t;
 
75
 
 
76
//      copyfmt(buffer);                // Transfer states from buffer
 
77
//      clear(buffer.rdstate());
 
78
 
 
79
        str_vec.push_back(buffer.str());
 
80
        str_flag.push_back(false);
 
81
 
 
82
        return *this;
 
83
}
 
84
 
 
85
#endif  /* __K_GTSTREAM_H */