/********************************************************************************
* *
* 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 IFCENTITYLIST_H
#define IFCENTITYLIST_H
// #include "IfcBaseClass.h"
#include "ifc_parse_api.h"
#include
#include
#include
#include
namespace IfcParse {
class declaration;
}
namespace IfcUtil {
class IfcBaseClass;
}
template
class aggregate_of;
class IFC_PARSE_API aggregate_of_instance {
std::vector list_;
public:
typedef boost::shared_ptr ptr;
typedef std::vector::const_iterator it;
void push(IfcUtil::IfcBaseClass* instance);
void push(const ptr& instance);
it begin();
it end();
IfcUtil::IfcBaseClass* operator[](int index);
size_t size() const;
void reserve(size_t capacity);
bool contains(IfcUtil::IfcBaseClass*) const;
template
typename U::list::ptr as();
void remove(IfcUtil::IfcBaseClass*);
aggregate_of_instance::ptr filtered(const std::set& entities);
aggregate_of_instance::ptr unique();
};
template
class aggregate_of {
std::vector list_;
public:
typedef boost::shared_ptr> ptr;
typedef typename std::vector::const_iterator it;
void push(T* type) {
if (type) {
list_.push_back(type);
}
}
void push(ptr instance) {
if (instance) {
for (typename T::list::it it = instance->begin(); it != instance->end(); ++it) {
push(*it);
}
}
}
it begin() { return list_.begin(); }
it end() { return list_.end(); }
size_t size() const { return list_.size(); }
aggregate_of_instance::ptr generalize() {
aggregate_of_instance::ptr result(new aggregate_of_instance());
for (it i = begin(); i != end(); ++i) {
result->push((*i)->template as());
}
return result;
}
bool contains(T* type) const { return std::find(list_.begin(), list_.end(), type) != list_.end(); }
template
typename U::list::ptr as() {
typename U::list::ptr result(new typename U::list);
for (it i = begin(); i != end(); ++i) {
if ((*i)->template as()) {
result->push((*i)->template as());
}
}
return result;
}
void remove(T* type) {
typename std::vector::iterator iter;
while ((iter = std::find(list_.begin(), list_.end(), type)) != list_.end()) {
list_.erase(iter);
}
}
};
template
class aggregate_of_aggregate_of;
class IFC_PARSE_API aggregate_of_aggregate_of_instance {
std::vector> list_;
public:
typedef boost::shared_ptr ptr;
typedef std::vector>::const_iterator outer_it;
typedef std::vector::const_iterator inner_it;
void push(const std::vector& instance) {
list_.push_back(instance);
}
void push(const aggregate_of_instance::ptr& instance) {
if (instance) {
std::vector list;
for (std::vector::const_iterator iter = instance->begin(); iter != instance->end(); ++iter) {
list.push_back(*iter);
}
push(list);
}
}
outer_it begin() const { return list_.begin(); }
outer_it end() const { return list_.end(); }
int size() const { return (int)list_.size(); }
int totalSize() const {
int accum = 0;
for (outer_it it = begin(); it != end(); ++it) {
accum += (int)it->size();
}
return accum;
}
bool contains(IfcUtil::IfcBaseClass* instance) const {
for (outer_it it = begin(); it != end(); ++it) {
const std::vector& inner = *it;
if (std::find(inner.begin(), inner.end(), instance) != inner.end()) {
return true;
}
}
return false;
}
template
typename aggregate_of_aggregate_of::ptr as();
};
template
class aggregate_of_aggregate_of {
std::vector> list_;
public:
typedef typename boost::shared_ptr> ptr;
typedef typename std::vector>::const_iterator outer_it;
typedef typename std::vector::const_iterator inner_it;
void push(const std::vector& type) { list_.push_back(type); }
outer_it begin() { return list_.begin(); }
outer_it end() { return list_.end(); }
int size() const { return (int)list_.size(); }
int totalSize() const {
int accum = 0;
for (outer_it it = begin(); it != end(); ++it) {
accum += it->size();
}
return accum;
}
bool contains(T* type) const {
for (outer_it iter = begin(); iter != end(); ++iter) {
const std::vector& inner = *iter;
if (std::find(inner.begin(), inner.end(), type) != inner.end()) {
return true;
}
}
return false;
}
aggregate_of_aggregate_of_instance::ptr generalize() {
aggregate_of_aggregate_of_instance::ptr result(new aggregate_of_aggregate_of_instance());
for (outer_it outer = begin(); outer != end(); ++outer) {
const std::vector& from = *outer;
std::vector to;
for (inner_it inner = from.begin(); inner != from.end(); ++inner) {
to.push_back(*inner);
}
result->push(to);
}
return result;
}
};
#endif