Files
OCCT/src/OSD/OSD_FileSystemSelector.cxx
kgv 65acdce54c 0032352: Coding Rules - clean up code from compatibility hacks with pre-C++11 compilers
Removed usage of std::auto_ptr.
opencascade::std workarounds for VS2008 have been dropped, when possible.
OCCT_NO_RVALUE_REFERENCE workaround for VS2008 has been removed.
2021-12-03 17:56:37 +03:00

179 lines
6.7 KiB
C++

// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <OSD_FileSystemSelector.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OSD_FileSystemSelector, OSD_FileSystem)
//=======================================================================
// function : AddProtocol
// purpose :
//=======================================================================
void OSD_FileSystemSelector::AddProtocol (const Handle(OSD_FileSystem)& theFileSystem, bool theIsPreferred)
{
myProtocols.Remove (theFileSystem); // avoid duplicates
if (theIsPreferred)
{
myProtocols.Prepend (theFileSystem);
}
else
{
myProtocols.Append (theFileSystem);
}
}
//=======================================================================
// function : RemoveProtocol
// purpose :
//=======================================================================
void OSD_FileSystemSelector::RemoveProtocol (const Handle(OSD_FileSystem)& theFileSystem)
{
myProtocols.Remove (theFileSystem);
}
//=======================================================================
// function : IsSupportedPath
// purpose :
//=======================================================================
Standard_Boolean OSD_FileSystemSelector::IsSupportedPath (const TCollection_AsciiString& theUrl) const
{
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter(myProtocols); aProtIter.More(); aProtIter.Next())
{
if (aProtIter.Value()->IsSupportedPath (theUrl))
{
return true;
}
}
return false;
}
//=======================================================================
// function : IsOpenIStream
// purpose :
//=======================================================================
Standard_Boolean OSD_FileSystemSelector::IsOpenIStream (const std::shared_ptr<std::istream>& theStream) const
{
std::shared_ptr<OSD_IStreamBuffer> aFileStream = std::dynamic_pointer_cast<OSD_IStreamBuffer> (theStream);
if (aFileStream.get() == NULL)
{
return false;
}
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter(myProtocols); aProtIter.More(); aProtIter.Next())
{
const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
if (aFileSystem->IsSupportedPath (TCollection_AsciiString (aFileStream->Url().c_str())))
{
if (aFileSystem->IsOpenIStream (theStream))
{
return true;
}
}
}
return false;
}
//=======================================================================
// function : IsOpenOStream
// purpose :
//=======================================================================
Standard_Boolean OSD_FileSystemSelector::IsOpenOStream (const std::shared_ptr<std::ostream>& theStream) const
{
std::shared_ptr<OSD_OStreamBuffer> aFileStream = std::dynamic_pointer_cast<OSD_OStreamBuffer> (theStream);
if (aFileStream.get() == NULL)
{
return false;
}
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
{
const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
if (aFileSystem->IsSupportedPath (TCollection_AsciiString (aFileStream->Url().c_str())))
{
if (aFileSystem->IsOpenOStream (theStream))
{
return true;
}
}
}
return false;
}
//=======================================================================
// function : OpenIStream
// purpose :
//=======================================================================
std::shared_ptr<std::istream> OSD_FileSystemSelector::OpenIStream (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode,
const int64_t theOffset,
const std::shared_ptr<std::istream>& theOldStream)
{
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
{
const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
if (aFileSystem->IsSupportedPath (theUrl))
{
std::shared_ptr<std::istream> aStream = aFileSystem->OpenIStream (theUrl, theMode, theOffset, theOldStream);
if (aStream.get() != NULL)
{
return aStream;
}
}
}
return std::shared_ptr<std::istream>();
}
//=======================================================================
// function : OpenOStream
// purpose :
//=======================================================================
std::shared_ptr<std::ostream> OSD_FileSystemSelector::OpenOStream (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode)
{
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
{
const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
if (aFileSystem->IsSupportedPath (theUrl))
{
std::shared_ptr<std::ostream> aStream = aFileSystem->OpenOStream (theUrl, theMode);
if (aStream.get() != NULL)
{
return aStream;
}
}
}
return std::shared_ptr<std::ostream>();
}
//=======================================================================
// function : OpenStreamBuffer
// purpose :
//=======================================================================
std::shared_ptr<std::streambuf> OSD_FileSystemSelector::OpenStreamBuffer (const TCollection_AsciiString& theUrl,
const std::ios_base::openmode theMode,
const int64_t theOffset,
int64_t* theOutBufSize)
{
for (NCollection_List<Handle(OSD_FileSystem)>::Iterator aProtIter (myProtocols); aProtIter.More(); aProtIter.Next())
{
const Handle(OSD_FileSystem)& aFileSystem = aProtIter.Value();
if (aFileSystem->IsSupportedPath (theUrl))
{
std::shared_ptr<std::streambuf> aBuf = aFileSystem->OpenStreamBuffer (theUrl, theMode, theOffset, theOutBufSize);
if (aBuf.get() != NULL)
{
return aBuf;
}
}
}
return std::shared_ptr<std::streambuf>();
}