refactor: Move ValueWrapper into lib_system
So other projects can use it
This commit is contained in:
1 parent
4751372f9a
commit
5657fc81e3
26 files changed
+178
-174
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
namespace bts::core {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace bts::domain {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace bts::domain {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/io/JsonReader.h"
|
||||
#include "spark/logging/logging.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace bts::domain {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/domain_model/SecurityKey.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
namespace bts {
|
||||
struct CQuantity {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "spark/core/TimeStamp.h"
|
||||
#include "spark/io/JsonDumper.h"
|
||||
#include "spark/io/JsonReader.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_export.h"
|
||||
#include "spark/utils/bts_no_copy.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
namespace bts {
|
||||
namespace md {
|
||||
using ImpliedSize = utils::ValueWrapper<struct ImpliedSizeTag, uint32_t>;
|
||||
}
|
||||
} // namespace bts
|
||||
} // namespace bts
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/mercury/common/FatWrapper.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "spark/orderman/gateways/sim/SimExecutionGatewayUniqueWrapper.h"
|
||||
#include "spark/tracing/PerfLog.h"
|
||||
#include "spark/utils/PBUtils.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "spark/domain_model/Security.h"
|
||||
#include "spark/md/IntPrice.h"
|
||||
#include "spark/domain_model/Security.pb.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include "spark/utils/overloaded.h"
|
||||
|
||||
namespace bts {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "spark/api/services/OrderService.pb.h"
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/domain_model/common.h"
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include "spark/utils/bts_chrono.h"
|
||||
#include "spark/utils/overloaded.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace bts {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
|
||||
namespace bts {
|
||||
namespace qbus {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/utils/ValueWrapper.h"
|
||||
#include "system/value_wrapper.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -1,151 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
class ValueWrapper {
|
||||
public:
|
||||
typedef ValueT Value;
|
||||
|
||||
constexpr ValueWrapper() = default;
|
||||
constexpr explicit ValueWrapper(const ValueT &v);
|
||||
constexpr explicit ValueWrapper(ValueT &&v);
|
||||
|
||||
constexpr ValueWrapper(const ValueWrapper &v) = default;
|
||||
constexpr ValueWrapper(ValueWrapper &&v) = default;
|
||||
|
||||
ValueWrapper &operator=(ValueWrapper const &v) = default;
|
||||
ValueWrapper &operator=(ValueWrapper &&v) = default;
|
||||
|
||||
constexpr const ValueT &value() const;
|
||||
constexpr ValueT &value();
|
||||
|
||||
private:
|
||||
ValueT v_;
|
||||
};
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator==(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator!=(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator>(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator>=(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator<(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator<=(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class V>
|
||||
std::ostream &operator<<(std::ostream &s, ValueWrapper<Tag, V> const &v);
|
||||
|
||||
} // namespace utils
|
||||
} // namespace bts
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename Tag, typename Value>
|
||||
struct hash<bts::utils::ValueWrapper<Tag, Value>> {
|
||||
std::size_t operator()(const bts::utils::ValueWrapper<Tag, Value> &k) const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueWrapper<Tag, ValueT>::ValueWrapper(const ValueT &v) : v_(v) {}
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueWrapper<Tag, ValueT>::ValueWrapper(ValueT &&v)
|
||||
: v_(std::move(v)) {}
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueT const &ValueWrapper<Tag, ValueT>::value() const {
|
||||
return v_;
|
||||
}
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueT &ValueWrapper<Tag, ValueT>::value() {
|
||||
return v_;
|
||||
}
|
||||
|
||||
#define BIN_OP(result_t, op) \
|
||||
template <class Tag, class ValueT> \
|
||||
constexpr result_t operator op( \
|
||||
const ValueWrapper<Tag, ValueT> &lhs, \
|
||||
const ValueWrapper<Tag, ValueT> &rhs) { \
|
||||
return result_t(lhs.value() op rhs.value()); \
|
||||
}
|
||||
|
||||
BIN_OP(bool, ==)
|
||||
BIN_OP(bool, !=)
|
||||
BIN_OP(bool, >)
|
||||
BIN_OP(bool, >=)
|
||||
BIN_OP(bool, <)
|
||||
BIN_OP(bool, <=)
|
||||
|
||||
#undef BIN_OP
|
||||
|
||||
template <class Tag, class V>
|
||||
V &operator*(ValueWrapper<Tag, V> &v);
|
||||
|
||||
template <class Tag, class V>
|
||||
const V &operator*(const ValueWrapper<Tag, V> &v);
|
||||
|
||||
template <class Tag, class V>
|
||||
std::ostream &operator<<(std::ostream &s, ValueWrapper<Tag, V> const &v);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
template <class Tag, class V>
|
||||
V &operator*(ValueWrapper<Tag, V> &v) {
|
||||
return v.value();
|
||||
}
|
||||
|
||||
template <class Tag, class V>
|
||||
const V &operator*(const ValueWrapper<Tag, V> &v) {
|
||||
return v.value();
|
||||
}
|
||||
|
||||
template <class Tag, class V>
|
||||
std::ostream &operator<<(std::ostream &s, ValueWrapper<Tag, V> const &v) {
|
||||
s << v.value();
|
||||
return s;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace bts
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename Tag, typename Value>
|
||||
std::size_t hash<bts::utils::ValueWrapper<Tag, Value>>::operator()(
|
||||
const bts::utils::ValueWrapper<Tag, Value> &k) const {
|
||||
return hash<Value>()(k.value());
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
#include "system/value_wrapper.h"
|
||||
@@ -0,0 +1,151 @@
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
class ValueWrapper {
|
||||
public:
|
||||
typedef ValueT Value;
|
||||
|
||||
constexpr ValueWrapper() = default;
|
||||
constexpr explicit ValueWrapper(const ValueT &v);
|
||||
constexpr explicit ValueWrapper(ValueT &&v);
|
||||
|
||||
constexpr ValueWrapper(const ValueWrapper &v) = default;
|
||||
constexpr ValueWrapper(ValueWrapper &&v) = default;
|
||||
|
||||
ValueWrapper &operator=(ValueWrapper const &v) = default;
|
||||
ValueWrapper &operator=(ValueWrapper &&v) = default;
|
||||
|
||||
constexpr const ValueT &value() const;
|
||||
constexpr ValueT &value();
|
||||
|
||||
private:
|
||||
ValueT v_;
|
||||
};
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator==(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator!=(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator>(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator>=(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator<(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr bool operator<=(
|
||||
const ValueWrapper<Tag, ValueT> &lhs, const ValueWrapper<Tag, ValueT> &rhs);
|
||||
|
||||
template <class Tag, class V>
|
||||
std::ostream &operator<<(std::ostream &s, ValueWrapper<Tag, V> const &v);
|
||||
|
||||
} // namespace utils
|
||||
} // namespace bts
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename Tag, typename Value>
|
||||
struct hash<bts::utils::ValueWrapper<Tag, Value>> {
|
||||
std::size_t operator()(const bts::utils::ValueWrapper<Tag, Value> &k) const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueWrapper<Tag, ValueT>::ValueWrapper(const ValueT &v) : v_(v) {}
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueWrapper<Tag, ValueT>::ValueWrapper(ValueT &&v)
|
||||
: v_(std::move(v)) {}
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueT const &ValueWrapper<Tag, ValueT>::value() const {
|
||||
return v_;
|
||||
}
|
||||
|
||||
template <class Tag, class ValueT>
|
||||
constexpr ValueT &ValueWrapper<Tag, ValueT>::value() {
|
||||
return v_;
|
||||
}
|
||||
|
||||
#define BIN_OP(result_t, op) \
|
||||
template <class Tag, class ValueT> \
|
||||
constexpr result_t operator op( \
|
||||
const ValueWrapper<Tag, ValueT> &lhs, \
|
||||
const ValueWrapper<Tag, ValueT> &rhs) { \
|
||||
return result_t(lhs.value() op rhs.value()); \
|
||||
}
|
||||
|
||||
BIN_OP(bool, ==)
|
||||
BIN_OP(bool, !=)
|
||||
BIN_OP(bool, >)
|
||||
BIN_OP(bool, >=)
|
||||
BIN_OP(bool, <)
|
||||
BIN_OP(bool, <=)
|
||||
|
||||
#undef BIN_OP
|
||||
|
||||
template <class Tag, class V>
|
||||
V &operator*(ValueWrapper<Tag, V> &v);
|
||||
|
||||
template <class Tag, class V>
|
||||
const V &operator*(const ValueWrapper<Tag, V> &v);
|
||||
|
||||
template <class Tag, class V>
|
||||
std::ostream &operator<<(std::ostream &s, ValueWrapper<Tag, V> const &v);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
template <class Tag, class V>
|
||||
V &operator*(ValueWrapper<Tag, V> &v) {
|
||||
return v.value();
|
||||
}
|
||||
|
||||
template <class Tag, class V>
|
||||
const V &operator*(const ValueWrapper<Tag, V> &v) {
|
||||
return v.value();
|
||||
}
|
||||
|
||||
template <class Tag, class V>
|
||||
std::ostream &operator<<(std::ostream &s, ValueWrapper<Tag, V> const &v) {
|
||||
s << v.value();
|
||||
return s;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace bts
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename Tag, typename Value>
|
||||
std::size_t hash<bts::utils::ValueWrapper<Tag, Value>>::operator()(
|
||||
const bts::utils::ValueWrapper<Tag, Value> &k) const {
|
||||
return hash<Value>()(k.value());
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
Reference in new issue
Block a user