Шаблон:CreateFileAsBinaryDataStorage example: различия между версиями

Материал из CAMaaS preliminary wiki
Перейти к навигации Перейти к поиску
(Новая страница: «<source lang='cpp'> char l_filename[] = "./somefile"; std::size_t cb_filename = sizeof(l_filename) - 1 →‎term. 0: ; IIOBinaryData* pIO; //uninitialized pointer {…»)
 
Строка 12: Строка 12:
   err = pStorage->IsInterfaceAvailable(IOBinaryDataType);
   err = pStorage->IsInterfaceAvailable(IOBinaryDataType);
   if (err < 0)
   if (err < 0)
  {
      pStorage->Release();
       return -1; //failure of IsInterfaceAvailable
       return -1; //failure of IsInterfaceAvailable
  }
   if (err == 1)
   if (err == 1)
  {
      pSotrage->Release();
       return 0; //Interface is not available
       return 0; //Interface is not available
  }
   err = pStorage->RepresentAs(IOBinaryDataType, (void**) std::addressof(pIO));
   err = pStorage->RepresentAs(IOBinaryDataType, (void**) std::addressof(pIO));
   if (err < 0)
   if (err < 0)
  {
      pStorage->Release();
       return -1; //failure of RepresentAs
       return -1; //failure of RepresentAs
  }
  pStorage->Release();
}
}
//access file via pIO...
//access file via pIO...
pIO->Release();
</source>
</source>

Версия 16:27, 16 марта 2017

char l_filename[] = "./somefile";
std::size_t cb_filename = sizeof(l_filename) - 1 /*term. 0*/;

IIOBinaryData* pIO; //uninitialized pointer
{
   IBinaryDataBase* pStorage; //uninitialized pointer
   int32_t err = CreateFileAsBinaryDataStorage(l_filename, cb_filename, FileRead | FileWrite, FileCreateAlways, std::addressof(pStorage));

   if (err < 0)
      return -1; //failure
   err = pStorage->IsInterfaceAvailable(IOBinaryDataType);
   if (err < 0)
   {
      pStorage->Release();
      return -1; //failure of IsInterfaceAvailable
   }
   if (err == 1)
   {
      pSotrage->Release();
      return 0; //Interface is not available
   }
   err = pStorage->RepresentAs(IOBinaryDataType, (void**) std::addressof(pIO));
   if (err < 0)
   {
      pStorage->Release();
      return -1; //failure of RepresentAs
   }
   pStorage->Release();
}
//access file via pIO...

pIO->Release();