MCPcopy Create free account
hub / github.com/assimp/assimp / ReadFileHeader

Method ReadFileHeader

code/AssetLib/STEPParser/STEPFileReader.cpp:84–137  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

82static constexpr char FILE_SCHEMA_Token[] = "FILE_SCHEMA";
83// ------------------------------------------------------------------------------------------------
84STEP::DB* STEP::ReadFileHeader(std::shared_ptr<IOStream> stream) {
85 std::shared_ptr<StreamReaderLE> reader = std::shared_ptr<StreamReaderLE>(new StreamReaderLE(std::move(stream)));
86 std::unique_ptr<STEP::DB> db = std::unique_ptr<STEP::DB>(new STEP::DB(reader));
87
88 LineSplitter &splitter = db->GetSplitter();
89 if (!splitter || *splitter != ISO_Token ) {
90 throw STEP::SyntaxError("expected magic token: " + std::string( ISO_Token ), 1);
91 }
92
93 HeaderInfo& head = db->GetHeader();
94 for(++splitter; splitter; ++splitter) {
95 const std::string& s = *splitter;
96 if (s == "DATA;") {
97 // here we go, header done, start of data section
98 ++splitter;
99 break;
100 }
101
102 // want one-based line numbers for human readers, so +1
103 const uint64_t line = splitter.get_index()+1;
104
105 if (s.substr(0,11) == FILE_SCHEMA_Token) {
106 const char* sz = s.c_str()+11;
107 const char *end = s.c_str() + s.size();
108 SkipSpaces(sz,&sz, end);
109 std::shared_ptr< const EXPRESS::DataType > schema = EXPRESS::DataType::Parse(sz, end);
110
111 // the file schema should be a regular list entity, although it usually contains exactly one entry
112 // since the list itself is contained in a regular parameter list, we actually have
113 // two nested lists.
114 const EXPRESS::LIST* list = dynamic_cast<const EXPRESS::LIST*>(schema.get());
115 if (list && list->GetSize()) {
116 list = dynamic_cast<const EXPRESS::LIST*>( (*list)[0].get() );
117 if (!list) {
118 throw STEP::SyntaxError("expected FILE_SCHEMA to be a list",line);
119 }
120
121 // XXX need support for multiple schemas?
122 if (list->GetSize() > 1) {
123 ASSIMP_LOG_WARN(AddLineNumber("multiple schemas currently not supported",line));
124 }
125 const EXPRESS::STRING *string = dynamic_cast<const EXPRESS::STRING *>((*list)[0].get());
126 if (!list->GetSize() || nullptr == string ) {
127 throw STEP::SyntaxError("expected FILE_SCHEMA to contain a single string literal",line);
128 }
129 head.fileSchema = *string;
130 }
131 }
132
133 // XXX handle more header fields
134 }
135
136 return db.release();
137}
138
139
140namespace {

Callers

nothing calls this directly

Calls 9

SyntaxErrorClass · 0.85
ParseFunction · 0.85
AddLineNumberFunction · 0.85
get_indexMethod · 0.80
SkipSpacesFunction · 0.50
sizeMethod · 0.45
getMethod · 0.45
GetSizeMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected