Merge pull request #4627 from assimp/kimkulling/remove_assert_from_parser_issue-4626

Remove assertion test
pull/4629/head
Kim Kulling 2022-07-08 10:11:44 +02:00 committed by GitHub
commit a1f9a299e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 94 deletions

View File

@ -2,8 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2022, assimp team
All rights reserved. All rights reserved.
@ -59,7 +58,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# pragma warning(disable : 4127 4456 4245 4512 ) # pragma warning(disable : 4127 4456 4245 4512 )
#endif // _MSC_VER #endif // _MSC_VER
//
#if _MSC_VER > 1500 || (defined __GNUC___) #if _MSC_VER > 1500 || (defined __GNUC___)
# define ASSIMP_STEP_USE_UNORDERED_MULTIMAP # define ASSIMP_STEP_USE_UNORDERED_MULTIMAP
#else #else
@ -99,13 +97,9 @@ namespace EXPRESS {
class DataType; class DataType;
class UNSET; /*: public DataType */ class UNSET; /*: public DataType */
class ISDERIVED; /*: public DataType */ class ISDERIVED; /*: public DataType */
// class REAL; /*: public DataType */
class ENUM; /*: public DataType */ class ENUM; /*: public DataType */
// class STRING; /*: public DataType */
// class INTEGER; /*: public DataType */
class ENTITY; /*: public DataType */ class ENTITY; /*: public DataType */
class LIST; /*: public DataType */ class LIST; /*: public DataType */
// class SELECT; /*: public DataType */
// a conversion schema is not exactly an EXPRESS schema, rather it // a conversion schema is not exactly an EXPRESS schema, rather it
// is a list of pointers to conversion functions to build up the // is a list of pointers to conversion functions to build up the
@ -127,7 +121,8 @@ namespace STEP {
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
/** Exception class used by the STEP loading & parsing code. It is typically /** Exception class used by the STEP loading & parsing code. It is typically
* coupled with a line number. */ * coupled with a line number.
*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
struct SyntaxError : DeadlyImportError { struct SyntaxError : DeadlyImportError {
enum : uint64_t { enum : uint64_t {
@ -139,8 +134,9 @@ struct SyntaxError : DeadlyImportError {
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
/** Exception class used by the STEP loading & parsing code when a type /** Exception class used by the STEP loading & parsing code when a type
* error (i.e. an entity expects a string but receives a bool) occurs. * error (i.e. an entity expects a string but receives a bool) occurs.
* It is typically coupled with both an entity id and a line number.*/ * It is typically coupled with both an entity id and a line number.
*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
struct TypeError : DeadlyImportError { struct TypeError : DeadlyImportError {
enum : uint64_t { enum : uint64_t {
@ -167,10 +163,8 @@ public:
typedef std::shared_ptr<const DataType> Out; typedef std::shared_ptr<const DataType> Out;
public: public:
virtual ~DataType() { virtual ~DataType() = default;
}
public:
template <typename T> template <typename T>
const T &To() const { const T &To() const {
return dynamic_cast<const T &>(*this); return dynamic_cast<const T &>(*this);
@ -206,16 +200,14 @@ public:
public: public:
/** parse a variable from a string and set 'inout' to the character /** parse a variable from a string and set 'inout' to the character
* behind the last consumed character. An optional schema enables, * behind the last consumed character. An optional schema enables,
* if specified, automatic conversion of custom data types. * if specified, automatic conversion of custom data types.
* *
* @throw SyntaxError * @throw SyntaxError
*/ */
static std::shared_ptr<const EXPRESS::DataType> Parse(const char *&inout, static std::shared_ptr<const EXPRESS::DataType> Parse(const char *&inout,
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED, uint64_t line = SyntaxError::LINE_NOT_SPECIFIED,
const EXPRESS::ConversionSchema *schema = NULL); const EXPRESS::ConversionSchema *schema = NULL);
public:
}; };
typedef DataType SELECT; typedef DataType SELECT;
@ -238,7 +230,8 @@ private:
}; };
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
/** Shared implementation for some of the primitive data type, i.e. int, float */ /** Shared implementation for some of the primitive data type, i.e. int, float
*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
template <typename T> template <typename T>
class PrimitiveDataType : public DataType { class PrimitiveDataType : public DataType {
@ -247,7 +240,7 @@ public:
// expose this data type to the user. // expose this data type to the user.
typedef T Out; typedef T Out;
PrimitiveDataType() {} PrimitiveDataType() = default;
PrimitiveDataType(const T &val) : PrimitiveDataType(const T &val) :
val(val) {} val(val) {}
@ -280,28 +273,18 @@ class ENUMERATION : public STRING {
public: public:
ENUMERATION(const std::string &val) : ENUMERATION(const std::string &val) :
STRING(val) {} STRING(val) {}
private:
}; };
typedef ENUMERATION BOOLEAN; typedef ENUMERATION BOOLEAN;
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
/** This is just a reference to an entity/object somewhere else */ /** This is just a reference to an entity/object somewhere else
*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
class ENTITY : public PrimitiveDataType<uint64_t> { class ENTITY : public PrimitiveDataType<uint64_t> {
public: public:
ENTITY(uint64_t val) : ENTITY(uint64_t val) : PrimitiveDataType<uint64_t>(val) {}
PrimitiveDataType<uint64_t>(val) { ENTITY() : PrimitiveDataType<uint64_t>(TypeError::ENTITY_NOT_SPECIFIED) {}
ai_assert(val != 0);
}
ENTITY() :
PrimitiveDataType<uint64_t>(TypeError::ENTITY_NOT_SPECIFIED) {
// empty
}
private:
}; };
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
@ -319,7 +302,8 @@ public:
} }
public: public:
/** @see DaraType::Parse */ /** @see DaraType::Parse
*/
static std::shared_ptr<const EXPRESS::LIST> Parse(const char *&inout, static std::shared_ptr<const EXPRESS::LIST> Parse(const char *&inout,
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED, uint64_t line = SyntaxError::LINE_NOT_SPECIFIED,
const EXPRESS::ConversionSchema *schema = NULL); const EXPRESS::ConversionSchema *schema = NULL);
@ -331,29 +315,20 @@ private:
class BINARY : public PrimitiveDataType<uint32_t> { class BINARY : public PrimitiveDataType<uint32_t> {
public: public:
BINARY(uint32_t val) : BINARY(uint32_t val) : PrimitiveDataType<uint32_t>(val) {}
PrimitiveDataType<uint32_t>(val) { BINARY() : PrimitiveDataType<uint32_t>(TypeError::ENTITY_NOT_SPECIFIED_32) {}
// empty
}
BINARY() :
PrimitiveDataType<uint32_t>(TypeError::ENTITY_NOT_SPECIFIED_32) {
// empty
}
}; };
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
/* Not exactly a full EXPRESS schema but rather a list of conversion functions /* Not exactly a full EXPRESS schema but rather a list of conversion functions
* to extract valid C++ objects out of a STEP file. Those conversion functions * to extract valid C++ objects out of a STEP file. Those conversion functions
* may, however, perform further schema validations. */ * may, however, perform further schema validations.
*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
class ConversionSchema { class ConversionSchema {
public: public:
struct SchemaEntry { struct SchemaEntry {
SchemaEntry(const char *name, ConvertObjectProc func) : SchemaEntry(const char *name, ConvertObjectProc func) : mName(name), mFunc(func) {}
mName(name), mFunc(func) {
// empty
}
const char *mName; const char *mName;
ConvertObjectProc mFunc; ConvertObjectProc mFunc;
@ -366,8 +341,7 @@ public:
*this = schemas; *this = schemas;
} }
ConversionSchema() { ConversionSchema() = default;
}
ConvertObjectProc GetConverterProc(const std::string &name) const { ConvertObjectProc GetConverterProc(const std::string &name) const {
ConverterMap::const_iterator it = converters.find(name); ConverterMap::const_iterator it = converters.find(name);
@ -399,8 +373,9 @@ private:
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** Bundle all the relevant info from a STEP header, parts of which may later /** Bundle all the relevant info from a STEP header, parts of which may later
* be plainly dumped to the logfile, whereas others may help the caller pick an * be plainly dumped to the logfile, whereas others may help the caller pick an
* appropriate loading strategy.*/ * appropriate loading strategy.
*/
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
struct HeaderInfo { struct HeaderInfo {
std::string timestamp; std::string timestamp;
@ -409,18 +384,14 @@ struct HeaderInfo {
}; };
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** Base class for all concrete object instances */ /** Base class for all concrete object instances
*/
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
class Object { class Object {
public: public:
Object(const char *classname = "unknown") : Object(const char *classname = "unknown") : id(0), classname(classname) {}
id(0), classname(classname) {
// empty
}
virtual ~Object() { virtual ~Object() = default;
// empty
}
// utilities to simplify casting to concrete types // utilities to simplify casting to concrete types
template <typename T> template <typename T>
@ -469,26 +440,15 @@ size_t GenericFill(const STEP::DB &db, const EXPRESS::LIST &params, T *in);
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
template <typename TDerived, size_t arg_count> template <typename TDerived, size_t arg_count>
struct ObjectHelper : virtual Object { struct ObjectHelper : virtual Object {
ObjectHelper() : ObjectHelper() : aux_is_derived(0) {}
aux_is_derived(0) {
// empty
}
static Object *Construct(const STEP::DB &db, const EXPRESS::LIST &params) { static Object *Construct(const STEP::DB &db, const EXPRESS::LIST &params) {
// make sure we don't leak if Fill() throws an exception // make sure we don't leak if Fill() throws an exception
std::unique_ptr<TDerived> impl(new TDerived()); std::unique_ptr<TDerived> impl(new TDerived());
// GenericFill<T> is undefined so we need to have a specialization // GenericFill<T> is undefined so we need to have a specialization
const size_t num_args = GenericFill<TDerived>(db, params, &*impl); static_cast<void>(GenericFill<TDerived>(db, params, &*impl));
(void)num_args;
// the following check is commented because it will always trigger if
// parts of the entities are generated with dummy wrapper code.
// This is currently done to reduce the size of the loader
// code.
//if (num_args != params.GetSize() && impl->GetClassName() != "NotImplemented") {
// DefaultLogger::get()->debug("STEP: not all parameters consumed");
//}
return impl.release(); return impl.release();
} }
@ -502,15 +462,9 @@ struct ObjectHelper : virtual Object {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
template <typename T> template <typename T>
struct Maybe { struct Maybe {
Maybe() : Maybe() : have() {}
have() {
// empty
}
explicit Maybe(const T &ptr) : explicit Maybe(const T &ptr) : ptr(ptr), have(true) {}
ptr(ptr), have(true) {
// empty
}
void flag_invalid() { void flag_invalid() {
have = false; have = false;
@ -557,7 +511,8 @@ private:
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** A LazyObject is created when needed. Before this happens, we just keep /** A LazyObject is created when needed. Before this happens, we just keep
the text line that contains the object definition. */ * the text line that contains the object definition.
*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
class LazyObject { class LazyObject {
friend class DB; friend class DB;
@ -649,10 +604,7 @@ inline bool operator==(const std::pair<uint64_t, std::shared_ptr<LazyObject>> &l
template <typename T> template <typename T>
struct Lazy { struct Lazy {
typedef Lazy Out; typedef Lazy Out;
Lazy(const LazyObject *obj = nullptr) : Lazy(const LazyObject *obj = nullptr) : obj(obj) {}
obj(obj) {
// empty
}
operator const T *() const { operator const T *() const {
return obj->ToPtr<T>(); return obj->ToPtr<T>();
@ -785,8 +737,9 @@ inline void GenericConvert(ListOf<T1, N1, N2> &a, const std::shared_ptr<const EX
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** Lightweight manager class that holds the map of all objects in a /** Lightweight manager class that holds the map of all objects in a
* STEP file. DB's are exclusively maintained by the functions in * STEP file. DB's are exclusively maintained by the functions in
* STEPFileReader.h*/ * STEPFileReader.h
*/
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
class DB { class DB {
friend DB *ReadFileHeader(std::shared_ptr<IOStream> stream); friend DB *ReadFileHeader(std::shared_ptr<IOStream> stream);
@ -873,7 +826,7 @@ public:
if (it != objects_bytype.end() && (*it).second.size()) { if (it != objects_bytype.end() && (*it).second.size()) {
return *(*it).second.begin(); return *(*it).second.begin();
} }
return NULL; return nullptr;
} }
// same, but raise an exception if the object doesn't exist and return a reference // same, but raise an exception if the object doesn't exist and return a reference
@ -965,7 +918,6 @@ private:
#endif // _MSC_VER #endif // _MSC_VER
} // namespace STEP } // namespace STEP
} // namespace Assimp } // namespace Assimp
#endif // INCLUDED_AI_STEPFILE_H #endif // INCLUDED_AI_STEPFILE_H