Open the hdbIsamfile instance. This is a matter of opening an input stream for the data file, an output stream for the data file and an output stream for the index file. Note both the output streams are opened with ios::app as they will only ever append and that there is no input stream for the index file as during normal operation of a hdbIsamfile, the index is never read. Arguments: None

Return TypeFunction nameArguments
hzEcodehdbIsamfile::Open(void)

Declared in file: hzDatabase.h
Defined in file : hdbIsamfile.cpp

Function Logic:

0:START 1:unknown 2:items 3:unknown 4:items 5:items 6:unknown 7:Return hzerr(E_OPENFAIL,Cannot open index file for writing: Repos %s,*m_fileDelta) 8:items 9:unknown 10:Return hzerr(E_OPENFAIL,Could not open file (%s) for writing,*m_fileStore) 11:items 12:unknown 13:Return hzerr(E_OPENFAIL,Could not open index file (%s) for reading,*m_fileStore) 14:m_nBlocks 15:unknown 16:items 17:unknown 18:items m_Buf items m_Buf key items items 19:items 20:unknown 21:addr key items 22:items items 23:unknown 24:Return hzerr(E_OPENFAIL,Could not open data file (%s) for reading,*m_fileStore) 25:m_nInitState 26:Return E_OK

Function body:

hzEcode hdbIsamfile::Open (void)
{
   //  Open the hdbIsamfile instance.
   //  
   //  This is a matter of opening an input stream for the data file, an output stream for the data file and an output stream for the index file. Note both the
   //  output streams are opened with ios::app as they will only ever append and that there is no input stream for the index file as during normal operation of
   //  a hdbIsamfile, the index is never read.
   //  
   //  Arguments: None
   //  
   //  Returns: E_NOINIT If the repository has not been initialized
   //     E_SEQUENCE If the repository is already open
   //     E_OPENFAIL If either the index or data file cannot be opened for either reading or writing
   //     E_OK  If the operation was successful
   _hzfunc("hdbIsamfile::Open") ;
   hzMapS<uint32_t,hzString>   tmp ;   //  Temporary map
   ifstream    is ;            //  Index input stream
   hzString    key ;           //  Key
   uint32_t    addr ;          //  Block address
   uint32_t    nLines = 0; //  Line count
   uint32_t    n ;             //  Temp index iterator
   if (m_nInitState == 0)  hzexit(E_NOINIT, "Cannot open an uninitialized datacron") ;
   if (m_nInitState == 2)  hzexit(E_SEQUENCE, "Datacron %s is already open", *m_Name) ;
   //  m_WrI.open(*m_fileDelta, std::ios::app) ;
   m_WrI.open(*m_fileDelta) ;
   if (m_WrI.fail())
       return hzerr(E_OPENFAIL, "Cannot open index file for writing: Repos %s", *m_fileDelta) ;
   //  m_WrD.open(*m_fileStore, std::ios::app) ;
   m_WrD.open(*m_fileStore) ;
   if (m_WrD.fail())
       return hzerr(E_OPENFAIL, "Could not open file (%s) for writing", *m_fileStore) ;
   is.open(*m_fileDelta) ;
   if (is.fail())
       return hzerr(E_OPENFAIL, "Could not open index file (%s) for reading", *m_fileStore) ;
   m_nBlocks = 0;
   for (;;)
   {
       is.getline(m_Buf, 500);
       if (!is.gcount())
           break ;
       nLines++ ;
       //  Block address is first part of line, key is remainder
       m_Buf[8]= 0;
       IsHexnum(addr, m_Buf) ;
       key = m_Buf + 9;
       tmp.Insert(addr, key) ;
       m_nBlocks++ ;
   }
   is.close() ;
   //  Transpose tmp index to operational index
   for (n = 0; n < tmp.Count() ; n++)
   {
       addr = tmp.GetKey(n) ;
       key = tmp.GetObj(n) ;
       m_Index.Insert(key, addr) ;
   }
   tmp.Clear() ;
   //  m_RdI.open(*m_fileDelta) ;
   //  if (m_RdI.fail())
   //   return hzerr(E_OPENFAIL, "Could not open index file (%s) for reading", *m_fileStore) ;
   m_RdD.open(*m_fileStore) ;
   if (m_RdD.fail())
       return hzerr(E_OPENFAIL, "Could not open data file (%s) for reading", *m_fileStore) ;
   m_nInitState = 2;
   return E_OK ;
}