-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make clcpp::GetTypeNameHash constexpr so that you can use them as
switch case values and parameterise in other ways.
- Loading branch information
1 parent
5365dae
commit 79dcfc4
Showing
8 changed files
with
766 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -983,3 +983,6 @@ namespace clcpp | |
return 0; | ||
} | ||
} | ||
|
||
template <typename Type> | ||
constexpr unsigned int clcppTypeHash(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
#include "clcppcodegen.h" | ||
#include <cstdio> | ||
|
||
struct Base | ||
{ | ||
const clcpp::Type* type = nullptr; | ||
}; | ||
|
||
struct attrReflect FirstType : public Base | ||
{ | ||
}; | ||
|
||
struct attrReflect SecondType : public Base | ||
{ | ||
}; | ||
|
||
struct attrReflect ThirdType : public Base | ||
{ | ||
}; | ||
|
||
template <typename Type> | ||
Type* New() | ||
{ | ||
auto* object = new Type(); | ||
object->type = clcpp::GetType<Type>(); | ||
return object; | ||
} | ||
|
||
void TestConstexprGetType() | ||
{ | ||
Base* objects[] = { | ||
New<FirstType>(), | ||
New<SecondType>(), | ||
New<ThirdType>(), | ||
}; | ||
|
||
for (Base* object : objects) | ||
{ | ||
switch (object->type->name.hash) | ||
{ | ||
case clcppTypeHash<FirstType>(): | ||
printf("Do something with the first type\n"); | ||
break; | ||
case clcppTypeHash<SecondType>(): | ||
printf("Do something with the second type\n"); | ||
break; | ||
case clcppTypeHash<ThirdType>(): | ||
printf("Do something with the third type\n"); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.