Files
IfcOpenShell/src/ifcparse/IfcEntityInstanceData.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.9 KiB
C++
Raw Normal View History

2017-06-05 17:26:58 +02:00
/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
#ifndef IFCENTITYINSTANCEDATA_H
#define IFCENTITYINSTANCEDATA_H
2023-09-17 12:30:17 +02:00
#include "ArgumentType.h"
2017-06-05 17:26:58 +02:00
#include <boost/optional.hpp>
2017-06-05 17:26:58 +02:00
#include <boost/shared_ptr.hpp>
class Argument;
2021-07-29 14:54:51 +02:00
class aggregate_of_instance;
2017-06-05 17:26:58 +02:00
namespace IfcParse {
2023-09-17 12:30:17 +02:00
class IfcFile;
2017-06-05 17:26:58 +02:00
}
class IFC_PARSE_API IfcEntityInstanceData {
2023-09-17 12:30:17 +02:00
public:
// Public for backwards compatibility
IfcParse::IfcFile* file;
protected:
unsigned id_;
const IfcParse::declaration* type_;
mutable Argument** attributes_;
unsigned offset_in_file_;
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
public:
2023-09-18 16:13:44 +02:00
IfcEntityInstanceData(const IfcParse::declaration* type,
IfcParse::IfcFile* file,
2023-09-18 16:13:44 +02:00
unsigned id = 0,
unsigned offset_in_file = 0)
: file(file),
2023-09-17 12:30:17 +02:00
id_(id),
type_(type),
attributes_(0),
offset_in_file_(offset_in_file) {}
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
IfcEntityInstanceData(IfcParse::IfcFile* file_, size_t size)
: file(file_),
id_(0),
type_(0),
attributes_(new Argument* [size] { 0 }),
offset_in_file_(0) {}
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
IfcEntityInstanceData(const IfcParse::declaration* type)
: file(0),
id_(0),
type_(type),
attributes_(new Argument* [getArgumentCount()] { 0 }),
offset_in_file_(0) {}
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
void load() const;
2017-06-24 21:35:38 +02:00
IfcEntityInstanceData(const IfcEntityInstanceData& data);
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
virtual ~IfcEntityInstanceData();
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
boost::shared_ptr<aggregate_of_instance> getInverse(const IfcParse::declaration* type, int attribute_index) const;
2017-06-05 17:26:58 +02:00
Argument* getArgument(size_t index) const;
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
// NB: This makes a copy of the argument if make_copy is set
void setArgument(size_t ibdex, Argument* argument, IfcUtil::ArgumentType attr_type = IfcUtil::Argument_UNKNOWN, bool make_copy = false);
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
virtual size_t getArgumentCount() const {
if (type_ == 0) {
return 0;
}
if (type_->as_entity() != nullptr) {
2023-09-17 12:30:17 +02:00
return type_->as_entity()->attribute_count();
}
return 1;
2023-09-17 12:30:17 +02:00
}
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
void clearArguments();
2022-04-28 10:33:54 +02:00
2023-09-17 12:30:17 +02:00
const IfcParse::declaration* type() const {
return type_;
}
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
std::string toString(bool upper = false) const;
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
unsigned int id() const { return id_; }
unsigned int offset_in_file() const { return offset_in_file_; }
2017-06-05 17:26:58 +02:00
2023-09-17 12:30:17 +02:00
// NB: const ommitted for lazy loading
Argument**& attributes() const { return attributes_; }
2017-06-05 17:26:58 +02:00
unsigned set_id(boost::optional<unsigned> id = boost::none);
2017-06-05 17:26:58 +02:00
};
#endif