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