Skip to content

Commit c2e867e

Browse files
author
Luke Brooks
committed
Changes the default behavior of IfcFile::Init to copy an existing string
instead of creating a new file descriptor. Creating a method named `Dup` repeatedly fails with a "No member named 'Dup'" error. The implementation is commented out in case a maintained knows or figures out how to get it working. Same for a `read` method on the Python wrapper that utilises `Dup`.
1 parent d10efe6 commit c2e867e

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

src/ifcparse/.IfcFile.h.swp

16 KB
Binary file not shown.

src/ifcparse/.IfcParse.cpp.swp

76 KB
Binary file not shown.

src/ifcparse/IfcFile.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class IFC_PARSE_API IfcFile {
106106
/// attributes as a flat list. NB: includes the root instance specified
107107
/// in the first function argument.
108108
IfcEntityList::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level=-1);
109-
109+
110110
#ifdef USE_MMAP
111111
bool Init(const std::string& fn, bool mmap=false);
112112
#else
@@ -115,6 +115,8 @@ class IFC_PARSE_API IfcFile {
115115
bool Init(std::istream& fn, int len);
116116
bool Init(void* data, int len);
117117
bool Init(IfcParse::IfcSpfStream* f);
118+
119+
//bool Dup(const std::string& data);
118120

119121
IfcEntityList::ptr getInverse(int instance_id, IfcSchema::Type::Enum type, int attribute_index);
120122

@@ -142,4 +144,4 @@ class IFC_PARSE_API IfcFile {
142144

143145
}
144146

145-
#endif
147+
#endif

src/ifcparse/IfcParse.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ void init_locale() {
108108

109109
#endif
110110

111+
IfcSpfStream::IfcSpfStream()
112+
: stream(0)
113+
, buffer(0)
114+
, valid(false)
115+
, eof(false)
116+
{
117+
ptr = 0;
118+
len = 0;
119+
valid = false;
120+
eof = false;
121+
size = 0;
122+
}
123+
111124
//
112125
// Opens the file and gets the filesize
113126
//
@@ -208,6 +221,18 @@ IfcSpfStream::IfcSpfStream(void* data, int l)
208221
len = l;
209222
}
210223

224+
IfcSpfStream::IfcSpfStream(const std::string& data, unsigned int x)
225+
: stream(0)
226+
, buffer(0)
227+
{
228+
eof = false;
229+
size = (unsigned int) data.length();
230+
buffer = data.c_str();
231+
valid = true;
232+
ptr = 0;
233+
len = (unsigned int) data.length();
234+
}
235+
211236
IfcSpfStream::~IfcSpfStream()
212237
{
213238
Close();
@@ -1219,16 +1244,22 @@ void IfcEntityInstanceData::setArgument(unsigned int i, Argument* a, IfcUtil::Ar
12191244
// Parses the IFC file in fn
12201245
// Creates the maps
12211246
//
1247+
/*
1248+
* bool IfcFile::Dup(const std::string& data) {
1249+
* return IfcFile::Init(new IfcSpfStream(data, (unsigned int) 0));
1250+
* }
1251+
*/
1252+
12221253
#ifdef USE_MMAP
12231254
bool IfcFile::Init(const std::string& fn, bool mmap) {
12241255
return IfcFile::Init(new IfcSpfStream(fn, mmap));
12251256
}
12261257
#else
12271258
bool IfcFile::Init(const std::string& fn) {
1259+
return IfcFile::Init(new IfcSpfStream(fn, (unsigned int) 0));
12281260
return IfcFile::Init(new IfcSpfStream(fn));
12291261
}
12301262
#endif
1231-
12321263
bool IfcFile::Init(std::istream& f, int len) {
12331264
return IfcFile::Init(new IfcSpfStream(f,len));
12341265
}
@@ -1237,6 +1268,7 @@ bool IfcFile::Init(void* data, int len) {
12371268
return IfcFile::Init(new IfcSpfStream(data,len));
12381269
}
12391270

1271+
12401272
bool IfcFile::Init(IfcParse::IfcSpfStream* s) {
12411273
// Initialize a "C" locale for locale-independent
12421274
// number parsing. See comment above on line 41.

src/ifcparse/IfcSpfStream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace IfcParse {
5353
bool valid;
5454
bool eof;
5555
unsigned int size;
56+
IfcSpfStream();
5657
#ifdef USE_MMAP
5758
IfcSpfStream(const std::string& fn, bool mmap=false);
5859
#else
@@ -61,6 +62,7 @@ namespace IfcParse {
6162
IfcSpfStream(std::istream& f, int len);
6263
IfcSpfStream(void* data, int len);
6364
~IfcSpfStream();
65+
IfcSpfStream(const std::string& data, unsigned int x);
6466
/// Returns the character at the cursor
6567
char Peek();
6668
/// Returns the character at specified offset

src/ifcwrap/IfcParseWrapper.i

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,21 @@ private:
377377

378378
// The IfcFile* returned by open() is to be freed by SWIG/Python
379379
%newobject open;
380+
//%newobject read;
380381

381382
%inline %{
382-
IfcParse::IfcFile* open(const std::string& s) {
383+
IfcParse::IfcFile* open(const std::string& fn) {
383384
IfcParse::IfcFile* f = new IfcParse::IfcFile();
384-
f->Init(s);
385+
f->Init(fn);
385386
return f;
386387
}
387-
388+
/*
389+
IfcParse::IfcFile* read(const std::string& fn) {
390+
IfcParse::IfcFile* f = new IfcParse::IfcFile();
391+
f->Dup(fn);
392+
return f;
393+
}
394+
*/
388395
const char* schema_identifier() {
389396
return IfcSchema::Identifier;
390397
}
@@ -410,4 +417,4 @@ private:
410417
IfcSchema::Type::PopulateDerivedFields(data);
411418
return IfcSchema::SchemaEntity(data);
412419
}
413-
%}
420+
%}

0 commit comments

Comments
 (0)