YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
cstdio.h
浏览该文件的文档.
1 /*
2  © 2011-2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YB_INC_ystdex_cstdio_h_
29 #define YB_INC_ystdex_cstdio_h_ 1
30 
31 #include "cassert.h" // for ../ydef.h, <cstdio> and yconstraint;
32 #include <ios> // for std::ios_base::openmode;
33 #include <iterator>
34 #include "iterator.hpp" // for ystdex::is_undereferenceable;
35 
36 namespace ystdex
37 {
38 
45 YB_API bool
46 fexists(const char*) ynothrow;
47 
48 
49 /*
50 \brief ISO C/C++ 标准输入输出接口打开模式转换。
51 \see ISO C++11 Table 132 。
52 \note 忽略 std::ios_base::ate 。
53 \since build 326
54 */
55 YB_API const char*
56 openmode_conv(std::ios_base::openmode) ynothrow;
57 /*
58 \brief ISO C/C++ 标准输入输出接口打开模式转换。
59 \return 若失败(包括空参数情形)为 std::ios_base::openmode() ,否则为对应的值。
60 \see ISO C11 7.21.5.3/3 。
61 \note 顺序严格限定。
62 \note 支持 x 转换。
63 \since build 326
64 */
65 YB_API std::ios_base::openmode
66 openmode_conv(const char*) ynothrow;
67 
68 
73 class YB_API ifile_iterator : public std::iterator<std::input_iterator_tag,
74  byte, ptrdiff_t, const byte*, const byte&>
75 {
76 protected:
77  using traits_type = std::iterator<std::input_iterator_tag, byte, ptrdiff_t,
78  const byte*, const byte&>;
79 
80 public:
81  using char_type = byte;
82 
83 private:
88  std::FILE* stream;
90 
91 public:
98  yconstfn
100  : stream(), value()
101  {}
108  explicit
109  ifile_iterator(std::FILE* ptr)
110  : stream(ptr)
111  {
112  yconstraint(ptr);
113  ++*this;
114  }
118  yconstfn
119  ifile_iterator(const ifile_iterator&) = default;
120  ~ifile_iterator() = default;
121 
123  yconstfn reference
124  operator*() const ynothrow
125  {
126  return value;
127  }
128 
129  yconstfn pointer
130  operator->() const
131  {
132  return &**this;
133  }
134 
135  /*
136  \brief 前置自增。
137  \pre 断言:流指针非空。
138  \return 自身引用。
139  \note 当读到 EOF 时置流指针为空指针。
140 
141  使用 std::fgetc 读字符。
142  */
144  operator++();
145  /*
146  \brief 后置自增。
147  \pre 断言:同前置自增。
148  \return 迭代器副本。
149 
150  读入字符。
151  */
154  {
155  const auto i(*this);
156 
157  ++*this;
158  return i;
159  }
160 
161  friend yconstfn bool
163  {
164  return x.stream == y.stream;
165  }
166 
167  yconstfn std::FILE*
168  get_stream() const
169  {
170  return stream;
171  }
172 };
173 
174 yconstfn bool
176 {
177  return !(x == y);
178 }
179 
180 
186 inline bool
188 {
189  return !i.get_stream();
190 }
191 
192 } // namespace ystdex;
193 
194 #endif
195 
ifile_iterator operator++(int)
Definition: cstdio.h:153
pointer operator->() const
Definition: cstdio.h:130
bool operator!=(nullptr_t lhs, const _type &rhs)
Definition: ydef.h:638
基于 ISO C 标准库的流只读迭代器。
Definition: cstdio.h:73
std::FILE * stream
流指针。
Definition: cstdio.h:88
friend bool operator==(const ifile_iterator &x, const ifile_iterator &y)
Definition: cstdio.h:162
unsigned char byte
字节类型。
Definition: ydef.h:555
ISO C 断言/调试跟踪扩展。
const char * openmode_conv(std::ios_base::openmode)
Definition: cstdio.cpp:49
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
std::FILE * get_stream() const
Definition: cstdio.h:168
reference operator*() const
Definition: cstdio.h:124
通用迭代器。
#define YB_API
YBase 应用程序编程接口:用于向库文件约定链接。
Definition: ydef.h:391
#define yconstraint
约束:接口语义。
Definition: cassert.h:47
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
char_type value
Definition: cstdio.h:89
ifile_iterator()
无参数构造。
Definition: cstdio.h:99
bool is_undereferenceable(const any_input_iterator< _type, _tDifference, _tPointer, _tReference > &i)
std::iterator< std::input_iterator_tag, byte, ptrdiff_t, const byte *, const byte & > traits_type
Definition: cstdio.h:78
ifile_iterator(std::FILE *ptr)
构造:使用流引用。
Definition: cstdio.h:109
bool fexists(const char *)
判断指定路径的文件是否存在。
Definition: cstdio.cpp:36