2011-05-06 23:55:38 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (ASSIMP)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2010, ASSIMP Development Team
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the ASSIMP team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the ASSIMP Development Team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file STEPFileReader.cpp
|
|
|
|
* @brief Implementation of the STEP file parser, which fills a
|
|
|
|
* STEP::DB with data read from a file.
|
|
|
|
*/
|
|
|
|
#include "AssimpPCH.h"
|
|
|
|
#include "STEPFileReader.h"
|
|
|
|
#include "TinyFormatter.h"
|
|
|
|
#include "fast_atof.h"
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
namespace EXPRESS = STEP::EXPRESS;
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// From http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
|
|
|
|
|
|
|
|
// trim from start
|
|
|
|
static inline std::string <rim(std::string &s) {
|
|
|
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1( std::ptr_fun(Assimp::IsSpace<char>))));
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// trim from end
|
|
|
|
static inline std::string &rtrim(std::string &s) {
|
2011-05-08 00:17:16 +00:00
|
|
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1( std::ptr_fun(Assimp::IsSpace<char>))).base(),s.end());
|
2011-05-06 23:55:38 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
// trim from both ends
|
|
|
|
static inline std::string &trim(std::string &s) {
|
|
|
|
return ltrim(rtrim(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
std::string AddLineNumber(const std::string& s,uint64_t line /*= LINE_NOT_SPECIFIED*/, const std::string& prefix = "")
|
|
|
|
{
|
|
|
|
return line == STEP::SyntaxError::LINE_NOT_SPECIFIED ? prefix+s : static_cast<std::string>( (Formatter::format(),prefix,"(line ",line,") ",s) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
std::string AddEntityID(const std::string& s,uint64_t entity /*= ENTITY_NOT_SPECIFIED*/, const std::string& prefix = "")
|
|
|
|
{
|
|
|
|
return entity == STEP::TypeError::ENTITY_NOT_SPECIFIED ? prefix+s : static_cast<std::string>( (Formatter::format(),prefix,"(entity #",entity,") ",s));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
STEP::SyntaxError::SyntaxError (const std::string& s,uint64_t line /* = LINE_NOT_SPECIFIED */)
|
|
|
|
: DeadlyImportError(AddLineNumber(s,line))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
STEP::TypeError::TypeError (const std::string& s,uint64_t entity /* = ENTITY_NOT_SPECIFIED */,uint64_t line /*= LINE_NOT_SPECIFIED*/)
|
|
|
|
: DeadlyImportError(AddLineNumber(AddEntityID(s,entity),line))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
STEP::DB* STEP::ReadFileHeader(boost::shared_ptr<IOStream> stream)
|
|
|
|
{
|
|
|
|
boost::shared_ptr<StreamReaderLE> reader = boost::shared_ptr<StreamReaderLE>(new StreamReaderLE(stream));
|
|
|
|
std::auto_ptr<STEP::DB> db = std::auto_ptr<STEP::DB>(new STEP::DB(reader));
|
|
|
|
|
|
|
|
LineSplitter& splitter = db->GetSplitter();
|
|
|
|
if (!splitter || *splitter != "ISO-10303-21;") {
|
|
|
|
throw STEP::SyntaxError("expected magic token: ISO-10303-21",1);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeaderInfo& head = db->GetHeader();
|
|
|
|
for(++splitter; splitter; ++splitter) {
|
|
|
|
const std::string& s = *splitter;
|
|
|
|
if (s == "DATA;") {
|
|
|
|
// here we go, header done, start of data section
|
|
|
|
++splitter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// want one-based line numbers for human readers, so +1
|
|
|
|
const uint64_t line = splitter.get_index()+1;
|
|
|
|
|
|
|
|
if (s.substr(0,11) == "FILE_SCHEMA") {
|
|
|
|
const char* sz = s.c_str()+11;
|
|
|
|
SkipSpaces(sz,&sz);
|
2011-05-31 17:37:17 +00:00
|
|
|
boost::shared_ptr< const EXPRESS::DataType > schema = EXPRESS::DataType::Parse(sz);
|
2011-05-06 23:55:38 +00:00
|
|
|
|
|
|
|
// the file schema should be a regular list entity, although it usually contains exactly one entry
|
|
|
|
// since the list itself is contained in a regular parameter list, we actually have
|
|
|
|
// two nested lists.
|
|
|
|
const EXPRESS::LIST* list = dynamic_cast<const EXPRESS::LIST*>(schema.get());
|
|
|
|
if (list && list->GetSize()) {
|
2011-05-31 14:23:43 +00:00
|
|
|
list = dynamic_cast<const EXPRESS::LIST*>( (*list)[0].get() );
|
2011-05-06 23:55:38 +00:00
|
|
|
if (!list) {
|
|
|
|
throw STEP::SyntaxError("expected FILE_SCHEMA to be a list",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX need support for multiple schemas?
|
|
|
|
if (list->GetSize() > 1) {
|
|
|
|
DefaultLogger::get()->warn(AddLineNumber("multiple schemas currently not supported",line));
|
|
|
|
}
|
|
|
|
const EXPRESS::STRING* string;
|
2011-05-31 14:23:43 +00:00
|
|
|
if (!list->GetSize() || !(string=dynamic_cast<const EXPRESS::STRING*>( (*list)[0].get() ))) {
|
2011-05-06 23:55:38 +00:00
|
|
|
throw STEP::SyntaxError("expected FILE_SCHEMA to contain a single string literal",line);
|
|
|
|
}
|
|
|
|
head.fileSchema = *string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX handle more header fields
|
|
|
|
}
|
|
|
|
|
|
|
|
return db.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2011-05-30 15:38:48 +00:00
|
|
|
void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
|
|
|
|
const char* const* types_to_track, size_t len,
|
|
|
|
const char* const* inverse_indices_to_track, size_t len2)
|
2011-05-06 23:55:38 +00:00
|
|
|
{
|
|
|
|
db.SetSchema(scheme);
|
2011-05-30 15:38:48 +00:00
|
|
|
db.SetTypesToTrack(types_to_track,len);
|
|
|
|
db.SetInverseIndicesToTrack(inverse_indices_to_track,len2);
|
2011-05-06 23:55:38 +00:00
|
|
|
|
|
|
|
const DB::ObjectMap& map = db.GetObjects();
|
|
|
|
LineSplitter& splitter = db.GetSplitter();
|
|
|
|
for(; splitter; ++splitter) {
|
|
|
|
const std::string& s = *splitter;
|
|
|
|
if (s == "ENDSEC;") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// want one-based line numbers for human readers, so +1
|
|
|
|
const uint64_t line = splitter.get_index()+1;
|
|
|
|
|
|
|
|
// LineSplitter already ignores empty lines
|
|
|
|
ai_assert(s.length());
|
|
|
|
if (s[0] != '#') {
|
|
|
|
DefaultLogger::get()->warn(AddLineNumber("expected token \'#\'",line));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
// extract id, entity class name and argument string,
|
|
|
|
// but don't create the actual object yet.
|
|
|
|
// ---
|
|
|
|
|
|
|
|
const std::string::size_type n0 = s.find_first_of('=');
|
|
|
|
if (n0 == std::string::npos) {
|
|
|
|
DefaultLogger::get()->warn(AddLineNumber("expected token \'=\'",line));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t id = strtoul10_64(s.substr(1,n0-1).c_str());
|
|
|
|
if (!id) {
|
|
|
|
DefaultLogger::get()->warn(AddLineNumber("expected positive, numeric entity id",line));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string::size_type n1 = s.find_first_of('(',n0);
|
|
|
|
if (n1 == std::string::npos) {
|
|
|
|
DefaultLogger::get()->warn(AddLineNumber("expected token \'(\'",line));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string::size_type n2 = s.find_last_of(')');
|
|
|
|
if (n2 == std::string::npos || n2 < n1) {
|
|
|
|
DefaultLogger::get()->warn(AddLineNumber("expected token \')\'",line));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map.find(id) != map.end()) {
|
|
|
|
DefaultLogger::get()->warn(AddLineNumber((Formatter::format(),"an object with the id #",id," already exists"),line));
|
|
|
|
}
|
|
|
|
|
2011-05-30 20:17:57 +00:00
|
|
|
std::string::size_type ns = n0;
|
|
|
|
do ++ns; while( IsSpace(s.at(ns)));
|
|
|
|
|
|
|
|
std::string::size_type ne = n1;
|
|
|
|
do --ne; while( IsSpace(s.at(ne)));
|
|
|
|
|
|
|
|
std::string type = s.substr(ns,ne-ns+1);
|
2011-05-06 23:55:38 +00:00
|
|
|
std::transform( type.begin(), type.end(), type.begin(), &Assimp::ToLower<char> );
|
2011-05-30 20:17:57 +00:00
|
|
|
|
|
|
|
const char* sz = scheme.GetStaticStringForToken(type);
|
|
|
|
if(sz) {
|
|
|
|
|
|
|
|
const std::string::size_type len = n2-n1+1;
|
|
|
|
char* const copysz = new char[len+1];
|
|
|
|
std::copy(s.c_str()+n1,s.c_str()+n2+1,copysz);
|
|
|
|
copysz[len] = '\0';
|
|
|
|
|
|
|
|
db.InternInsert(new LazyObject(db,id,line,sz,copysz));
|
|
|
|
}
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!splitter) {
|
|
|
|
DefaultLogger::get()->warn("STEP: ignoring unexpected EOF");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !DefaultLogger::isNullLogger() ){
|
2011-05-30 15:38:48 +00:00
|
|
|
DefaultLogger::get()->debug((Formatter::format(),"STEP: got ",map.size()," object records with ",
|
|
|
|
db.GetRefs().size()," inverse index entries"));
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2011-05-31 17:37:17 +00:00
|
|
|
boost::shared_ptr<const EXPRESS::DataType> EXPRESS::DataType::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= NULL*/)
|
2011-05-06 23:55:38 +00:00
|
|
|
{
|
|
|
|
const char* cur = inout;
|
|
|
|
SkipSpaces(&cur);
|
|
|
|
|
|
|
|
if (*cur == ',' || IsSpaceOrNewLine(*cur)) {
|
|
|
|
throw STEP::SyntaxError("unexpected token, expected parameter",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// just skip over constructions such as IFCPLANEANGLEMEASURE(0.01) and read only the value
|
|
|
|
if (schema) {
|
|
|
|
bool ok = false;
|
|
|
|
for(const char* t = cur; *t && *t != ')' && *t != ','; ++t) {
|
|
|
|
if (*t=='(') {
|
|
|
|
if (!ok) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(--t;IsSpace(*t);--t);
|
|
|
|
std::string s(cur,static_cast<size_t>(t-cur+1));
|
|
|
|
std::transform(s.begin(),s.end(),s.begin(),&ToLower<char> );
|
|
|
|
if (schema->IsKnownToken(s)) {
|
|
|
|
for(cur = t+1;*cur++ != '(';);
|
2011-05-31 17:37:17 +00:00
|
|
|
const boost::shared_ptr<const EXPRESS::DataType> dt = Parse(cur);
|
2011-05-06 23:55:38 +00:00
|
|
|
inout = *cur ? cur+1 : cur;
|
|
|
|
return dt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!IsSpace(*t)) {
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cur == '*' ) {
|
|
|
|
inout = cur+1;
|
2011-05-31 17:37:17 +00:00
|
|
|
return boost::make_shared<EXPRESS::ISDERIVED>();
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '$' ) {
|
|
|
|
inout = cur+1;
|
2011-05-31 17:37:17 +00:00
|
|
|
return boost::make_shared<EXPRESS::UNSET>();
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '(' ) {
|
|
|
|
// start of an aggregate, further parsing is done by the LIST factory constructor
|
|
|
|
inout = cur;
|
|
|
|
return EXPRESS::LIST::Parse(inout,line,schema);
|
|
|
|
}
|
|
|
|
else if (*cur == '.' ) {
|
|
|
|
// enum (includes boolean)
|
|
|
|
const char* start = ++cur;
|
|
|
|
for(;*cur != '.';++cur) {
|
|
|
|
if (*cur == '\0') {
|
|
|
|
throw STEP::SyntaxError("enum not closed",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inout = cur+1;
|
2011-05-31 17:37:17 +00:00
|
|
|
return boost::make_shared<EXPRESS::ENUMERATION>(std::string(start, static_cast<size_t>(cur-start) ));
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '#' ) {
|
|
|
|
// object reference
|
2011-05-31 17:37:17 +00:00
|
|
|
return boost::make_shared<EXPRESS::ENTITY>(strtoul10_64(++cur,&inout));
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '\'' ) {
|
|
|
|
// string literal
|
|
|
|
const char* start = ++cur;
|
|
|
|
for(;*cur != '\'';++cur) {
|
|
|
|
if (*cur == '\0') {
|
|
|
|
throw STEP::SyntaxError("string literal not closed",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cur[1]=='\'') {
|
|
|
|
for(cur+=2;*cur != '\'';++cur) {
|
|
|
|
if (*cur == '\0') {
|
|
|
|
throw STEP::SyntaxError("string literal not closed",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inout = cur+1;
|
2011-05-31 17:37:17 +00:00
|
|
|
return boost::make_shared<EXPRESS::STRING>(std::string(start, static_cast<size_t>(cur-start) ));
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
else if (*cur == '\"' ) {
|
|
|
|
throw STEP::SyntaxError("binary data not supported yet",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// else -- must be a number. if there is a decimal dot in it,
|
|
|
|
// parse it as real value, otherwise as integer.
|
|
|
|
const char* start = cur;
|
|
|
|
for(;*cur && *cur != ',' && *cur != ')' && !IsSpace(*cur);++cur) {
|
|
|
|
if (*cur == '.') {
|
|
|
|
// XXX many STEP files contain extremely accurate data, float's precision may not suffice in many cases
|
|
|
|
float f;
|
|
|
|
inout = fast_atof_move(start,f);
|
2011-05-31 17:37:17 +00:00
|
|
|
return boost::make_shared<EXPRESS::REAL>(f);
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool neg = false;
|
|
|
|
if (*start == '-') {
|
|
|
|
neg = true;
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
else if (*start == '+') {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
int64_t num = static_cast<int64_t>( strtoul10_64(start,&inout) );
|
2011-05-31 17:37:17 +00:00
|
|
|
return boost::make_shared<EXPRESS::INTEGER>(neg?-num:num);
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2011-05-31 17:37:17 +00:00
|
|
|
boost::shared_ptr<const EXPRESS::LIST> EXPRESS::LIST::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= NULL*/)
|
2011-05-06 23:55:38 +00:00
|
|
|
{
|
2011-05-31 17:37:17 +00:00
|
|
|
const boost::shared_ptr<EXPRESS::LIST> list = boost::make_shared<EXPRESS::LIST>();
|
2011-05-06 23:55:38 +00:00
|
|
|
EXPRESS::LIST::MemberList& members = list->members;
|
|
|
|
|
|
|
|
const char* cur = inout;
|
|
|
|
if (*cur++ != '(') {
|
|
|
|
throw STEP::SyntaxError("unexpected token, expected \'(\' token at beginning of list",line);
|
|
|
|
}
|
|
|
|
|
|
|
|
// estimate the number of items upfront - lists can grow large
|
|
|
|
size_t count = 1;
|
|
|
|
for(const char* c=cur; *c && *c != ')'; ++c) {
|
|
|
|
count += (*c == ',' ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
members.reserve(count);
|
|
|
|
|
|
|
|
for(;;++cur) {
|
|
|
|
if (!*cur) {
|
|
|
|
throw STEP::SyntaxError("unexpected end of line while reading list");
|
|
|
|
}
|
|
|
|
SkipSpaces(cur,&cur);
|
|
|
|
if (*cur == ')') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-31 17:37:17 +00:00
|
|
|
members.push_back( EXPRESS::DataType::Parse(cur,line,schema));
|
2011-05-06 23:55:38 +00:00
|
|
|
SkipSpaces(cur,&cur);
|
|
|
|
|
|
|
|
if (*cur != ',') {
|
|
|
|
if (*cur == ')') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw STEP::SyntaxError("unexpected token, expected \',\' or \')\' token after list element",line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inout = cur+1;
|
2011-05-31 17:37:17 +00:00
|
|
|
return list;
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
|
2011-05-30 20:17:57 +00:00
|
|
|
|
2011-05-06 23:55:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2011-06-09 14:29:32 +00:00
|
|
|
STEP::LazyObject::LazyObject(DB& db, uint64_t id,uint64_t /*line*/, const char* const type,const char* args)
|
|
|
|
: id(id)
|
2011-05-06 23:55:38 +00:00
|
|
|
, type(type)
|
2011-06-09 14:29:32 +00:00
|
|
|
, db(db)
|
2011-05-30 20:17:57 +00:00
|
|
|
, args(args)
|
2011-06-09 14:29:32 +00:00
|
|
|
, obj()
|
2011-05-06 23:55:38 +00:00
|
|
|
{
|
|
|
|
// find any external references and store them in the database.
|
|
|
|
// this helps us emulate STEPs INVERSE fields.
|
2011-05-30 15:38:48 +00:00
|
|
|
if (db.KeepInverseIndicesForType(type)) {
|
2011-05-30 20:17:57 +00:00
|
|
|
const char* a = args;
|
|
|
|
|
|
|
|
// do a quick scan through the argument tuple and watch out for entity references
|
|
|
|
int64_t skip_depth = 0;
|
|
|
|
while(*a) {
|
|
|
|
if (*a == '(') {
|
|
|
|
++skip_depth;
|
|
|
|
}
|
|
|
|
else if (*a == ')') {
|
|
|
|
--skip_depth;
|
2011-05-30 15:38:48 +00:00
|
|
|
}
|
2011-05-30 20:17:57 +00:00
|
|
|
|
|
|
|
if (skip_depth == 1 && *a=='#') {
|
|
|
|
const char* tmp;
|
|
|
|
const int64_t num = static_cast<int64_t>( strtoul10_64(a+1,&tmp) );
|
|
|
|
db.MarkRef(num,id);
|
|
|
|
}
|
|
|
|
++a;
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
2011-05-30 20:17:57 +00:00
|
|
|
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
STEP::LazyObject::~LazyObject()
|
|
|
|
{
|
2011-05-30 20:17:57 +00:00
|
|
|
// make sure the right dtor/operator delete get called
|
|
|
|
if (obj) {
|
2011-05-30 21:04:11 +00:00
|
|
|
delete obj;
|
2011-05-30 20:17:57 +00:00
|
|
|
}
|
|
|
|
else delete[] args;
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void STEP::LazyObject::LazyInit() const
|
|
|
|
{
|
|
|
|
const EXPRESS::ConversionSchema& schema = db.GetSchema();
|
|
|
|
STEP::ConvertObjectProc proc = schema.GetConverterProc(type);
|
|
|
|
|
|
|
|
if (!proc) {
|
2011-05-30 20:17:57 +00:00
|
|
|
throw STEP::TypeError("unknown object type: " + std::string(type),id);
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
|
2011-05-31 17:37:17 +00:00
|
|
|
const char* acopy = args;
|
|
|
|
boost::shared_ptr<const EXPRESS::LIST> conv_args = EXPRESS::LIST::Parse(acopy,STEP::SyntaxError::LINE_NOT_SPECIFIED,&db.GetSchema());
|
|
|
|
delete[] args;
|
|
|
|
args = NULL;
|
2011-05-30 20:17:57 +00:00
|
|
|
|
2011-05-06 23:55:38 +00:00
|
|
|
// if the converter fails, it should throw an exception, but it should never return NULL
|
|
|
|
try {
|
|
|
|
obj = proc(db,*conv_args);
|
|
|
|
}
|
|
|
|
catch(const TypeError& t) {
|
|
|
|
// augment line and entity information
|
2011-05-30 20:17:57 +00:00
|
|
|
throw TypeError(t.what(),id);
|
2011-05-06 23:55:38 +00:00
|
|
|
}
|
|
|
|
++db.evaluated_count;
|
|
|
|
ai_assert(obj);
|
|
|
|
|
|
|
|
// store the original id in the object instance
|
|
|
|
obj->SetID(id);
|
|
|
|
}
|
2011-05-30 20:17:57 +00:00
|
|
|
|