diff --git a/src/ifcparse/IfcFile.h b/src/ifcparse/IfcFile.h index 8b2137514aa..a121f45f006 100644 --- a/src/ifcparse/IfcFile.h +++ b/src/ifcparse/IfcFile.h @@ -138,7 +138,7 @@ class IFC_PARSE_API IfcFile { /// attributes as a flat list. NB: includes the root instance specified /// in the first function argument. IfcEntityList::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level=-1); - + #ifdef USE_MMAP bool Init(const std::string& fn, bool mmap=false); #else @@ -147,6 +147,8 @@ class IFC_PARSE_API IfcFile { bool Init(std::istream& fn, int len); bool Init(void* data, int len); bool Init(IfcParse::IfcSpfStream* f); + + bool Init(const std::string& data, unsigned int unused); IfcEntityList::ptr getInverse(int instance_id, IfcSchema::Type::Enum type, int attribute_index); @@ -174,4 +176,4 @@ class IFC_PARSE_API IfcFile { } -#endif \ No newline at end of file +#endif diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 1d46a4ab8fb..591b7ffe45c 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -108,6 +108,19 @@ void init_locale() { #endif +IfcSpfStream::IfcSpfStream() + : stream(0) + , buffer(0) + , valid(false) + , eof(false) +{ + ptr = 0; + len = 0; + valid = false; + eof = false; + size = 0; +} + // // Opens the file and gets the filesize // @@ -208,6 +221,18 @@ IfcSpfStream::IfcSpfStream(void* data, int l) len = l; } +IfcSpfStream::IfcSpfStream(const std::string& data, unsigned int x) + : stream(0) + , buffer(0) +{ + eof = false; + size = (unsigned int) data.length(); + buffer = data.c_str(); + valid = true; + ptr = 0; + len = (unsigned int) data.length(); +} + IfcSpfStream::~IfcSpfStream() { Close(); @@ -1227,16 +1252,17 @@ void IfcEntityInstanceData::setArgument(unsigned int i, Argument* a, IfcUtil::Ar // Parses the IFC file in fn // Creates the maps // + #ifdef USE_MMAP bool IfcFile::Init(const std::string& fn, bool mmap) { return IfcFile::Init(new IfcSpfStream(fn, mmap)); } #else bool IfcFile::Init(const std::string& fn) { + //return IfcFile::Init(new IfcSpfStream(fn, (unsigned int) 0)); return IfcFile::Init(new IfcSpfStream(fn)); } #endif - bool IfcFile::Init(std::istream& f, int len) { return IfcFile::Init(new IfcSpfStream(f,len)); } @@ -1244,6 +1270,10 @@ bool IfcFile::Init(std::istream& f, int len) { bool IfcFile::Init(void* data, int len) { return IfcFile::Init(new IfcSpfStream(data,len)); } +bool IfcFile::Init(const std::string& data, unsigned int unused) { + return IfcFile::Init(new IfcSpfStream(data, (unsigned int) 0)); +} + bool IfcFile::Init(IfcParse::IfcSpfStream* s) { // Initialize a "C" locale for locale-independent diff --git a/src/ifcparse/IfcSpfStream.h b/src/ifcparse/IfcSpfStream.h index 820b69d275a..5ca3fa53038 100644 --- a/src/ifcparse/IfcSpfStream.h +++ b/src/ifcparse/IfcSpfStream.h @@ -53,6 +53,7 @@ namespace IfcParse { bool valid; bool eof; unsigned int size; + IfcSpfStream(); #ifdef USE_MMAP IfcSpfStream(const std::string& fn, bool mmap=false); #else @@ -61,6 +62,7 @@ namespace IfcParse { IfcSpfStream(std::istream& f, int len); IfcSpfStream(void* data, int len); ~IfcSpfStream(); + IfcSpfStream(const std::string& data, unsigned int x); /// Returns the character at the cursor char Peek(); /// Returns the character at specified offset diff --git a/src/ifcwrap/IfcParseWrapper.i b/src/ifcwrap/IfcParseWrapper.i index b554b67e563..2119d5d29f1 100644 --- a/src/ifcwrap/IfcParseWrapper.i +++ b/src/ifcwrap/IfcParseWrapper.i @@ -412,14 +412,21 @@ private: // The IfcFile* returned by open() is to be freed by SWIG/Python %newobject open; +%newobject read; %inline %{ - IfcParse::IfcFile* open(const std::string& s) { + IfcParse::IfcFile* open(const std::string& fn) { IfcParse::IfcFile* f = new IfcParse::IfcFile(); - f->Init(s); + f->Init(fn); + return f; + } + IfcParse::IfcFile* read(const std::string& data) { + char* copiedData = new char[data.length()]; + memcpy(copiedData, data.c_str(), data.length()); + IfcParse::IfcFile* f = new IfcParse::IfcFile(); + f->Init((void *)copiedData, data.length()); return f; } - const char* schema_identifier() { return IfcSchema::Identifier; } @@ -459,4 +466,5 @@ private: ifcopenshell_log_stream.str(""); return log; } -%} \ No newline at end of file +%} +