Skip to content

Commit

Permalink
Merge pull request #1271 from ThatOpen/NewFunc
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
beachtom authored Feb 17, 2025
2 parents 9c8b6d7 + 6e8aad8 commit 5d76600
Show file tree
Hide file tree
Showing 6 changed files with 15,349 additions and 10 deletions.
47 changes: 46 additions & 1 deletion src/cpp/web-ifc/parsing/IfcLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace webifc::parsing {
void p21encode(std::string_view input, std::ostringstream &output);
std::string p21decode(std::string_view & str);

IfcLoader::IfcLoader(uint32_t tapeSize, uint32_t memoryLimit,uint32_t lineWriterBuffer, const schema::IfcSchemaManager &schemaManager) :_lineWriterBuffer(lineWriterBuffer), _schemaManager(schemaManager)
IfcLoader::IfcLoader(uint32_t tapeSize, uint64_t memoryLimit,uint32_t lineWriterBuffer, const schema::IfcSchemaManager &schemaManager) :_lineWriterBuffer(lineWriterBuffer), _schemaManager(schemaManager)
{
_tokenStream = new IfcTokenStream(tapeSize,memoryLimit/tapeSize);
_maxExpressId=0;
Expand Down Expand Up @@ -642,6 +642,51 @@ namespace webifc::parsing {
}
}
}

uint32_t IfcLoader::GetNoLineArguments() const
{
uint32_t noArguments = 0;
uint32_t setDepth = 0;
while (true)
{
if (setDepth == 1) noArguments++;

IfcTokenType t = static_cast<IfcTokenType>(_tokenStream->Read<char>());

switch (t)
{
case IfcTokenType::LINE_END: return noArguments;
case IfcTokenType::UNKNOWN:
case IfcTokenType::EMPTY:
break;
case IfcTokenType::SET_BEGIN:
setDepth++;
break;
case IfcTokenType::SET_END:
setDepth--;
if (setDepth == 0) return noArguments;
break;
case IfcTokenType::STRING:
case IfcTokenType::ENUM:
case IfcTokenType::LABEL:
case IfcTokenType::INTEGER:
case IfcTokenType::REAL:
{
uint16_t length = _tokenStream->Read<uint16_t>();
_tokenStream->Forward(length);
break;
}
case IfcTokenType::REF:
{
_tokenStream->Read<uint32_t>();
break;
}
default:
break;
}
}
return noArguments;
}

