-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor key store Co-authored-by: Igor Egorov <igor@qdrvm.io> --------- Co-authored-by: Igor Egorov <igor@qdrvm.io>
- Loading branch information
1 parent
e22c53e
commit bd278d7
Showing
88 changed files
with
1,190 additions
and
1,607 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
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
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
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,75 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
namespace kagome { | ||
template <typename T> | ||
class OptRef { | ||
public: | ||
OptRef() : data{nullptr} {} | ||
OptRef(T &data) : data{&data} {} | ||
OptRef(T &&) = delete; | ||
OptRef(std::nullopt_t) : data{nullptr} {} | ||
|
||
OptRef(const OptRef &) = default; | ||
|
||
OptRef &operator=(const OptRef &) = default; | ||
|
||
T &operator*() { | ||
BOOST_ASSERT(data); | ||
return *data; | ||
} | ||
|
||
const T &operator*() const { | ||
BOOST_ASSERT(data); | ||
return *data; | ||
} | ||
|
||
T *operator->() { | ||
BOOST_ASSERT(data); | ||
return data; | ||
} | ||
|
||
const T *operator->() const { | ||
BOOST_ASSERT(data); | ||
return data; | ||
} | ||
|
||
T &value() { | ||
BOOST_ASSERT(data); | ||
return *data; | ||
} | ||
|
||
const T &value() const { | ||
BOOST_ASSERT(data); | ||
return *data; | ||
} | ||
|
||
explicit operator bool() const noexcept { | ||
return data != nullptr; | ||
} | ||
|
||
bool operator!() const noexcept { | ||
return data == nullptr; | ||
} | ||
|
||
bool has_value() const noexcept { | ||
return data != nullptr; | ||
} | ||
|
||
bool operator==(const OptRef<T> &) const = default; | ||
|
||
bool operator==(const T &other) const { | ||
return has_value() && (*data == other); | ||
} | ||
|
||
private: | ||
T *data; | ||
}; | ||
} // namespace kagome |
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
Oops, something went wrong.