Files
IfcOpenShell/src/ifcparse/IfcBaseClass.h
T

90 lines
3.1 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 IFCBASECLASS_H
#define IFCBASECLASS_H
#include "ifc_parse_api.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4enum.h"
#else
#include "../ifcparse/Ifc2x3enum.h"
#endif
#include "../ifcparse/IfcEntityInstanceData.h"
2017-12-11 14:20:30 +01:00
#include "../ifcparse/IfcSchema.h"
2017-06-05 17:26:58 +02:00
class Argument;
namespace IfcUtil {
class IFC_PARSE_API IfcBaseClass {
protected:
2017-12-11 14:20:30 +01:00
IfcEntityInstanceData* data_;
2017-06-05 17:26:58 +02:00
public:
IfcBaseClass() : data_(0) {}
2017-12-11 14:20:30 +01:00
IfcBaseClass(IfcEntityInstanceData* d) : data_(d) {}
2017-12-11 14:47:30 +01:00
virtual ~IfcBaseClass() { delete data_; }
2017-12-11 14:20:30 +01:00
const IfcEntityInstanceData& data() const { return *data_; }
IfcEntityInstanceData& data() { return *data_; }
void data(IfcEntityInstanceData* d);
virtual const IfcParse::declaration& declaration() const = 0;
2017-06-05 17:26:58 +02:00
template <class T>
T* as() {
2017-12-11 14:47:30 +01:00
return declaration().is(T::Class())
2017-06-05 17:26:58 +02:00
? static_cast<T*>(this)
: static_cast<T*>(0);
}
template <class T>
const T* as() const {
2017-12-11 14:47:30 +01:00
return declaration().is(T::Class())
2017-06-05 17:26:58 +02:00
? static_cast<const T*>(this)
: static_cast<const T*>(0);
}
};
class IFC_PARSE_API IfcBaseEntity : public IfcBaseClass {
public:
IfcBaseEntity() : IfcBaseClass() {}
2017-12-11 14:20:30 +01:00
IfcBaseEntity(IfcEntityInstanceData* d) : IfcBaseClass(d) {}
virtual const IfcParse::entity& declaration() const = 0;
2017-12-11 14:47:30 +01:00
Argument* getArgumentByName(const std::string& name) const;
2017-06-05 17:26:58 +02:00
};
// TODO: Investigate whether these should be template classes instead
2017-12-11 14:20:30 +01:00
class IFC_PARSE_API IfcBaseType : public IfcBaseClass {
2017-06-05 17:26:58 +02:00
public:
IfcBaseType() : IfcBaseClass() {}
2017-12-11 14:20:30 +01:00
IfcBaseType(IfcEntityInstanceData* d) : IfcBaseClass(d) {}
virtual const IfcParse::type_declaration& declaration() const = 0;
2017-06-05 17:26:58 +02:00
};
}
#endif