~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Base/Stream.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2007 Werner Mayer <werner.wm.mayer@gmx.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  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 Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#ifndef BASE_STREAM_H
 
25
#define BASE_STREAM_H
 
26
 
 
27
 
 
28
#include <fstream>
 
29
#include <ios>
 
30
#include <iostream>
 
31
#include <sstream>
 
32
#include <string>
 
33
#include <vector>
 
34
 
 
35
namespace Base {
 
36
 
 
37
class BaseExport Stream
 
38
{
 
39
public:
 
40
    enum ByteOrder { BigEndian, LittleEndian };
 
41
    
 
42
    ByteOrder byteOrder() const;
 
43
    void setByteOrder(ByteOrder);
 
44
 
 
45
protected:
 
46
    Stream();
 
47
    virtual ~Stream(); 
 
48
 
 
49
    bool _swap;
 
50
};
 
51
 
 
52
/**
 
53
 * The OutputStream class provides writing of binary data to an ostream.
 
54
 * @author Werner Mayer
 
55
 */
 
56
class BaseExport OutputStream : public Stream
 
57
{
 
58
public:
 
59
    OutputStream(std::ostream &rout);
 
60
    ~OutputStream();
 
61
 
 
62
    OutputStream& operator << (bool b);
 
63
    OutputStream& operator << (int8_t ch);
 
64
    OutputStream& operator << (uint8_t uch);
 
65
    OutputStream& operator << (int16_t s);
 
66
    OutputStream& operator << (uint16_t us);
 
67
    OutputStream& operator << (int32_t i);
 
68
    OutputStream& operator << (uint32_t ui);
 
69
    OutputStream& operator << (int64_t l);
 
70
    OutputStream& operator << (uint64_t ul);
 
71
    OutputStream& operator << (float f);
 
72
    OutputStream& operator << (double d);
 
73
 
 
74
private:
 
75
    OutputStream (const OutputStream&);
 
76
    void operator = (const OutputStream&);
 
77
 
 
78
private:
 
79
    std::ostream& _out;
 
80
};
 
81
 
 
82
/**
 
83
 * The InputStream class provides reading of binary data from an istream.
 
84
 * @author Werner Mayer
 
85
 */
 
86
class BaseExport InputStream : public Stream
 
87
{
 
88
public:
 
89
    InputStream(std::istream &rin);
 
90
    ~InputStream();
 
91
 
 
92
    InputStream& operator >> (bool& b);
 
93
    InputStream& operator >> (int8_t& ch);
 
94
    InputStream& operator >> (uint8_t& uch);
 
95
    InputStream& operator >> (int16_t& s);
 
96
    InputStream& operator >> (uint16_t& us);
 
97
    InputStream& operator >> (int32_t& i);
 
98
    InputStream& operator >> (uint32_t& ui);
 
99
    InputStream& operator >> (int64_t& l);
 
100
    InputStream& operator >> (uint64_t& ul);
 
101
    InputStream& operator >> (float& f);
 
102
    InputStream& operator >> (double& d);
 
103
 
 
104
        operator bool() const
 
105
        {       // test if _Ipfx succeeded
 
106
                        return !_in.eof();
 
107
        }
 
108
 
 
109
private:
 
110
    InputStream (const InputStream&);
 
111
    void operator = (const InputStream&);
 
112
 
 
113
private:
 
114
    std::istream& _in;
 
115
};
 
116
 
 
117
// ----------------------------------------------------------------------------
 
118
 
 
119
class FileInfo;
 
120
 
 
121
/**
 
122
 * The ofstream class is provided for convenience. On Windows
 
123
 * platforms it opens a stream with UCS-2 encoded file name
 
124
 * while on Linux platforms the file name is UTF-8 encoded.
 
125
 * @author Werner Mayer
 
126
 */
 
127
class BaseExport ofstream : public std::ofstream
 
128
{
 
129
public:
 
130
    ofstream(const FileInfo& fi, ios_base::openmode mode =
 
131
                                 std::ios::out | std::ios::trunc);
 
132
    virtual ~ofstream();
 
133
};
 
134
 
 
135
/**
 
136
 * The ofstream class is provided for convenience. On Windows
 
137
 * platforms it opens a stream with UCS-2 encoded file name
 
138
 * while on Linux platforms the file name is UTF-8 encoded.
 
139
 * @author Werner Mayer
 
140
 */
 
141
class BaseExport ifstream : public std::ifstream
 
142
{
 
143
public:
 
144
    ifstream(const FileInfo& fi, ios_base::openmode mode = 
 
145
                                 std::ios::in);
 
146
    virtual ~ifstream();
 
147
};
 
148
 
 
149
} // namespace Base
 
150
 
 
151
#endif // BASE_STREAM_H