Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions code_gen/macros_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,38 @@ def generate_macros( path:str, undef_path:str ):
}
''' )

def_text.comment_ln('Used to declare & define all bitwise operators for an enum class that uses bit patterns which can be combined. Note to use in the correct namespace (usually the global namespace)')
add_macro( '_CTLE_DEFINE_BITWISE_OPERATORS', '''
#define _CTLE_DEFINE_BITWISE_OPERATORS(enum_type)\\
inline enum_type operator|(enum_type lhs, enum_type rhs) { \\
using _Ty = std::underlying_type_t<enum_type>; \\
return (enum_type)((_Ty)(lhs) | (_Ty)(rhs)); \\
}\\
inline enum_type operator&(enum_type lhs, enum_type rhs) { \\
using _Ty = std::underlying_type_t<enum_type>; \\
return (enum_type)((_Ty)(lhs) & (_Ty)(rhs)); \\
}\\
inline enum_type operator^(enum_type lhs, enum_type rhs) { \\
using _Ty = std::underlying_type_t<enum_type>; \\
return (enum_type)((_Ty)(lhs) ^ (_Ty)(rhs)); \\
}\\
inline enum_type operator~(enum_type value) {\\
using _Ty = std::underlying_type_t<enum_type>; \\
return (enum_type)(~(_Ty)(value)); \\
}\\
inline enum_type& operator|=(enum_type& lhs, enum_type rhs) {\\
lhs = lhs | rhs; \\
return lhs;\\
}\\
inline enum_type& operator&=(enum_type& lhs, enum_type rhs) {\\
lhs = lhs & rhs; \\
return lhs;\\
}\\
inline enum_type& operator^=(enum_type& lhs, enum_type rhs) {\\
lhs = lhs ^ rhs; \\
return lhs;\\
}
''' )

out = formatted_output()
out.lines.extend( header_text.lines )
Expand Down
3 changes: 2 additions & 1 deletion code_gen/types_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

# forward definition of all ctle classes
fwd_classes = [
['status.h', ['enum class status_code : int','status']],
['status.h', ['enum class status_code : int','status']],
['status_return.h', ['template<class _StatusType, class _ValueType> class status_return']],
['', ['template<typename _Ty> using value_return = status_return<status, _Ty>;']],
['data_source.h', ['file_data_source']],
['data_destination.h', ['file_data_destination']],
['hasher.h', ['hasher_sha256', 'hasher_xxh64', 'hasher_xxh128', 'template <size_t _Size> class hasher_noop']],
Expand Down
32 changes: 32 additions & 0 deletions include/ctle/_macros.inl
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,35 @@
}\
}

// Used to declare & define all bitwise operators for an enum class that uses bit patterns which can be combined. Note
// to use in the correct namespace (usually the global namespace)
#define _CTLE_DEFINE_BITWISE_OPERATORS(enum_type)\
inline enum_type operator|(enum_type lhs, enum_type rhs) { \
using _Ty = std::underlying_type_t<enum_type>; \
return (enum_type)((_Ty)(lhs) | (_Ty)(rhs)); \
}\
inline enum_type operator&(enum_type lhs, enum_type rhs) { \
using _Ty = std::underlying_type_t<enum_type>; \
return (enum_type)((_Ty)(lhs) & (_Ty)(rhs)); \
}\
inline enum_type operator^(enum_type lhs, enum_type rhs) { \
using _Ty = std::underlying_type_t<enum_type>; \
return (enum_type)((_Ty)(lhs) ^ (_Ty)(rhs)); \
}\
inline enum_type operator~(enum_type value) {\
using _Ty = std::underlying_type_t<enum_type>; \
return (enum_type)(~(_Ty)(value)); \
}\
inline enum_type& operator|=(enum_type& lhs, enum_type rhs) {\
lhs = lhs | rhs; \
return lhs;\
}\
inline enum_type& operator&=(enum_type& lhs, enum_type rhs) {\
lhs = lhs & rhs; \
return lhs;\
}\
inline enum_type& operator^=(enum_type& lhs, enum_type rhs) {\
lhs = lhs ^ rhs; \
return lhs;\
}

5 changes: 5 additions & 0 deletions include/ctle/_undef_macros.inl
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@
#endif//ctStatusCallThrow
#undef ctStatusCallThrow

#ifndef _CTLE_DEFINE_BITWISE_OPERATORS
#error The expected macro _CTLE_DEFINE_BITWISE_OPERATORS does not exist.
#endif//_CTLE_DEFINE_BITWISE_OPERATORS
#undef _CTLE_DEFINE_BITWISE_OPERATORS

3 changes: 3 additions & 0 deletions include/ctle/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class status;
// from status_return.h
template<class _StatusType, class _ValueType> class status_return;

// from
template<typename _Ty> using value_return = status_return<status, _Ty>;;

// from data_source.h
class file_data_source;

Expand Down
Loading