mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 11:24:19 +00:00
Use naked pointer for attribute list and derive size from schema type to reduce mem usage
This commit is contained in:
@@ -39,41 +39,27 @@ public:
|
||||
protected:
|
||||
unsigned id_;
|
||||
const IfcParse::declaration* type_;
|
||||
mutable std::vector<Argument*> attributes_;
|
||||
|
||||
// To reduce memory footprint, these two could potentially be combined,
|
||||
// e.g. initialized_ <-> offset_in_file_ == 0, but it would imply that
|
||||
// instances cannot be located at the beginning of the file. Officially
|
||||
// there should be a header anyways.
|
||||
mutable bool initialized_;
|
||||
mutable Argument** attributes_;
|
||||
unsigned offset_in_file_;
|
||||
|
||||
public:
|
||||
IfcEntityInstanceData(const IfcParse::declaration* type, IfcParse::IfcFile* file_, unsigned id = 0, unsigned offset_in_file = 0)
|
||||
: file(file_), id_(id), type_(type), initialized_(false), offset_in_file_(offset_in_file)
|
||||
: file(file_), id_(id), type_(type), attributes_(0), offset_in_file_(offset_in_file)
|
||||
{}
|
||||
|
||||
IfcEntityInstanceData(IfcParse::IfcFile* file_, size_t size)
|
||||
: file(file_), id_(0), type_(0), attributes_(new Argument*[size]), offset_in_file_(0)
|
||||
{}
|
||||
|
||||
IfcEntityInstanceData(const IfcParse::declaration* type)
|
||||
: file(0), id_(0), type_(type), initialized_(true)
|
||||
: file(0), id_(0), type_(type), attributes_(0)
|
||||
{}
|
||||
|
||||
/*
|
||||
IfcEntityInstanceData(IfcParse::IfcFile* file = 0, unsigned id = 0, IfcSchema::Type::Enum type = IfcSchema::Type::UNDEFINED, unsigned offset_in_file = 0, size_t n)
|
||||
: file_(file), id_(0), type_(type), initialized_(false)
|
||||
{
|
||||
attributes_.reserve(n);
|
||||
}
|
||||
|
||||
IfcEntityInstanceData(IfcParse::IfcFile* file = 0, unsigned id = 0, IfcSchema::Type::Enum type = IfcSchema::Type::UNDEFINED, const std::vector<Argument*>& attributes)
|
||||
: file_(file), id_(0), type_(type), attributes_(attributes), initialized_(true)
|
||||
{}
|
||||
*/
|
||||
|
||||
void load() const;
|
||||
|
||||
IfcEntityInstanceData(const IfcEntityInstanceData& e);
|
||||
|
||||
~IfcEntityInstanceData();
|
||||
virtual ~IfcEntityInstanceData();
|
||||
|
||||
boost::shared_ptr<IfcEntityList> getInverse(const IfcParse::declaration* type, int attribute_index);
|
||||
|
||||
@@ -82,11 +68,15 @@ public:
|
||||
// NB: This makes a copy of the argument
|
||||
void setArgument(unsigned int i, Argument* a, IfcUtil::ArgumentType attr_type = IfcUtil::Argument_UNKNOWN);
|
||||
|
||||
unsigned int getArgumentCount() const {
|
||||
if (!initialized_) {
|
||||
load();
|
||||
virtual unsigned int getArgumentCount() const {
|
||||
if (type_ == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (type_->as_entity()) {
|
||||
return type_->as_entity()->attribute_count();
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return (unsigned int)attributes_.size();
|
||||
}
|
||||
|
||||
const IfcParse::declaration* type() const {
|
||||
@@ -99,7 +89,7 @@ public:
|
||||
unsigned int offset_in_file() const { return offset_in_file_; }
|
||||
|
||||
// NB: const ommitted for lazy loading
|
||||
std::vector<Argument*>& attributes() const { return attributes_; }
|
||||
Argument**& attributes() const { return attributes_; }
|
||||
|
||||
unsigned set_id(boost::optional<unsigned> i = boost::none);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user