siplasplas
A library for C++ reflection and introspection
cpp::dynamic_reflection::Entity Class Reference

Represents a C++ semantic entity (Class, function, namespace, etc) and manages its dynamic reflection information. More...

#include <siplasplas/reflection/dynamic/entity.hpp>

Inheritance diagram for cpp::dynamic_reflection::Entity:
cpp::dynamic_reflection::Class cpp::dynamic_reflection::Enum cpp::dynamic_reflection::Field cpp::dynamic_reflection::Function cpp::dynamic_reflection::Namespace

Public Member Functions

Entityparent ()
 Returns a reference to the parent entity The behavior is undefined if the entity has no parent entity (See orphan())
 
Runtimeruntime ()
 Returns a reference to the runtime where the entity is registered. More...
 
const SourceInfo & sourceInfo () const
 Returns source information about the entity.
 
const std::string & name () const
 Returns the name of the entity.
 
const std::string & fullName () const
 Returns the full qualifies name of the entity.
 
const SourceInfo::Kindkind () const
 Returns the kind (Namespace, class, enum, member function, etc) of the entity.
 
bool detached () const
 Checks whether the entity is not registered (attached) into a dynamic reflection runtime. More...
 
bool orphan () const
 Checks if the entity has no parent entity. More...
 
void attach (Runtime &runtime)
 Attaches the entity to a given runtime. More...
 
void attach (const std::weak_ptr< Entity > &parent)
 Attaches the entity to the runtime of a given entity and links that enity as parent. More...
 
void addChild (const std::shared_ptr< Entity > &entity)
 Links the given entity as child of the entity. More...
 
bool isChild (const std::shared_ptr< Entity > &entity) const
 Checks if the given entity is a child entity of this entity. More...
 
bool isChild (const Entity &entity) const
 Checks if the given entity is a child entity of this entity. More...
 
bool isChildByName (const std::string &name) const
 Checks if the entity has a child entity with the given name. More...
 
bool isChildByFullName (const std::string &fullName) const
 Checks if the entity has a child entity with the given name. More...
 
EntitygetChildByFullName (const std::string &fullName)
 Returns a child entity given its full name. More...
 
EntitygetChildByName (const std::string &name)
 Returns a child entity given its name. More...
 
std::vector< std::string > getChildrenNamesByKind (const SourceInfo::Kind &kind)
 Returns the names of the child entities with a given kind. More...
 
std::shared_ptr< Entitypointer ()
 Returns the shared pointer holding the entity object.
 

Protected Member Functions

 Entity (const SourceInfo &sourceInfo)
 

Friends

bool operator== (const Entity &lhs, const Entity &rhs)
 Checks two entitties for equality. More...
 
bool operator!= (const Entity &lhs, const Entity &rhs)
 Checks two entitties for inequality. More...
 

Detailed Description

Represents a C++ semantic entity (Class, function, namespace, etc) and manages its dynamic reflection information.

Member Function Documentation

void cpp::dynamic_reflection::Entity::addChild ( const std::shared_ptr< Entity > &  entity)

Links the given entity as child of the entity.

This function links the given entity as a child entity of the entity object. At the same time, the given entity links this entity as its parent. The behavior is undefined if the given entity already has a parent (See orphan()). If the entity object already has a child entity with the given entity full name, the given entity is ignored

Parameters
entityShared pointer to an orphan entity
void cpp::dynamic_reflection::Entity::attach ( Runtime runtime)

Attaches the entity to a given runtime.

The behavior is undefined if the entity is already attached to a dynamic reflection runtime

Parameters
runtimeRuntime which the enity will be attached to
void cpp::dynamic_reflection::Entity::attach ( const std::weak_ptr< Entity > &  parent)

Attaches the entity to the runtime of a given entity and links that enity as parent.

The behavior is undefined if the entity is already attached to a dynamic reflection runtime or if the entity already has a parent entity

Parameters
parentPointer to an already-registered entity
bool cpp::dynamic_reflection::Entity::detached ( ) const

Checks whether the entity is not registered (attached) into a dynamic reflection runtime.

Returns
True if the entity is not attached to a runtime. False otherwise
Entity& cpp::dynamic_reflection::Entity::getChildByFullName ( const std::string &  fullName)

Returns a child entity given its full name.

The behavior is undefined if the entity object has no linked child entity with that full name

Parameters
fullNameChild entity full name
Returns
A reference to the child entity
Entity& cpp::dynamic_reflection::Entity::getChildByName ( const std::string &  name)

Returns a child entity given its name.

The behavior is undefined if the entity object has no linked child entity with that name. Equivalent to getChildByFullName(fullName() + <name>)

Parameters
fullNameChild entity full name
Returns
A reference to the child entity
std::vector<std::string> cpp::dynamic_reflection::Entity::getChildrenNamesByKind ( const SourceInfo::Kind kind)

Returns the names of the child entities with a given kind.

This function filters the set of child entities of the entity object, returning only the names of those which kind is equal to the specified kind. This can be useful to do quaries like "List the set of classes of a given namespace":

for(const std::string& entityName : entity.getChildrenNamesByKind(SourceInfo::Kind::ENUM))
{
const auto& enum_ = Enum::fromEntity(entity.getChildByFullName(entityName).pointer());
std::cout << enum_.fullName() << std::endl;
}
Parameters
kindEntity kind Requested entity kind
Returns
A vector with the full names of the children entities with the given kind
bool cpp::dynamic_reflection::Entity::isChild ( const std::shared_ptr< Entity > &  entity) const

Checks if the given entity is a child entity of this entity.

Parameters
entityShared pointer to an entity
Returns
True if the given entity has this entity as parent, false otherwise
bool cpp::dynamic_reflection::Entity::isChild ( const Entity entity) const

Checks if the given entity is a child entity of this entity.

Parameters
entityReference to an entity
Returns
True if the given entity has this entity as parent, false otherwise
bool cpp::dynamic_reflection::Entity::isChildByFullName ( const std::string &  fullName) const

Checks if the entity has a child entity with the given name.

Equivalent to isChildByFullName(fullName() + <name>)

Parameters
nameName of the child entity
Returns
True there's a child entity with the given name. False otherwise
bool cpp::dynamic_reflection::Entity::isChildByName ( const std::string &  name) const

Checks if the entity has a child entity with the given name.

Equivalent to isChildByFullName(fullName() + <name>)

Parameters
nameName of the child entity
Returns
True there's a child entity with the given name. False otherwise
bool cpp::dynamic_reflection::Entity::orphan ( ) const

Checks if the entity has no parent entity.

Returns
True if the entity has no parent entity, true otherwisw
Runtime& cpp::dynamic_reflection::Entity::runtime ( )

Returns a reference to the runtime where the entity is registered.

The behavior is undefined if the entity is not attached to any runtime. See detached()

Friends And Related Function Documentation

bool operator!= ( const Entity lhs,
const Entity rhs 
)
friend

Checks two entitties for inequality.

Equivalent to !(lhs == rhs)

Returns
True if the two entitites have different full name. False otherwise
bool operator== ( const Entity lhs,
const Entity rhs 
)
friend

Checks two entitties for equality.

Returns
True if the two entitites have the same full name. False otherwise

The documentation for this class was generated from the following file: