1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
////////////////////////////////////////////////////////////////////////////////
/*! @file Files.h Минимальный интерфейс файловой системы.
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
- Copyright(C) 2010, Viktor E. Bursian, St.Petersburg, Russia.
Viktor.Bursian@mail.ioffe.ru
*///////////////////////////////////////////////////////////////////////////////
#ifndef Files_H
#define Files_H
#include "General.h"
#include "Strings.h"
#include "Time.h"
#include <fstream>
namespace RA {
//------------------------------------------------------------------------------
ANNOUNCE_CLASS(sPath)
ANNOUNCE_CLASS(sFile)
//-------------------------------------------------------------------- sPath ---
class RANet_EXPORT sPath
{
public: //static
static sPath CurrentDir ();
static sString Validate (rcsString S);
static sString ValidateName (rcsString S);
public:
sPath ();
sPath (rcsString);
// sPath (rcsString dir
// ,rcsString path_relative_to_the_dir);
// sPath (rcsString dir
// ,rcsString path_relative_to_the_dir
// ,rcsString extension);
sPath (rcsPath);
rsPath operator = (rcsPath);
rsPath operator = (rcsString S)
{ return operator=(sPath(S)); }
// rsPath operator = (literal L)
// { return operator=(sPath(sString(L))); };
rcsString PathStr () const
{ return ThePathStr; }
sPath Dir () const;
sString Name () const;
sString Ext () const;
void Validate ();
bool Exists () const;
sTime ModificationTime () const;
sTime AccessTime () const;
sTime CreationTime () const;
bool Erase () const;
bool CreateDirForIt () const;
private:
void Split (rsString dir
,rsString name
,rsString extension) const;
// void Construct (rcsString dir
// ,rcsString path_relative_to_the_dir
// ,rcsString extension);
sString ThePathStr;
};
//------------------------------------------------------------------------------
//class sFileLocation
//{
// public:
// static const char DirDelimiter;
// static sString Validate (rcsString);
//
// public:
// sFileLocation (rcsString);
// sFileLocation ()
// {};
// sFileLocation (rcsFileLocation F)
// :IsDirectory(F.IsDirectory)
// ,IsUNCName(F.IsUNCName)
// ,Volume(F.Volume)
// ,Dir(F.Dir),Name(F.Name),Ext(F.Ext)
// {};
// public:
// rsFileLocation operator = (rcsFileLocation F)
// {
// IsDirectory=F.IsDirectory;
// IsUNCName=F.IsUNCName;
// Volume=F.Volume;
// Dir=F.Dir; Name=F.Name; Ext=F.Ext;
// return *this;
// };
// rsFileLocation operator = (rcsString S)
// { return operator=(sFileLocation(S)); };
// rsFileLocation operator = (literal L)
// { return operator=(sFileLocation(sString(L))); };
// sString Path () const;
// bool Exists () const;
// bool DirExists () const;
// void CreateDirForIt () const;
// sFileLocation WithName (rcsString another_name);
// sFileLocation WithExt (rcsString another_ext);
// public:
// bool IsDirectory;
// bool IsUNCName;
// sString Volume;
// sString Dir;
// sString Name;
// sString Ext; //includes period if not empty
//};
//-------------------------------------------------------------------- sFile ---
class RANet_EXPORT sFile : public std::fstream
{
public:
enum eStateMode
{NotAssigned,Closed,EndOfFile,Opened};
enum eTypeMode
{Binary,Textual};
enum eOpenMode
{Reading,Writing,Updating,Appending};
public:
virtual ~sFile ();
sFile ()
:std::fstream()
,State(NotAssigned)
{}
virtual void Assign (rcsString fname
,eTypeMode type=Binary);
virtual void Assign (rcsPath file_path
,eTypeMode type=Binary);
virtual void Open (eOpenMode mode);
virtual void Close ();
// virtual bool TryToOpen (eOpenMode mode);
// virtual bool TryToClose ();
virtual void SetWritingPosition (tStreamPos pos)
{ seekp(pos); }
virtual tStreamPos GetReadingPosition ()
{ return tellg(); }
virtual void WriteBlock (const char * data_ptr
,size_t data_size)
{ write(data_ptr ,data_size); }
virtual void ReadBlock (char * data_ptr ,size_t data_size)
{ read(data_ptr ,data_size); }
private: // fields
eStateMode State;
eTypeMode Type;
eOpenMode Mode;
sString FullName;
};
//------------------------------------------------------------------------------
} //namespace RA
#endif
|