186#include "b2ppconfig.h"
189#include "utils/b2module.H"
197inline std::ostream& operator<<(std::ostream& o,
const ObjectType& m);
206 const std::string& name_,
const std::string& suffix =
"",
208 ObjectType* base_type_ =
nullptr,
const char* doc_ =
nullptr)
212 base_type(base_type_),
215 module.set_object_type(this, name + suffix, aliases, suffix);
222 const std::string
get_name()
const {
return name + suffix; }
229 bool matching = identifier == name;
230 auto alias = aliases.begin();
231 while (!matching && alias != aliases.end()) {
232 matching = (*alias == identifier);
235 if (matching) { identifier =
get_name(); }
240 virtual const std::string get_cpp_name()
const {
return "??"; }
286 return module_.get_object_type(name_);
290 const std::string name;
291 const std::string suffix;
297 using children_t = std::map<std::string, ObjectType*>;
305inline std::ostream& operator<<(std::ostream& o,
const ObjectType& ot) {
306 return o << ot.get_name() <<
" (c++ type=" << ot.get_cpp_name() <<
")";
339template <
typename OBJECT,
typename BASE_OBJECT_TYPE = ObjectType>
343 const std::string& name_,
const std::string& suffix,
345 ObjectType* base_type_ =
nullptr,
const char* doc_ =
nullptr)
346 : BASE_OBJECT_TYPE(name_, suffix, aliases, module_, base_type_, doc_) {}
349 TypeError() <<
"Cannot create an object of type " << *
this
350 <<
" because this type is incomplete." <<
THROW;
355 TypeError() <<
"Cannot create an object of type " << *
this
356 <<
" because this type is incomplete." <<
THROW;
360 const std::string get_cpp_name()
const {
return demangle(
typeid(OBJECT)); }
362 bool is_type(
const Object* o) {
return typeid(o) ==
typeid(
const OBJECT*); }
370 ObjectType* ot = module_.get_object_type(name_);
372 KeyError() <<
"The type " << name_ <<
" is not a type of the module \"" << module_
377 KeyError() <<
"The type " << *ot <<
" is not a subtype of the type " << *
this <<
"."
414template <
typename OBJECT,
typename BASE_OBJECT_TYPE = ObjectType>
418 const std::string& name_,
const std::string& suffix,
420 ObjectType* base_type_ =
nullptr,
const char* doc_ =
nullptr)
421 : BASE_OBJECT_TYPE(name_, suffix, aliases, module_, base_type_, doc_) {}
426 return new (allocator.allocate(
sizeof(OBJECT))) OBJECT{};
429 const std::string get_cpp_name()
const {
return demangle(
typeid(OBJECT)); }
431 bool is_type(
const Object* o) {
return typeid(o) ==
typeid(
const OBJECT*); }
439 ObjectType* ot = module_.get_object_type(name_);
441 KeyError() <<
"The type " << name_ <<
" is not a type of the module \"" << module_
446 KeyError() <<
"The type " << *ot <<
" is not a subtype of the type " << *
this <<
"."
468 virtual void incref()
const {}
472 virtual void decref()
const {}
476 virtual void free() { this->
~Object(); }
481 virtual void decref_or_free()
const { this->
~Object(); }
487 static std::string unknown_object_name;
490inline std::string type_name(
const std::string& s =
"") {
return s; }
492template <
typename T1>
493inline std::string type_name(
const std::string& s =
"") {
494 return s +
'<' + demangle(
typeid(T1)) +
'>';
497template <
typename T1,
typename T2>
498inline std::string type_name(
const std::string& s =
"") {
499 return s +
'<' + demangle(
typeid(T1)) +
"," + demangle(
typeid(T2)) +
'>';
502template <
typename T1,
typename T2,
typename T3>
503inline std::string type_name(
const std::string& s =
"") {
504 return s +
'<' + demangle(
typeid(T1)) +
"," + demangle(
typeid(T2)) +
"," + demangle(
typeid(T3))
508template <
typename T1,
typename T2,
typename T3,
typename T4>
509inline std::string type_name(
const std::string& s =
"") {
510 return s +
'<' + demangle(
typeid(T1)) +
"," + demangle(
typeid(T2)) +
"," + demangle(
typeid(T3))
511 +
"," + demangle(
typeid(T4)) +
'>';
#define THROW
Definition b2exception.H:198
Definition b2allocator.H:63
Definition b2object.H:415
bool is_subtype(const Object *o)
Definition b2object.H:433
bool is_type(const Object *o)
Definition b2object.H:431
ObjectTypeComplete * get_subtype(const std::string &name_, Module &module_=b2000_module)
Definition b2object.H:438
OBJECT * new_object(Allocator &allocator)
Definition b2object.H:425
OBJECT * new_object()
Definition b2object.H:423
Definition b2object.H:340
bool is_type(const Object *o)
Definition b2object.H:362
ObjectTypeIncomplete * get_subtype(const std::string &name_, Module &module_=b2000_module)
Definition b2object.H:369
OBJECT * new_object()
Definition b2object.H:348
bool is_subtype(const Object *o)
Definition b2object.H:364
OBJECT * new_object(Allocator &allocator)
Definition b2object.H:354
Definition b2object.H:203
bool normalize_name(std::string &identifier) const
Definition b2object.H:228
const std::string get_name() const
Definition b2object.H:222
virtual Object * new_object(Allocator &allocator)
Definition b2object.H:259
virtual ObjectType * get_subtype(const std::string &name_, Module &module_=b2000_module)
Definition b2object.H:285
virtual Object * new_object()
Definition b2object.H:247
virtual bool is_type(const Object *o)
Definition b2object.H:265
virtual bool is_subtype(const Object *o)
Definition b2object.H:269
Definition b2object.H:456
virtual ~Object()
Definition b2object.H:464
static ObjectType type
Definition b2object.H:484
virtual const std::string & get_object_name() const
Definition b2object.H:460
Contains the base classes for implementing Finite Elements.
Definition b2boundary_condition.H:32
GenericException< KeyError_name > KeyError
Definition b2exception.H:320
GenericException< TypeError_name > TypeError
Definition b2exception.H:325
GenericException< UnimplementedError_name > UnimplementedError
Definition b2exception.H:314