Salome HOME
WIN32 compilation of the SMESH module:
[modules/smesh.git] / src / SMESHUtils / SMESH_File.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File      : SMESH_File.hxx
21 // Created   : Wed Mar 10 10:33:04 2010
22 // Author    : Edward AGAPOV (eap)
23 //
24 #ifndef __SMESH_File_HXX__
25 #define __SMESH_File_HXX__
26
27 #include "SMESH_Utils.hxx"
28
29 #include <string>
30 #include <vector>
31
32 #ifdef WIN32
33 #include <windows.h>
34 #else
35 #include <dlfcn.h>
36 #endif
37
38 /*!
39  * \brief High level util for effective file reading and other file operations
40  */
41 class SMESHUtils_EXPORT SMESH_File
42 {
43 public:
44
45   SMESH_File(const std::string& name, bool open=true);
46
47   ~SMESH_File();
48
49   std::string getName() const { return _name; }
50
51   bool open();
52
53   void close();
54
55   bool remove();
56
57   int size() const;
58
59   // ------------------------
60   // Access to file contents
61   // ------------------------
62
63   operator const char*() const { return _pos; }
64
65   bool operator++() { return ++_pos < _end; }
66
67   void operator +=(int posDelta) { _pos+=posDelta; }
68
69   bool eof() const { return _pos >= _end; }
70
71   const char* getPos() const { return _pos; }
72
73   void setPos(const char* pos);
74
75   std::string getLine();
76
77   void rewind();
78
79   bool getInts(std::vector<int>& ids);
80
81 private:
82
83   std::string _name; //!< file name
84   int         _size; //!< file size
85 #ifdef WIN32
86   HANDLE      _file, _mapObj;
87 #else
88   int         _file;
89 #endif
90   void*       _map;
91   const char* _pos; //!< current position
92   const char* _end; //!< position after file end
93 };
94
95 #endif