This is part of a larger effort to unify the way we index securities in order to generate unique ids. Older md sources (e.g., MDP3Listener) use SecurityIDRecorder to generate ids, which uses a different database and different key-string formatting than the IDGenerator used by the newer md sources (e.g., GeneralMarketDataListener and various ccapi-based sources).
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "lib/api/domain/SecurityType.pb.h"
|
|
#include "lib/api/domain/Venue.pb.h"
|
|
|
|
#include <OnixS/CME/MDH/Integral.h>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <optional>
|
|
|
|
namespace bts::persistence {
|
|
|
|
class IDGenerator {
|
|
public:
|
|
IDGenerator();
|
|
~IDGenerator();
|
|
IDGenerator(const IDGenerator &) = delete;
|
|
IDGenerator &operator=(const IDGenerator &) = delete;
|
|
|
|
static IDGenerator &instance();
|
|
static std::shared_ptr<IDGenerator> instance_ptr();
|
|
|
|
std::optional<uint64_t> get_id(
|
|
const api::domain::Venue &venue,
|
|
api::domain::SecurityType type,
|
|
const std::string &name,
|
|
bool add_if_new = false);
|
|
|
|
std::optional<uint64_t> get_id(
|
|
const std::string &ns, const std::string &key, bool add_if_new);
|
|
|
|
std::uint64_t get_or_add(
|
|
api::domain::Venue venue,
|
|
api::domain::SecurityType type,
|
|
const std::string &name);
|
|
|
|
private:
|
|
static std::shared_ptr<IDGenerator> instance_ptr_;
|
|
static std::mutex _instance_mx;
|
|
|
|
struct PImpl;
|
|
std::unique_ptr<PImpl> me;
|
|
|
|
// These methods are private to force callers to use the [public] overloads with venue, type and
|
|
// name params, to ensure consistent formatting.
|
|
std::uint64_t get_or_add(const std::string &ns, const std::string &key);
|
|
};
|
|
|
|
} // namespace bts::persistence
|