로딩중...
검색중...
일치하는것 없음
by::type 클래스 참조abstract

Core class for runtime type information in byeol language 더 자세히 ...

#include <type.hpp>

by::type에 대한 상속 다이어그램 :
by::ttypeBase< T, tmetaTypeDef< T, tifHasMetaTypeDef< T >::is >::is > by::ntype by::ttypeBase< void, type > by::ttype< T > by::expr::exprType by::mgdType by::funcType

Public 멤버 함수

virtual nbool operator== (const me &rhs) const
 Checks if two type objects represent the same type.
 
nbool operator!= (const me &rhs) const
 
virtual nbool isTemplate () const =0
 
virtual nbool isAbstract () const =0
 
virtual const std::string & getName () const
 
virtual void * make () const =0
 create an instance to be refered this type.
 
template<typename T >
T * makeAs () const
 
virtual ncnt size () const =0
 
virtual nbool init ()
 Initializes type metadata and constructs class hierarchy
 
virtual nbool rel ()
 
virtual const typegetSuper () const =0
 
virtual const nboolisInit () const =0
 
const types & getLeafs () const
 Returns all most derived classes (leaf nodes) from this class
 
const types & getSubs () const
 
const types & getSupers () const
 
virtual nbool isSuper (const type &it) const
 Checks if this type is a super class of the given type
 
nbool isSuper (const type *it) const BY_SIDE_FUNC(isSuper)
 
template<typename T >
nbool isSuper () const
 
nbool isSub (const type &it) const
 Checks if this type is a sub class of the given type
 
nbool isSub (const type *it) const BY_SIDE_FUNC(isSub)
 
template<typename T >
nbool isSub () const
 
const typegetStatic () const BY_CONST_FUNC(_getStatic()) virtual const nchar *getMetaTypeName() const
 Get meta type name for efficient type checking
 

Protected 멤버 함수

virtual types & _getSubs ()=0
 
virtual types & _getSupers ()=0
 
virtual type_getStatic () const =0
 
void _setInit (nbool newState)
 
virtual void _onAddSubClass (const me &subClass)
 Hook method called when a new subclass is registered with this type.
 
virtual types ** _onGetLeafs () const =0
 
void _setLeafs (types *newLeafs) const
 
virtual const std::string & _getNativeName () const
 

상세한 설명

Core class for runtime type information in byeol language

The central class of the meta module. Provides fundamental type information APIs.

Basic type identification

  • isTemplate(): Returns whether this is a template class
  • isAbstract(): Returns whether this is an abstract class
  • getName(): Returns class name (demangled)

Class hierarchy information

  • getSupers(): Returns list of super classes, with direct parent at the end
  • getSubs(): Returns list of sub classes, with closest descendants first
  • isSuper(const type& rhs): Checks if this is a super class of rhs
  • isSub(const type& rhs): Checks if this is a sub class of rhs

Performance note: isSuper() and isSub() are more efficient than dynamic_cast. While dynamic_cast typically loops through vtables, the meta module uses a tier algorithm that compares tier values and char* addresses for O(1) type checking.

Instance creation

  • make(): Creates instance using default constructor. Returns nullptr if no default constructor exists.

Meta type information management

  • init(): Initializes type information
  • rel(): Releases type information

These are typically handled automatically via BY_INIT_META macro and rarely need direct invocation.

How meta information is generated

Type information like isTemplate(), isAbstract(), and getName() is filled by ttypeBase<T> through metaprogramming. The purpose of type::init() is to construct the class hierarchy.

The hierarchy is built using the constraint that "all classes must define super as a typedef". With super defined for all classes, ttype<super>().init() can be called, enabling recursive class hierarchy construction:

if(_isInit) return false;
_isInit = true; // Executes only once
type& super = (type&) getSuper();
super.init(); // Recursively calls parent's init
// Eventually reaches adam, which has no parent
types& mySupers = getSupers();
mySupers = super.getSupers();
mySupers.push_back(&super);
}
Core class for runtime type information in byeol language
Definition type.hpp:100
virtual nbool init()
Initializes type metadata and constructs class hierarchy
Rich logging support with polymorphic type conversion
Definition richLog.hpp:34

Automatic meta information generation

Type objects are initialized via init() calls, but manually calling init() for every class would be inefficient. The BY_INIT_META macro solves this by using BY_INITIATOR to execute init() before main() via static object initialization with lambda functions.

