Salome HOME
aa175dfecbd1e6b6e364d88ec9c24e200c8e81f2
[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 #ifdef WNT
36 #include <windows.h>
37 #else
38 #include <dlfcn.h>
39 #endif
40
41 /*!
42  * \brief High level util for effective file reading and other file operations
43  */
44 class SMESH_EXPORT SMESH_File
45 {
46 public:
47
48   SMESH_File(const std::string& name, bool open=true);
49
50   ~SMESH_File();
51
52   std::string getName() const { return _name; }
53
54   bool open();
55
56   void close();
57
58   bool remove();
59
60   int size() const;
61
62   // ------------------------
63   // Access to file contents
64   // ------------------------
65
66   operator const char*() const { return _pos; }
67
68   bool operator++() { return ++_pos < _end; }
69
70   void operator +=(int posDelta) { _pos+=posDelta; }
71
72   bool eof() const { return _pos >= _end; }
73
74   const char* getPos() const { return _pos; }
75
76   void setPos(const char* pos);
77
78   std::string getLine();
79
80   void rewind();
81
82   bool getInts(std::vector<int>& ids);
83
84 private:
85
86   std::string _name; //!< file name
87   int         _size; //!< file size
88 #ifdef WNT
89   HANDLE      _file, _mapObj;
90 #else
91   int         _file;
92 #endif
93   void*       _map;
94   const char* _pos; //!< current position
95   const char* _end; //!< position after file end
96 };
97
98 #endif