~vbursian/research-assistant/intervers

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