1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0028887: TKJT - add option to cache file content

Added new auxiliary class Standard_ArrayStreamBuffer implementing
std::streambuf interface for defining std::istream from allocated memory.
This commit is contained in:
kgv
2017-07-03 20:22:56 +03:00
committed by bugmaster
parent da67ffb75a
commit a5460e9d98
6 changed files with 428 additions and 0 deletions

View File

@@ -59,6 +59,8 @@
#include <HLRBRep_PolyHLRToShape.hxx>
#include <HLRBRep_PolyAlgo.hxx>
#include <limits>
//=======================================================================
//function : SurfaceGenOCC26675_1
//purpose : Generates a surface for intersect (in corresponding
@@ -2340,6 +2342,99 @@ static Standard_Integer OCC28829 (Draw_Interpretor&, Standard_Integer, const cha
return 0;
}
#include <NCollection_Buffer.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <OSD_OpenFile.hxx>
#include <Standard_ArrayStreamBuffer.hxx>
#include <TDataStd_Name.hxx>
#include <TDocStd_Application.hxx>
#ifdef max
#undef max
#endif
static Standard_Integer OCC28887 (Draw_Interpretor&, Standard_Integer theNbArgs, const char** theArgVec)
{
if (theNbArgs < 3)
{
std::cout << "Syntax error: wrong number of arguments!\n";
return 1;
}
const TCollection_AsciiString aFilePath (theArgVec[1]);
const TCollection_AsciiString aName (theArgVec[2]);
Handle(NCollection_Buffer) aBuffer;
{
std::ifstream aFile;
OSD_OpenStream (aFile, aFilePath.ToCString(), std::ios::binary | std::ios::in);
if (!aFile.is_open())
{
std::cout << "Error: input file '" << aFilePath << "' cannot be read\n";
return 1;
}
aFile.seekg (0, std::ios_base::end);
const int64_t aFileLength = int64_t (aFile.tellg());
if (aFileLength > int64_t (std::numeric_limits<ptrdiff_t>::max())
|| aFileLength < 1)
{
std::cout << "Error: input file '" << aFilePath << "' is too large\n";
return 1;
}
aFile.seekg (0, std::ios_base::beg);
aBuffer = new NCollection_Buffer (NCollection_BaseAllocator::CommonBaseAllocator());
if (!aBuffer->Allocate (size_t(aFileLength)))
{
std::cout << "Error: memory allocation (" << aFileLength << ") has failed\n";
return 1;
}
aFile.read ((char* )aBuffer->ChangeData(), aBuffer->Size());
if (!aFile.good())
{
std::cout << "Error: input file '" << aFilePath << "' reading failure\n";
return 1;
}
}
Standard_ArrayStreamBuffer aStreamBuffer ((const char* )aBuffer->ChangeData(), aBuffer->Size());
std::istream aStream (&aStreamBuffer);
// just play with seeking
aStream.seekg (0, std::ios_base::end);
aStream.seekg (0, std::ios_base::beg);
if (aFilePath.EndsWith (".brep")
|| aFilePath.EndsWith (".rle"))
{
TopoDS_Shape aShape;
BRep_Builder aBuilder;
BRepTools::Read (aShape, aStream, aBuilder);
DBRep::Set (aName.ToCString(), aShape);
}
else
{
Handle(TDocStd_Document) aDoc;
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
Standard_CString aNameVar = aName.ToCString();
if (DDocStd::GetDocument (aNameVar, aDoc, Standard_False))
{
std::cout << "Error: document with name " << aName << " already exists\n";
return 1;
}
if (anApp->Open (aStream, aDoc) != PCDM_RS_OK)
{
std::cout << "Error: cannot open XDE document\n";
return 1;
}
Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
TDataStd_Name::Set (aDoc->GetData()->Root(), aName.ToCString());
Draw::Set (aName.ToCString(), aDrawDoc);
}
return 0;
}
void QABugs::Commands_20(Draw_Interpretor& theCommands) {
const char *group = "QABugs";
@@ -2363,6 +2458,10 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
theCommands.Add("OCC28594", "OCC28594", __FILE__, OCC28594, group);
theCommands.Add("OCC28784", "OCC28784 result shape", __FILE__, OCC28784, group);
theCommands.Add("OCC28829", "OCC28829: perform invalid FPE operation", __FILE__, OCC28829, group);
theCommands.Add("OCC28887",
"OCC28887 filePath result"
"\n\t\t: Check interface for reading BRep from memory.",
__FILE__, OCC28887, group);
return;
}