1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESH_File.hxx
21 // Created : Wed Mar 10 10:33:04 2010
22 // Author : Edward AGAPOV (eap)
24 #ifndef __SMESH_File_HXX__
25 #define __SMESH_File_HXX__
27 #include "SMESH_Utils.hxx"
39 * \brief High level util for effective file reading and other file operations
41 class SMESHUtils_EXPORT SMESH_File
45 SMESH_File(const std::string& name, bool openForReading=true);
49 std::string getName() const { return _name; }
51 const std::string& error() const { return _error; }
63 // ------------------------
64 // Access to file contents
65 // ------------------------
67 bool open(); // for reading
69 operator const char*() const { return _pos; }
71 bool operator++() { return ++_pos < _end; }
73 void operator +=(int posDelta) { _pos+=posDelta; }
75 bool eof() const { return _pos >= _end; }
77 const char* end() const { return _end; }
79 const char* getPos() const { return _pos; }
81 void setPos(const char* pos);
83 std::string getLine();
87 bool getInts(std::vector<int>& ids);
89 // ------------------------
90 // Writing a binary file
91 // ------------------------
93 bool openForWriting(); // binary writing only
96 bool write( const T* values, size_t nbTValues )
98 return writeRaw((const void*) values, nbTValues * sizeof(T));
101 template <typename T>
102 bool write( const T& value )
104 return writeRaw((const void*) & value, sizeof(T));
107 bool writeRaw(const void* data, size_t size);
111 std::string _name; //!< file name
112 long _size; //!< file size
115 HANDLE _file, _mapObj;
120 const char* _pos; //!< current position
121 const char* _end; //!< position after file end