1 |
786 |
skrzyp |
// This file is part of the uSTL library, an STL implementation.
|
2 |
|
|
//
|
3 |
|
|
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
|
4 |
|
|
// This file is free software, distributed under the MIT License.
|
5 |
|
|
|
6 |
|
|
#ifndef UIOSFUNC_H_730C16E316F7650E3A02E1C6611B789A
|
7 |
|
|
#define UIOSFUNC_H_730C16E316F7650E3A02E1C6611B789A
|
8 |
|
|
|
9 |
|
|
#include "sostream.h"
|
10 |
|
|
|
11 |
|
|
namespace ustl {
|
12 |
|
|
|
13 |
|
|
class ios : public ios_base {
|
14 |
|
|
public:
|
15 |
|
|
/// \class align uiosfunc.h ustl.h
|
16 |
|
|
/// \ingroup StreamFunctors
|
17 |
|
|
/// \brief Stream functor to allow inline align() calls.
|
18 |
|
|
///
|
19 |
|
|
/// Example: os << ios::align(sizeof(uint16_t));
|
20 |
|
|
///
|
21 |
|
|
class align {
|
22 |
|
|
public:
|
23 |
|
|
inline explicit align (size_t grain = c_DefaultAlignment) : m_Grain(grain) {}
|
24 |
|
|
inline istream& apply (istream& is) const { is.align (m_Grain); return (is); }
|
25 |
|
|
inline ostream& apply (ostream& os) const { os.align (m_Grain); return (os); }
|
26 |
|
|
inline void read (istream& is) const { apply (is); }
|
27 |
|
|
inline void write (ostream& os) const { apply (os); }
|
28 |
|
|
inline size_t stream_size (void) const { return (m_Grain - 1); }
|
29 |
|
|
private:
|
30 |
|
|
const size_t m_Grain;
|
31 |
|
|
};
|
32 |
|
|
|
33 |
|
|
/// \class talign uiosfunc.h ustl.h
|
34 |
|
|
/// \ingroup StreamFunctors
|
35 |
|
|
/// \brief Stream functor to allow type-based alignment.
|
36 |
|
|
template <typename T>
|
37 |
|
|
class talign : public align {
|
38 |
|
|
public:
|
39 |
|
|
inline explicit talign (void) : align (alignof (NullValue<T>())) {}
|
40 |
|
|
};
|
41 |
|
|
|
42 |
|
|
/// \class skip uiosfunc.h ustl.h
|
43 |
|
|
/// \ingroup StreamFunctors
|
44 |
|
|
/// \brief Stream functor to allow inline skip() calls.
|
45 |
|
|
///
|
46 |
|
|
/// Example: os << ios::skip(sizeof(uint16_t));
|
47 |
|
|
///
|
48 |
|
|
class skip {
|
49 |
|
|
public:
|
50 |
|
|
inline explicit skip (size_t nBytes) : m_nBytes(nBytes) {}
|
51 |
|
|
inline istream& apply (istream& is) const { is.skip (m_nBytes); return (is); }
|
52 |
|
|
inline ostream& apply (ostream& os) const { os.skip (m_nBytes); return (os); }
|
53 |
|
|
inline void read (istream& is) const { apply (is); }
|
54 |
|
|
inline void write (ostream& os) const { apply (os); }
|
55 |
|
|
inline size_t stream_size (void) const { return (m_nBytes); }
|
56 |
|
|
private:
|
57 |
|
|
const size_t m_nBytes;
|
58 |
|
|
};
|
59 |
|
|
|
60 |
|
|
/// \class width uiosfunc.h ustl.h
|
61 |
|
|
/// \ingroup StreamFunctors
|
62 |
|
|
/// \brief Stream functor to allow inline set_width() calls.
|
63 |
|
|
///
|
64 |
|
|
/// Example: os << ios::width(15);
|
65 |
|
|
///
|
66 |
|
|
class width {
|
67 |
|
|
public:
|
68 |
|
|
inline explicit width (size_t nBytes) : m_nBytes(nBytes) {}
|
69 |
|
|
inline ostringstream& apply (ostringstream& os) const { os.set_width (m_nBytes); return (os); }
|
70 |
|
|
inline void text_write (ostringstream& os) const { apply (os); }
|
71 |
|
|
private:
|
72 |
|
|
const size_t m_nBytes;
|
73 |
|
|
};
|
74 |
|
|
|
75 |
|
|
/// \class base uiosfunc.h ustl.h
|
76 |
|
|
/// \ingroup StreamFunctors
|
77 |
|
|
/// \brief Stream functor to allow inline set_base() calls.
|
78 |
|
|
///
|
79 |
|
|
/// Example: os << ios::base(15);
|
80 |
|
|
///
|
81 |
|
|
class base {
|
82 |
|
|
public:
|
83 |
|
|
inline explicit base (size_t n) : m_Base(n) {}
|
84 |
|
|
inline ostringstream& apply (ostringstream& os) const { os.set_base (m_Base); return (os); }
|
85 |
|
|
inline void text_write (ostringstream& os) const { apply (os); }
|
86 |
|
|
private:
|
87 |
|
|
const size_t m_Base;
|
88 |
|
|
};
|
89 |
|
|
};
|
90 |
|
|
|
91 |
|
|
} // namespace ustl
|
92 |
|
|
|
93 |
|
|
CAST_STREAMABLE(ustl::ios::fmtflags, uint32_t)
|
94 |
|
|
NUMERIC_LIMITS(ustl::ios::fmtflags, ustl::ios::boolalpha, ustl::ios::floatfield, false, true, true)
|
95 |
|
|
|
96 |
|
|
#endif
|