|
@@ -363,8 +363,7 @@ namespace STEP {
|
|
* 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 )
|
|
@@ -379,30 +378,27 @@ namespace STEP {
|
|
|
|
|
|
typedef std::map<std::string,ConvertObjectProc> ConverterMap;
|
|
typedef std::map<std::string,ConvertObjectProc> ConverterMap;
|
|
|
|
|
|
- public:
|
|
|
|
-
|
|
|
|
template <size_t N>
|
|
template <size_t N>
|
|
explicit ConversionSchema( const SchemaEntry (& schemas)[N]) {
|
|
explicit ConversionSchema( const SchemaEntry (& schemas)[N]) {
|
|
*this = schemas;
|
|
*this = schemas;
|
|
}
|
|
}
|
|
|
|
|
|
- ConversionSchema() {}
|
|
|
|
|
|
+ ConversionSchema() {
|
|
|
|
|
|
- public:
|
|
|
|
|
|
+ }
|
|
|
|
|
|
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);
|
|
- return it == converters.end() ? NULL : (*it).second;
|
|
|
|
|
|
+ return it == converters.end() ? nullptr : (*it).second;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
bool IsKnownToken(const std::string& name) const {
|
|
bool IsKnownToken(const std::string& name) const {
|
|
return converters.find(name) != converters.end();
|
|
return converters.find(name) != converters.end();
|
|
}
|
|
}
|
|
|
|
|
|
const char* GetStaticStringForToken(const std::string& token) const {
|
|
const char* GetStaticStringForToken(const std::string& token) const {
|
|
ConverterMap::const_iterator it = converters.find(token);
|
|
ConverterMap::const_iterator it = converters.find(token);
|
|
- return it == converters.end() ? NULL : (*it).first.c_str();
|
|
|
|
|
|
+ return it == converters.end() ? nullptr : (*it).first.c_str();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -450,8 +446,6 @@ namespace STEP {
|
|
// empty
|
|
// empty
|
|
}
|
|
}
|
|
|
|
|
|
- public:
|
|
|
|
-
|
|
|
|
// utilities to simplify casting to concrete types
|
|
// utilities to simplify casting to concrete types
|
|
template <typename T>
|
|
template <typename T>
|
|
const T& To() const {
|
|
const T& To() const {
|
|
@@ -473,7 +467,6 @@ namespace STEP {
|
|
return dynamic_cast<T*>(this);
|
|
return dynamic_cast<T*>(this);
|
|
}
|
|
}
|
|
|
|
|
|
- public:
|
|
|
|
uint64_t GetID() const {
|
|
uint64_t GetID() const {
|
|
return id;
|
|
return id;
|
|
}
|
|
}
|
|
@@ -500,9 +493,11 @@ namespace STEP {
|
|
/** CRTP shared base class for use by concrete entity implementation classes */
|
|
/** CRTP shared base class for use by concrete entity implementation classes */
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
template <typename TDerived, size_t arg_count>
|
|
template <typename TDerived, size_t arg_count>
|
|
- struct ObjectHelper : virtual Object
|
|
|
|
- {
|
|
|
|
- ObjectHelper() : aux_is_derived(0) {}
|
|
|
|
|
|
+ struct ObjectHelper : virtual Object {
|
|
|
|
+ ObjectHelper()
|
|
|
|
+ : 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
|
|
@@ -531,10 +526,16 @@ namespace STEP {
|
|
/** Class template used to represent OPTIONAL data members in the converted schema */
|
|
/** Class template used to represent OPTIONAL data members in the converted schema */
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
template <typename T>
|
|
template <typename T>
|
|
- struct Maybe
|
|
|
|
- {
|
|
|
|
- Maybe() : have() {}
|
|
|
|
- explicit Maybe(const T& ptr) : ptr(ptr), have(true) {
|
|
|
|
|
|
+ struct Maybe {
|
|
|
|
+ Maybe()
|
|
|
|
+ : have() {
|
|
|
|
+ // empty
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ explicit Maybe(const T& ptr)
|
|
|
|
+ : ptr(ptr)
|
|
|
|
+ , have(true) {
|
|
|
|
+ // empty
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -571,7 +572,6 @@ namespace STEP {
|
|
}
|
|
}
|
|
|
|
|
|
private:
|
|
private:
|
|
-
|
|
|
|
template <typename T2> friend struct InternGenericConvert;
|
|
template <typename T2> friend struct InternGenericConvert;
|
|
|
|
|
|
operator T&() {
|
|
operator T&() {
|
|
@@ -586,16 +586,13 @@ namespace STEP {
|
|
/** 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;
|
|
- public:
|
|
|
|
|
|
|
|
|
|
+ public:
|
|
LazyObject(DB& db, uint64_t id, uint64_t line, const char* type,const char* args);
|
|
LazyObject(DB& db, uint64_t id, uint64_t line, const char* type,const char* args);
|
|
~LazyObject();
|
|
~LazyObject();
|
|
|
|
|
|
- public:
|
|
|
|
-
|
|
|
|
Object& operator * () {
|
|
Object& operator * () {
|
|
if (!obj) {
|
|
if (!obj) {
|
|
LazyInit();
|
|
LazyInit();
|
|
@@ -653,38 +650,37 @@ namespace STEP {
|
|
}
|
|
}
|
|
|
|
|
|
private:
|
|
private:
|
|
-
|
|
|
|
void LazyInit() const;
|
|
void LazyInit() const;
|
|
|
|
|
|
private:
|
|
private:
|
|
-
|
|
|
|
mutable uint64_t id;
|
|
mutable uint64_t id;
|
|
const char* const type;
|
|
const char* const type;
|
|
DB& db;
|
|
DB& db;
|
|
-
|
|
|
|
mutable const char* args;
|
|
mutable const char* args;
|
|
mutable Object* obj;
|
|
mutable Object* obj;
|
|
};
|
|
};
|
|
|
|
|
|
template <typename T>
|
|
template <typename T>
|
|
- inline bool operator==( std::shared_ptr<LazyObject> lo, T whatever ) {
|
|
|
|
|
|
+ inline
|
|
|
|
+ bool operator==( std::shared_ptr<LazyObject> lo, T whatever ) {
|
|
return *lo == whatever; // XXX use std::forward if we have 0x
|
|
return *lo == whatever; // XXX use std::forward if we have 0x
|
|
}
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
template <typename T>
|
|
- inline bool operator==( const std::pair<uint64_t, std::shared_ptr<LazyObject> >& lo, T whatever ) {
|
|
|
|
|
|
+ inline
|
|
|
|
+ bool operator==( const std::pair<uint64_t, std::shared_ptr<LazyObject> >& lo, T whatever ) {
|
|
return *(lo.second) == whatever; // XXX use std::forward if we have 0x
|
|
return *(lo.second) == whatever; // XXX use std::forward if we have 0x
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
/** Class template used to represent lazily evaluated object references in the converted schema */
|
|
/** Class template used to represent lazily evaluated object references in the converted schema */
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
template <typename T>
|
|
template <typename T>
|
|
- struct Lazy
|
|
|
|
- {
|
|
|
|
|
|
+ struct Lazy {
|
|
typedef Lazy Out;
|
|
typedef Lazy Out;
|
|
- Lazy(const LazyObject* obj = NULL) : obj(obj) {
|
|
|
|
|
|
+ Lazy(const LazyObject* obj = nullptr)
|
|
|
|
+ : obj(obj) {
|
|
|
|
+ // empty
|
|
}
|
|
}
|
|
|
|
|
|
operator const T*() const {
|
|
operator const T*() const {
|
|
@@ -710,19 +706,15 @@ namespace STEP {
|
|
/** Class template used to represent LIST and SET data members in the converted schema */
|
|
/** Class template used to represent LIST and SET data members in the converted schema */
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
template <typename T, uint64_t min_cnt, uint64_t max_cnt=0uL>
|
|
template <typename T, uint64_t min_cnt, uint64_t max_cnt=0uL>
|
|
- struct ListOf : public std::vector<typename T::Out>
|
|
|
|
- {
|
|
|
|
|
|
+ struct ListOf : public std::vector<typename T::Out> {
|
|
typedef typename T::Out OutScalar;
|
|
typedef typename T::Out OutScalar;
|
|
typedef ListOf Out;
|
|
typedef ListOf Out;
|
|
|
|
|
|
-
|
|
|
|
ListOf() {
|
|
ListOf() {
|
|
static_assert(min_cnt <= max_cnt || !max_cnt, "min_cnt <= max_cnt || !max_cnt");
|
|
static_assert(min_cnt <= max_cnt || !max_cnt, "min_cnt <= max_cnt || !max_cnt");
|
|
}
|
|
}
|
|
-
|
|
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
template <typename TOut>
|
|
template <typename TOut>
|
|
struct PickBaseType {
|
|
struct PickBaseType {
|
|
@@ -734,7 +726,8 @@ namespace STEP {
|
|
typedef EXPRESS::ENTITY Type;
|
|
typedef EXPRESS::ENTITY Type;
|
|
};
|
|
};
|
|
|
|
|
|
- template <> struct PickBaseType< std::shared_ptr< const EXPRESS::DataType > >;
|
|
|
|
|
|
+ template<>
|
|
|
|
+ struct PickBaseType< std::shared_ptr< const EXPRESS::DataType > >;
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
template <typename T>
|
|
template <typename T>
|
|
@@ -742,8 +735,7 @@ namespace STEP {
|
|
void operator()(T& out, const std::shared_ptr< const EXPRESS::DataType >& in, const STEP::DB& /*db*/) {
|
|
void operator()(T& out, const std::shared_ptr< const EXPRESS::DataType >& in, const STEP::DB& /*db*/) {
|
|
try{
|
|
try{
|
|
out = dynamic_cast< const typename PickBaseType<T>::Type& > ( *in );
|
|
out = dynamic_cast< const typename PickBaseType<T>::Type& > ( *in );
|
|
- }
|
|
|
|
- catch(std::bad_cast&) {
|
|
|
|
|
|
+ } catch(std::bad_cast&) {
|
|
throw TypeError("type error reading literal field");
|
|
throw TypeError("type error reading literal field");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -816,7 +808,6 @@ namespace STEP {
|
|
return InternGenericConvertList<T1,N1,N2>()(a,b,db);
|
|
return InternGenericConvertList<T1,N1,N2>()(a,b,db);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------
|
|
/** 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
|
|
@@ -833,7 +824,6 @@ namespace STEP {
|
|
friend class LazyObject;
|
|
friend class LazyObject;
|
|
|
|
|
|
public:
|
|
public:
|
|
-
|
|
|
|
// objects indexed by ID - this can grow pretty large (i.e some hundred million
|
|
// objects indexed by ID - this can grow pretty large (i.e some hundred million
|
|
// entries), so use raw pointers to avoid *any* overhead.
|
|
// entries), so use raw pointers to avoid *any* overhead.
|
|
typedef std::map<uint64_t,const LazyObject* > ObjectMap;
|
|
typedef std::map<uint64_t,const LazyObject* > ObjectMap;
|
|
@@ -858,19 +848,16 @@ namespace STEP {
|
|
: reader(reader)
|
|
: reader(reader)
|
|
, splitter(*reader,true,true)
|
|
, splitter(*reader,true,true)
|
|
, evaluated_count()
|
|
, evaluated_count()
|
|
- , schema( NULL )
|
|
|
|
|
|
+ , schema( nullptr )
|
|
{}
|
|
{}
|
|
|
|
|
|
public:
|
|
public:
|
|
-
|
|
|
|
~DB() {
|
|
~DB() {
|
|
for(ObjectMap::value_type& o : objects) {
|
|
for(ObjectMap::value_type& o : objects) {
|
|
delete o.second;
|
|
delete o.second;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public:
|
|
|
|
-
|
|
|
|
uint64_t GetObjectCount() const {
|
|
uint64_t GetObjectCount() const {
|
|
return objects.size();
|
|
return objects.size();
|
|
}
|
|
}
|
|
@@ -899,7 +886,6 @@ namespace STEP {
|
|
return refs;
|
|
return refs;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
bool KeepInverseIndicesForType(const char* const type) const {
|
|
bool KeepInverseIndicesForType(const char* const type) const {
|
|
return inv_whitelist.find(type) != inv_whitelist.end();
|
|
return inv_whitelist.find(type) != inv_whitelist.end();
|
|
}
|
|
}
|
|
@@ -911,7 +897,7 @@ namespace STEP {
|
|
if (it != objects.end()) {
|
|
if (it != objects.end()) {
|
|
return (*it).second;
|
|
return (*it).second;
|
|
}
|
|
}
|
|
- return NULL;
|
|
|
|
|
|
+ return nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|