-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnyParameterProperties refactor #4412
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a8628d
combined parameter flags in a single mask
c505c2a
changed properties default
3aba095
changed modelselection_param to model_param
476d2a9
fixed docs
3e32f1c
switched to bitshifts instead of hexadecimals
dfb5aea
typesafe bitmasking
2bf79c4
refactored code to use enum class and bitmask operators
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,110 @@ | ||
#ifndef JSS_BITMASK_HPP | ||
#define JSS_BITMASK_HPP | ||
|
||
// (C) Copyright 2015 Just Software Solutions Ltd | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// | ||
// Boost Software License - Version 1.0 - August 17th, 2003 | ||
// | ||
// Permission is hereby granted, free of charge, to any person or | ||
// organization obtaining a copy of the software and accompanying | ||
// documentation covered by this license (the "Software") to use, | ||
// reproduce, display, distribute, execute, and transmit the | ||
// Software, and to prepare derivative works of the Software, and | ||
// to permit third-parties to whom the Software is furnished to | ||
// do so, all subject to the following: | ||
// | ||
// The copyright notices in the Software and this entire | ||
// statement, including the above license grant, this restriction | ||
// and the following disclaimer, must be included in all copies | ||
// of the Software, in whole or in part, and all derivative works | ||
// of the Software, unless such copies or derivative works are | ||
// solely in the form of machine-executable object code generated | ||
// by a source language processor. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE | ||
// LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could put "modified by G.F" here if you want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok! I wasn't sure how it works with the boost software license! |
||
|
||
#include<type_traits> | ||
|
||
namespace shogun { | ||
|
||
template<typename E> | ||
struct enable_bitmask_operators { | ||
static constexpr bool enable = false; | ||
}; | ||
|
||
#define enableEnumClassBitmask(T) template<> \ | ||
struct enable_bitmask_operators<T> \ | ||
{ \ | ||
static constexpr bool enable = true; \ | ||
} | ||
|
||
template<typename E> | ||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type | ||
operator|(E lhs, E rhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
return static_cast<E>( | ||
static_cast<underlying>(lhs) | static_cast<underlying>(rhs)); | ||
} | ||
|
||
template<typename E> | ||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type | ||
operator&(E lhs, E rhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
return static_cast<E>( | ||
static_cast<underlying>(lhs) & static_cast<underlying>(rhs)); | ||
} | ||
|
||
template<typename E> | ||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type | ||
operator^(E lhs, E rhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
return static_cast<E>( | ||
static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs)); | ||
} | ||
|
||
template<typename E> | ||
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type | ||
operator~(E lhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
return static_cast<E>( | ||
~static_cast<underlying>(lhs)); | ||
} | ||
|
||
template<typename E> | ||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type | ||
operator|=(E &lhs, E rhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
lhs = static_cast<E>( | ||
static_cast<underlying>(lhs) | static_cast<underlying>(rhs)); | ||
return lhs; | ||
} | ||
|
||
template<typename E> | ||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type | ||
operator&=(E &lhs, E rhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
lhs = static_cast<E>( | ||
static_cast<underlying>(lhs) & static_cast<underlying>(rhs)); | ||
return lhs; | ||
} | ||
|
||
template<typename E> | ||
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type | ||
operator^=(E &lhs, E rhs) { | ||
typedef typename std::underlying_type<E>::type underlying; | ||
lhs = static_cast<E>( | ||
static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs)); | ||
return lhs; | ||
} | ||
} | ||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whitespaces seem weird here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, and should change it to default to
false
instead of alltrue
.