/******************************************************************************** * * * 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 IFCUTIL_H #define IFCUTIL_H #include #include #include #include "../ifcparse/SharedPointer.h" #ifdef USE_IFC4 #include "../ifcparse/Ifc4enum.h" #else #include "../ifcparse/Ifc2x3enum.h" #endif class IfcAbstractEntity; //typedef SHARED_PTR IfcAbstractEntityPtr; typedef IfcAbstractEntity* IfcAbstractEntityPtr; class IfcEntityList; typedef SHARED_PTR IfcEntities; class Argument; //typedef SHARED_PTR ArgumentPtr; typedef Argument* ArgumentPtr; template inline T* reinterpret_pointer_cast(F* from) { return (T*)from; //SHARED_PTR v = std::tr1::static_pointer_cast(from); //return std::tr1::static_pointer_cast(v); } namespace IfcUtil { enum ArgumentType { Argument_INT, Argument_BOOL, Argument_DOUBLE, Argument_STRING, Argument_VECTOR_INT, Argument_VECTOR_DOUBLE, Argument_VECTOR_STRING, Argument_ENTITY, Argument_ENTITY_LIST, Argument_ENTITY_LIST_LIST, Argument_ENUMERATION, Argument_DERIVED, Argument_UNKNOWN }; } namespace IfcUtil { class IfcBaseClass { public: IfcAbstractEntityPtr entity; virtual bool is(IfcSchema::Type::Enum v) const = 0; virtual IfcSchema::Type::Enum type() const = 0; }; class IfcBaseEntity : public IfcBaseClass { public: virtual unsigned int getArgumentCount() const = 0; virtual ArgumentType getArgumentType(unsigned int i) const = 0; virtual ArgumentPtr getArgument(unsigned int i) const = 0; virtual const char* getArgumentName(unsigned int i) const = 0; }; //typedef SHARED_PTR IfcSchemaEntity; typedef IfcBaseClass* IfcSchemaEntity; } template class IfcTemplatedEntityList; class IfcEntityList { std::vector ls; public: typedef std::vector::const_iterator it; IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL); IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a); void push(IfcUtil::IfcSchemaEntity l); void push(IfcEntities l); it begin(); it end(); IfcUtil::IfcSchemaEntity operator[] (int i); int Size() const; template typename U::list as() { typename U::list r(new IfcTemplatedEntityList()); for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push((U*)*i); return r; } }; template class IfcTemplatedEntityList { std::vector ls; public: typedef typename std::vector::const_iterator it; inline void push(T* t) {if (t) ls.push_back(t);} inline void push(SHARED_PTR< IfcTemplatedEntityList > t) { for ( typename T::it it = t->begin(); it != t->end(); ++it ) push(*it); } inline it begin() { return ls.begin(); } inline it end() { return ls.end(); } inline unsigned int Size() const { return (unsigned int) ls.size(); } IfcEntities generalize() { IfcEntities r (new IfcEntityList()); for ( it i = begin(); i != end(); ++ i ) r->push(*i); return r; } template typename U::list as() { typename U::list r(new IfcTemplatedEntityList()); for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push(*i); return r; } }; namespace IfcUtil { class IfcAbstractSelect : public IfcBaseClass { public: typedef SHARED_PTR< IfcTemplatedEntityList > list; typedef IfcTemplatedEntityList::it it; typedef IfcAbstractSelect* ptr; virtual bool isSimpleType() = 0; }; class IfcEntitySelect : public IfcAbstractSelect { public: typedef IfcEntitySelect* ptr; IfcEntitySelect(IfcSchemaEntity b); IfcEntitySelect(IfcAbstractEntityPtr e); ~IfcEntitySelect(); bool is(IfcSchema::Type::Enum v) const; IfcSchema::Type::Enum type() const; bool isSimpleType(); }; class IfcArgumentSelect : public IfcAbstractSelect { IfcSchema::Type::Enum _type; ArgumentPtr arg; public: typedef IfcArgumentSelect* ptr; IfcArgumentSelect(IfcSchema::Type::Enum t, ArgumentPtr a); ~IfcArgumentSelect(); ArgumentPtr wrappedValue(); bool is(IfcSchema::Type::Enum v) const; IfcSchema::Type::Enum type() const; bool isSimpleType(); }; } namespace IfcParse { class IfcFile; } class Argument { public: //void* file; //public: virtual operator int() const = 0; virtual operator bool() const = 0; virtual operator double() const = 0; virtual operator std::string() const = 0; virtual operator std::vector() const = 0; virtual operator std::vector() const = 0; virtual operator std::vector() const = 0; virtual operator IfcUtil::IfcSchemaEntity() const = 0; //virtual operator IfcUtil::IfcAbstractSelect::ptr() const = 0; virtual operator IfcEntities() const = 0; virtual unsigned int Size() const = 0; virtual ArgumentPtr operator [] (unsigned int i) const = 0; virtual std::string toString(bool upper=false) const = 0; virtual bool isNull() const = 0; virtual ~Argument() {}; }; class IfcAbstractEntity { public: IfcParse::IfcFile* file; virtual IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL) = 0; virtual IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) = 0; virtual std::string datatype() = 0; virtual ArgumentPtr getArgument (unsigned int i) = 0; virtual unsigned int getArgumentCount() = 0; virtual ~IfcAbstractEntity() {}; virtual IfcSchema::Type::Enum type() const = 0; virtual bool is(IfcSchema::Type::Enum v) const = 0; virtual std::string toString(bool upper=false) = 0; virtual unsigned int id() = 0; virtual bool isWritable() = 0; }; class Logger { public: typedef enum { LOG_NOTICE, LOG_WARNING, LOG_ERROR } Severity; private: static std::ostream* log1; static std::ostream* log2; static std::stringstream log_stream; static Severity verbosity; static const char* severity_strings[]; public: /// Determines to what stream respectively progress and errors are logged static void SetOutput(std::ostream* l1, std::ostream* l2); /// Determines the types of log messages to get logged static void Verbosity(Severity v); static Severity Verbosity(); /// Log a message to the output stream static void Message(Severity type, const std::string& message, const IfcAbstractEntityPtr entity=0); static void Status(const std::string& message, bool new_line=true); static void ProgressBar(int progress); static std::string GetLog(); }; #endif