void IfcLoader::MoveToArgumentOffset(const uint32_t expressID, const uint32_t argumentIndex) const
{
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/web-ifc/parsing/IfcLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace webifc::parsing
class IfcLoader {

public:
IfcLoader(uint32_t tapeSize, uint32_t memoryLimit,uint32_t lineWriterBuffer, const schema::IfcSchemaManager &schemaManager);
IfcLoader(uint32_t tapeSize, uint64_t memoryLimit,uint32_t lineWriterBuffer, const schema::IfcSchemaManager &schemaManager);
~IfcLoader();
const std::vector<uint32_t> GetHeaderLinesWithType(const uint32_t type) const;
void LoadFile(const std::function<uint32_t(char *, size_t, size_t)> &requestData);
Expand Down Expand Up @@ -51,6 +51,7 @@ namespace webifc::parsing
std::vector<uint32_t> GetAllLines() const;
const std::vector<std::vector<uint32_t>> GetSetListArgument() const;
void MoveToArgumentOffset(const uint32_t expressID, const uint32_t argumentIndex) const;
uint32_t GetNoLineArguments() const;
void StepBack() const;
IFC_SCHEMA GetSchema() const;
void Push(void *v, const uint64_t size);
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/web-ifc/parsing/IfcTokenStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace webifc::parsing
{

IfcTokenStream::IfcTokenStream(const size_t chunkSize, const size_t maxChunks)
IfcTokenStream::IfcTokenStream(const size_t chunkSize, const uint64_t maxChunks)
: _chunkSize(chunkSize), _maxChunks(maxChunks)
{
_cChunk=nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/web-ifc/parsing/IfcTokenStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace webifc::parsing
class IfcTokenStream
{
public:
IfcTokenStream(const size_t chunkSize, const size_t maxChunks);
IfcTokenStream(const size_t chunkSize, const uint64_t maxChunks);
~IfcTokenStream();
void SetTokenSource(const std::function<uint32_t(char *, size_t, size_t)> &requestData);
void SetTokenSource(std::istream &requestData);
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace webifc::parsing
size_t _currentChunk = 0;
size_t _activeChunks = 0;
size_t _chunkSize;
size_t _maxChunks;
uint64_t _maxChunks;
class IfcFileStream
{
public:
Expand Down
15,265 changes: 15,265 additions & 0 deletions src/cpp/web-ifc/schema/schema-names.h

Large diffs are not rendered by default.

38 changes: 33 additions & 5 deletions src/schema-generator/gen_functional_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ console.log("Starting...");

let tsSchema: Array<string> = [];
let cppSchema: Array<string> = [];
let cppPropertyNames: Array<string> = [];
let cppPropertyNamesList: Array<String> = [];
let chSchema: Array<string> = [];

let completeifcElementList = new Set<string>();
Expand All @@ -22,6 +24,8 @@ completeEntityList.add("FILE_DESCRIPTION");

let typeList = new Set<string>();

cppPropertyNames.push("std::string getPropertyName(IFC_SCHEMA schema,uint32_t typeCode,uint32_t prop) {")

tsSchema.push('/**');
tsSchema.push(' * Web-IFC IFC Schema Representation');
tsSchema.push(' * @module ifc-schema');
Expand Down Expand Up @@ -97,7 +101,6 @@ for (var i = 0; i < files.length; i++) {
let entities: Array<Entity> = sortEntities(parsed.entities);
let types = parsed.types;


entities.forEach((e) => {
walkParents(e,entities);
});
Expand Down Expand Up @@ -254,14 +257,26 @@ for (var i = 0; i < files.length; i++) {

for (var x=0; x < entities.length; x++) generateClass(entities[x], tsSchema,types,crcTable);
tsSchema.push("}");

for (var x=0; x < entities.length; x++) {
let crcCode = crc32(entities[x].name.toUpperCase(),crcTable);
for (let i=0; i < entities[x].derivedProps.length;i++) {
let idex = cppPropertyNamesList.indexOf(entities[x].derivedProps[i].name);
if (idex == -1 ) {
idex=cppPropertyNamesList.length;
cppPropertyNamesList.push(entities[x].derivedProps[i] .name);
}
cppPropertyNames.push("if (schema == "+schemaNameClean+" && prop=="+i+" && typeCode=="+crcCode+") return propyNames["+idex+"];");

}
}

}

// now write out the global c++/ts metadata. All the WASM needs to know about is a list of all entities

console.log(`Writing Global WASM/TS Metadata!...`);



chSchema.push("#pragma once");
chSchema.push("// unique list of crc32 codes for ifc classes - this is a generated file - please see schema generator in src/schema");
chSchema.push("");
Expand Down Expand Up @@ -307,8 +322,21 @@ cppSchema.push("}");
cppSchema.push("}");
cppSchema.push("}");

fs.writeFileSync("../cpp/schema/ifc-schema.h", chSchema.join("\n"));
fs.writeFileSync("../cpp/schema/schema-functions.cpp", cppSchema.join("\n"));
let nameList ="std::array<std::string,"+cppPropertyNamesList.length+"> propyNames = {";
for (let x=0; x < cppPropertyNamesList.length; x++) {
nameList+="\""+cppPropertyNamesList[x]+"\"";
if (x!+cppPropertyNamesList.length-1) nameList+=",";
}
nameList+="};";
cppPropertyNames.unshift(nameList);
cppPropertyNames.push("}")




fs.writeFileSync("../cpp/web-ifc/schema/ifc-schema.h", chSchema.join("\n"));
fs.writeFileSync("../cpp/web-ifc/schema/schema-functions.cpp", cppSchema.join("\n"));
fs.writeFileSync("../cpp/web-ifc/schema/schema-names.h", cppPropertyNames.join("\n"));
fs.writeFileSync("../ts/ifc-schema.ts", tsSchema.join("\n"));

console.log(`...Done!`);

0 comments on commit 5d76600

Please sign in to comment.