The constraint is that each class declaration must include BY_INIT_META(MyClass). These meta DSL-style macros are executed through the BY macro convention, and core module adds additional meta DSL macros, so use BY(CLASS()) or BY(ADT()) instead of calling BY_INIT_META directly.

Adding custom meta information

While type provides substantial type information, language implementations like byeol may need additional information like parameters or return types. You might think to inherit from type, but since the user entry point must always be ttype<T>, and you cannot modify ttype<T> code from modules depending on meta, inheritance isn't possible. Instead, inject custom meta types.

The core code is in ttypeBase<T>:

class ttypeBase: public S { }
struct tmetaTypeDef { using is = type; };
template <typename T>
struct tmetaTypeDef<T, true> { using is = typename T::metaType; };
Base class for template type metadata
Definition ttypeBase.hpp:19
Meta type definition selector
Definition rtti.hpp:164

tmetaTypeDef returns T::metaType if it exists, otherwise returns type. ttype inherits from ttypeBase, which inherits from tmetaTypeDef<T>::is. When calling ttype<T>, if class T defines typedef metaType MyType, the ttype<T> object will be based on MyType.

This feature is actually used in the core module to inject ntype. See ntype for details.

멤버 함수 문서화

◆ _onAddSubClass()

virtual void by::type::_onAddSubClass ( const me & subClass)
protectedvirtual

Hook method called when a new subclass is registered with this type.

Derived type classes can override this method to perform custom actions (e.g., updating internal structures or caches) whenever a new subClass is added to its hierarchy.

매개변수
subClassThe new subclass being added.

◆ getLeafs()

const types & by::type::getLeafs ( ) const

Returns all most derived classes (leaf nodes) from this class

반환값
Vector of type pointers representing all leaf classes in hierarchy

◆ getStatic()

const type & by::type::getStatic ( ) const

Get meta type name for efficient type checking

This returns metaTypename. metaTypename can be used like 'dynamic_cast<yourType>'. as you may know, c++'s dynamic_cast is slow. because normally compilers tries to loop in order to figure out which type is fit to given your type parameter. 'meta' library, however, uses 'tier' algorithm and it's O(1), so it's faster.

you can use your own metaType to represent more data on type class. for instance, 'core' module uses 'ntype' custom type class. but in that case, when you compare custom type class, you must compare extended data to 'rhs' variable to base type class, 'type'.

so how can you know that 'type' is actually instance of your derived custom type class in 'tier' algorithm? please don't think about 'dynamic_cast'. it'll vanish our effectiveness to use 'tier' algorithm. that's why I make 'getMetaTypeName()' func.

반환값
static literal c-style string for meta type name. so you are able to use c-style casting if address of 'rhs' variables's getMetaTypeName() isn just same to yours.
yourType& a = ....;
type& rhs = ....;
if(a.getMetaTypeName() != rhs.getMetaTypeName()) return;
...now you can do something on yourType's data...

◆ init()

virtual nbool by::type::init ( )
virtual

Initializes type metadata and constructs class hierarchy

반환값
true on success, false if already initialized
주의
Recursively initializes super class hierarchy. Automatically called via BY_INIT_META macro before main(). Sets up super/sub relationships.

◆ isSub()

nbool by::type::isSub ( const type & it) const

Checks if this type is a sub class of the given type

반환값
true if this is a sub class of it, false otherwise
주의
Uses O(1) tier algorithm. Implemented as it.isSuper(*this).

◆ isSuper()

virtual nbool by::type::isSuper ( const type & it) const
virtual

Checks if this type is a super class of the given type

반환값
true if this is a super class of it, false otherwise
주의
Uses O(1) tier algorithm comparing tier values, much faster than dynamic_cast which typically loops through vtables.

◆ make()

virtual void * by::type::make ( ) const
pure virtual

create an instance to be refered this type.

Remarks
available when the type defines a ctor without any params.
반환값
return an address of new instance, however, if ctor without any params isn't defined, then returns null.

by::mgdType, by::ttypeBase< void, type >에서 구현되었습니다.

◆ operator==()

virtual nbool by::type::operator== ( const me & rhs) const
virtual

Checks if two type objects represent the same type.

This comparison typically checks if the underlying type information (e.g., name, template status) is identical.

매개변수
rhsThe other type object to compare with.
반환값
true if both type objects represent the same type, false otherwise.

이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: