Changeset b67be8d in tol


Ignore:
Timestamp:
Sep 7, 2009, 7:47:05 AM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
d626b32
Parents:
d794d03
Message:

New class BFileDesc to ahndle with TOL file input-output functions

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1340 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol/btol/bdb
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/bdb/filehandle.cpp

    rd794d03 rb67be8d  
    2525
    2626
     27#include <tol/tol_filehandle.h>
    2728#include <tol/tol_bout.h>
    2829#include <tol/tol_btxtgra.h>
    … …  
    3940BTraceInit("file.cpp");
    4041
    41 /////////////////////////////////////////////////////////////////////////////
    42 struct BFileDesc
    43 /////////////////////////////////////////////////////////////////////////////
    44 {
    45   FILE* file_;
    46   BText path_;
    47   BFileDesc(FILE* file, BText path)
    48   : file_(file),
    49     path_(path)
    50   { }
    51 };
    52 
    53 BFileDesc noFileDesc_(NULL,"");
    54 
    55 typedef hash_map_by_int <BFileDesc*>::dense_ BFileHashByHandle;
    56 
    57 
    58 /////////////////////////////////////////////////////////////////////////////
    59 static BFileHashByHandle& FileHandle()
     42
     43BFileDesc BFileDesc::noFileDesc_(NULL,"");
     44
     45
     46/////////////////////////////////////////////////////////////////////////////
     47BFileDesc::BFileHashByHandle& BFileDesc::FileHandle()
    6048/////////////////////////////////////////////////////////////////////////////
    6149{
    … …  
    7361
    7462/////////////////////////////////////////////////////////////////////////////
    75 static FILE* CheckFileHandle(int handle, bool verbose, const BText& msg,
    76                              BFileHashByHandle::const_iterator& found)
     63 FILE* BFileDesc::CheckFileHandle(int handle, bool verbose, const BText& msg,
     64                                  BFileHashByHandle::const_iterator& found)
    7765/////////////////////////////////////////////////////////////////////////////
    7866{
    … …  
    9684
    9785/////////////////////////////////////////////////////////////////////////////
    98 static FILE* CheckFileHandle(int handle, bool verbose, const BText& msg)
     86FILE* BFileDesc::CheckFileHandle(int handle, bool verbose, const BText& msg)
    9987/////////////////////////////////////////////////////////////////////////////
    10088{
    … …  
    10492
    10593/////////////////////////////////////////////////////////////////////////////
    106 void SysChkErrNo(bool clean, bool verbose, const BText& msg)
     94void BFileDesc::SysChkErrNo(bool clean, bool verbose, const BText& msg)
    10795/////////////////////////////////////////////////////////////////////////////
    10896{
    … …  
    145133  if(Arg(2)) { verbose = int(Real(Arg(2)))!=0; }
    146134  contens_ = errno;
    147   SysChkErrNo(clean, verbose, "");
     135  BFileDesc::SysChkErrNo(clean, verbose, "");
    148136}
    149137
    … …  
    215203  {
    216204    handle = fileno(file);
    217     FileHandle()[handle] = new BFileDesc(file, path);
     205    BFileDesc::FileHandle()[handle] = new BFileDesc(file, path);
    218206  }
    219207  else
    220208  {
    221     SysChkErrNo(clean, verbose,
     209    BFileDesc::SysChkErrNo(clean, verbose,
    222210      I2("Fail in ","Fallo en ")+
    223211      "FOpen(\""+path+"\",\""+access+"\")");
    … …  
    245233  contens_ = "";
    246234   
    247   FILE* file = CheckFileHandle(handle,true,
     235  FILE* file = BFileDesc::CheckFileHandle(handle,true,
    248236                               I2("Fail in ","Fallo en ")+"FGetText");
    249237  if(file)
    … …  
    266254  BText& txt    = Text(Arg(2));
    267255  contens_ = EOF;
    268   FILE* file = CheckFileHandle(handle,true,
     256  FILE* file = BFileDesc::CheckFileHandle(handle,true,
    269257                               I2("Fail in ","Fallo en ")+"FPutText");
    270258  if(file)
    … …  
    288276  int handle  = (int)Real(Arg(1));
    289277  contens_ = EOF;
    290   FILE* file = CheckFileHandle(handle, true,
     278  FILE* file = BFileDesc::CheckFileHandle(handle, true,
    291279                               I2("Fail in ","Fallo en ")+"FEof");
    292280  if(file)
    … …  
    320308  else
    321309  {
    322     FILE* file = CheckFileHandle(handle, true,
     310    FILE* file = BFileDesc::CheckFileHandle(handle, true,
    323311                                 I2("Fail in ","Fallo en ")+"FFlush");
    324312    if(file)
    … …  
    350338  if(Arg(3)) { verbose = int(Real(Arg(3)))!=0; }
    351339  contens_ = EOF;
    352   BFileHashByHandle::const_iterator found;
     340  BFileDesc::BFileHashByHandle::const_iterator found;
    353341  BText failMsg = I2("Fail in ","Fallo en ")+"FClose";
    354   FILE* file = CheckFileHandle(handle, true, failMsg, found);
     342  FILE* file = BFileDesc::CheckFileHandle(handle, true, failMsg, found);
    355343  if(file)
    356344  {
    … …  
    359347    if(!fc)
    360348    {
    361       FileHandle().erase(found->first);
     349      BFileDesc::FileHandle().erase(found->first);
    362350    }
    363351    else
    364352    {
    365       SysChkErrNo(clean, verbose, failMsg);
     353      BFileDesc::SysChkErrNo(clean, verbose, failMsg);
    366354    }
    367355  }
Note: See TracChangeset for help on using the changeset viewer.