Created
June 22, 2016 15:46
-
-
Save EAirPeter/f57437ccac4715523ecdaee2e997491f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* utils/Type.h | |
* Provides utilities for creating types. | |
* Any move operation will destruct the source object. | |
*/ | |
#ifndef PQS_SOURCE | |
# error Invalid use of this file. | |
#endif | |
#ifndef PQS_UTILS_TYPE_H_ | |
#define PQS_UTILS_TYPE_H_ | |
#include "../Common.h" // CONCAT{,_},this | |
#define TNAME(type_) CONCAT_(T, type_) | |
// Provides the declaration of a member function: | |
// Generics: | |
// With const this and a default parameter list. | |
#define TMFUNCD(type_, ret_, name_) \ | |
ret_ CONCAT(type_, name_) (const TNAME(type_) *this) | |
// With const this and a given parameter list. | |
#define TMFUNCP(type_, ret_, name_, ...) \ | |
ret_ CONCAT(type_, name_) (const TNAME(type_) *this, __VA_ARGS__) | |
// With non-const this and a default parameter list. | |
#define TMFUNVD(type_, ret_, name_) \ | |
ret_ CONCAT(type_, name_) (TNAME(type_) *this) | |
// With non-const this and a given parameter list. | |
#define TMFUNVP(type_, ret_, name_, ...) \ | |
ret_ CONCAT(type_, name_) (TNAME(type_) *this, __VA_ARGS__) | |
// Basic concepts: | |
// Default Constructor. | |
#define TMCTORD(type_) \ | |
TMFUNVD(type_, TNAME(type_) *, Ctor) | |
// Copy Constructor. | |
#define TMCTORC(type_, rhs_) \ | |
TMFUNVP(type_, TNAME(type_) *, CtorCopy, const TNAME(type_) *rhs_) | |
// Move Constructor. | |
#define TMCTORM(type_, rhs_) \ | |
TMFUNVP(type_, TNAME(type_) *, CtorMove, TNAME(type_) *rhs_) | |
// Other Constructor. | |
#define TMCTORO(type_, name_, ...) \ | |
TMFUNVP(type_, TNAME(type_) *, CONCAT_(Ctor, name_), __VA_ARGS__) | |
// Destructor. | |
#define TMFDTOR(type_) \ | |
TMFUNVD(type_, TNAME(type_) *, Dtor) | |
// Copy Assignment. | |
#define TMFASSC(type_, rhs_) \ | |
TMFUNVP(type_, TNAME(type_) *, AssCopy, const TNAME(type_) *rhs_) | |
// Move Assignment. | |
#define TMFASSM(type_, rhs_) \ | |
TMFUNVP(type_, TNAME(type_) *, AssMove, const TNAME(type_) *rhs_) | |
// Other Assignment. | |
#define TMFASSO(type_, name_, ...) \ | |
TMFUNVP(type_, TNAME(type_) *, CONCAT_(Ass, name_), __VA_ARGS__) | |
// About persistence: | |
// Constructs from a file containing saved data. | |
#define TMCTORF(type_, from_) \ | |
TMCTORO(type_, File, FILE *from_) | |
// Reads from a file containing saved data. | |
#define TMFUNSR(type_, from_) \ | |
TMFUNVP(type_, TNAME(type_) *, FRead, FILE *from_) | |
// Writes to a file to be saved. | |
#define TMFUNSW(type_, to_) \ | |
TMFUNCP(type_, TNAME(type_) *, FWrite, FILE *to_) | |
#endif // ifndef PQS_UTILS_TYPE_H_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment