YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yfile.cpp
浏览该文件的文档.
1 /*
2  Copyright (C) by Franksoft 2009 - 2012.
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 #include "YSLib/Service/yfile.h"
29 #include "YSLib/Core/yfilesys.h"
30 
32 
33 File::File()
34  : fp(), fsize(0)
35 {}
36 File::File(const_path_t filename, const char* mode)
37  : File()
38 {
39  if(Open(filename, mode))
40  {
41  Seek(0, SEEK_END);
42  fsize = GetPosition();
43  Rewind();
44  }
45 }
46 File::File(const_path_t filename, std::ios_base::openmode mode)
47  : File(filename, ystdex::openmode_conv(mode))
48 {}
49 File::File(const String& filename, const ucs2_t* mode)
50  : File()
51 {
52  if(Open(filename, mode))
53  {
54  Seek(0, SEEK_END);
55  fsize = GetPosition();
56  Rewind();
57  }
58 }
59 File::File(const String& filename, std::ios_base::openmode mode)
60  : File(filename, String(ystdex::openmode_conv(mode)).c_str())
61 {}
62 
64 {
65  Close();
66 }
67 
68 void
70 {
71  Seek(0, SEEK_END);
72  fsize = GetPosition();
73  Rewind();
74 }
75 
76 void
78 {
79  if(*this)
80  std::fclose(fp);
81 }
82 
83 bool
84 File::Open(const_path_t filename, const char* mode)
85 {
86  Close();
87  if((fp = ufopen(filename, mode)))
88  CheckSize();
89  return fp;
90 }
91 bool
92 File::Open(const_path_t filename, std::ios_base::openmode mode)
93 {
94  return Open(filename, ystdex::openmode_conv(mode));
95 }
96 bool
97 File::Open(const String& filename, const ucs2_t* mode)
98 {
99  Close();
100  if((fp = ufopen(filename.c_str(), mode)))
101  CheckSize();
102  return fp;
103 }
104 bool
105 File::Open(const String& filename, std::ios_base::openmode mode)
106 {
107  return Open(filename, String(ystdex::openmode_conv(mode)).c_str());
108 }
109 
110 bool
111 File::Truncate(size_t size) const
112 {
113  return truncate(GetPtr(), size);
114 }
115 
116 YSL_END
117