Back to index

salome-smesh  6.5.0
SMESH_File.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File      : SMESH_File.hxx
00021 // Created   : Wed Mar 10 10:33:04 2010
00022 // Author    : Edward AGAPOV (eap)
00023 //
00024 #ifndef __SMESH_File_HXX__
00025 #define __SMESH_File_HXX__
00026 
00027 #include "SMESH_Utils.hxx"
00028 
00029 #include <string>
00030 #include <vector>
00031 
00032 #ifdef WNT
00033 #include <windows.h>
00034 #else
00035 #include <dlfcn.h>
00036 #endif
00037 
00041 class SMESHUtils_EXPORT SMESH_File
00042 {
00043 public:
00044 
00045   SMESH_File(const std::string& name, bool open=true);
00046 
00047   ~SMESH_File();
00048 
00049   std::string getName() const { return _name; }
00050 
00051   bool open();
00052 
00053   void close();
00054 
00055   bool remove();
00056 
00057   int size() const;
00058 
00059   // ------------------------
00060   // Access to file contents
00061   // ------------------------
00062 
00063   operator const char*() const { return _pos; }
00064 
00065   bool operator++() { return ++_pos < _end; }
00066 
00067   void operator +=(int posDelta) { _pos+=posDelta; }
00068 
00069   bool eof() const { return _pos >= _end; }
00070 
00071   const char* getPos() const { return _pos; }
00072 
00073   void setPos(const char* pos);
00074 
00075   std::string getLine();
00076 
00077   void rewind();
00078 
00079   bool getInts(std::vector<int>& ids);
00080 
00081 private:
00082 
00083   std::string _name; 
00084   int         _size; 
00085 #ifdef WNT
00086   HANDLE      _file, _mapObj;
00087 #else
00088   int         _file;
00089 #endif
00090   void*       _map;
00091   const char* _pos; 
00092   const char* _end; 
00093 };
00094 
00095 #endif