Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timkerchmar/tstype
Lightweight C++ RTTI library
https://github.com/timkerchmar/tstype
Last synced: 28 days ago
JSON representation
Lightweight C++ RTTI library
- Host: GitHub
- URL: https://github.com/timkerchmar/tstype
- Owner: timkerchmar
- License: mit
- Created: 2018-04-25T22:40:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-28T11:59:30.000Z (over 6 years ago)
- Last Synced: 2024-08-04T02:09:36.040Z (4 months ago)
- Language: C++
- Size: 16.6 KB
- Stars: 47
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- AwesomeCppGameDev - tstype
README
# TSType
## What is it?
A lightweight RTTI lib for C++ that doesn't require C++'s RTTI or boost. It enables real reflection and is useful for inspecting 3rd party structs and classes without modifying 3rd party source files.
## How do I use it?
Add the cpp and h source files to your project.
### Header Changes
Add TSType declarations after the classes declarations you want to inspect:
```cpp
TSDeclareType(SomeKindOfClass, SomeBaseClassType);
```If there is no base class:
```cpp
TSDeclareType(SomeKindOfClass, TSEmpty);
```If the class is abstract:
```cpp
TSDeclareAbstractType(SomeKindOfClass, SomeBaseClassType);
```### Source Changes
Implement the class in a c++ file:
```cpp
TSImplementType(SomeKindOfClass, "complexity manager");
```If the class is abstract:
```cpp
TSImplementAbstractType(SomeKindOfClass, "complexity manager");
```Describe each public field in the C++ source and add a default value:
```cpp
TSField(TSString, SomeKindOfClass, fileName, "user.prefs");
```## Sample
```cpp
#include "TSType.h"class MostWanted
{
public:
std::vector< std::string > names;
};
TSDeclareType(MostWanted, TSEmpty);
``````cpp
#include "MostWanted.h"TSImplementType(MostWanted, "persons of interest");
TSField(TSStringArray, MostWanted, names, std::vector< std::string >());void testTSType()
{
printf("All known types:\n");
TSType::print();
printf("\nPrinting a description of the TSStringType object:\n");
PrintObjectHierarchy(TSTypeType, TSStringType);
MostWanted* foo = MostWantedType->create();
foo->names.push_back("Bob");printf("\nPrinting a description of the MostWanted object:\n");
PrintObjectHierarchy(MostWantedType, foo);MostWantedType->destroy(foo);
}
```Output:
```
All known types:
Type
MostWanted ( names )
TSObject ( type )
ContainerBase
GenericContainer
GenericReference ( id )
TSType ( fields name description )
Array
MostWantedArray
MostWantedPtrArray
TSObjectArray
TSObjectPtrArray
TSTypePtrArray
TSTypefields
ContainerBaseArray
ContainerBasePtrArray
GenericContainerArray
GenericContainerPtrArray
GenericReferenceArray
GenericReferencePtrArray
TSStringArray
MostWantednames
TSStringPtrArray
Pointer
MostWantedPtr
MostWantedArrayPtr
MostWantedPtrArrayPtr
TSObjectPtr
TSObjectArrayPtr
TSObjectPtrArrayPtr
TSTypePtr
TSObjecttype
TSTypePtrArrayPtr
ContainerBasePtr
ContainerBaseArrayPtr
ContainerBasePtrArrayPtr
GenericContainerPtr
GenericContainerArrayPtr
GenericContainerPtrArrayPtr
GenericReferencePtr
GenericReferenceArrayPtr
GenericReferencePtrArrayPtr
TSStringPtr
TSStringArrayPtr
TSStringPtrArrayPtr
TSString
TSTypename
TSTypedescription
GenericReferenceidPrinting a description of the TSStringType object:
type instance
fields
name = "TSString"
description = "text"Printing a description of the MostWanted object:
persons of interest
names
text = "Bob"
```## Notes
Missing API for enumerating the methods of an object.
Default values are not evaluated until they are requested by calling field type class's setDefaultValue on the object instance.