/********************************************************************************
* *
* 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 . *
* *
********************************************************************************/
#ifndef IFCBASECLASS_H
#define IFCBASECLASS_H
#include "argument.h"
#include "ifc_parse_api.h"
#include "schema.h"
#include "utils.h"
#include
#include
class aggregate_of_instance;
namespace ifcopenshell {
class file;
namespace impl {
struct in_memory_file_storage;
}
} // namespace ifcopenshell
class instance_data;
class attribute_value;
namespace express {
class Base;
class Select;
class Entity;
class DeclaredType;
class IFC_PARSE_API Base {
protected:
std::weak_ptr data_;
const instance_data* data() const;
instance_data* data();
public:
operator bool() const {
return !data_.expired();
}
bool operator<(const Base& other) const {
return data() < other.data();
}
bool operator==(const Base& other) const {
return data() == other.data();
}
bool operator!=(const Base& other) const {
return !(*this == other);
}
Base() {};
Base(std::nullopt_t) noexcept : Base() {}
Base(const std::weak_ptr& data) : data_(data) {}
// @todo try and make this private over time too
const std::weak_ptr& data_weak() const { return data_; }
const ifcopenshell::declaration& declaration() const;
template
typename std::enable_if<
(!std::is_base_of_v || std::is_same_v),
void>::type
set_attribute_value(size_t attribute_index, const T& value);
template
typename std::enable_if<
(!std::is_base_of_v || std::is_same_v),
void>::type
set_attribute_value(const std::string& attribute_name, const T& value);
void set_attribute_value(size_t attribute_index, const express::Base& value);
void set_attribute_value(const std::string& attribute_name, const express::Base& value);
void unset_attribute_value(size_t attribute_index);
attribute_value get_attribute_value(size_t attribute_index) const;
uint32_t identity() const;
uint32_t id() const;
void to_string(std::ostream& stream, bool uppercase = false) const;
template
T as() const {
if constexpr (std::is_same_v) {
if (declaration().as_entity() != nullptr) {
return T(data_weak());
} else {
return T{};
}
} else if constexpr (std::is_same_v) {
if (declaration().as_entity() == nullptr) {
return T(data_weak());
} else {
return T{};
}
} else if constexpr (std::is_same_v