mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-24 18:50:49 +00:00
![Ivan](/assets/img/avatar_default.png)
* Add support for darwin-aarch64 * Fix PVS warnings * Add build configuration * Fix packager args
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "DateLUTImpl.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <atomic>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <unordered_map>
|
|
|
|
|
|
/// This class provides lazy initialization and lookup of singleton DateLUTImpl objects for a given timezone.
|
|
class DateLUT : private boost::noncopyable
|
|
{
|
|
public:
|
|
/// Return singleton DateLUTImpl instance for the default time zone.
|
|
static ALWAYS_INLINE const DateLUTImpl & instance() // -V1071
|
|
{
|
|
const auto & date_lut = getInstance();
|
|
return *date_lut.default_impl.load(std::memory_order_acquire);
|
|
}
|
|
|
|
/// Return singleton DateLUTImpl instance for a given time zone.
|
|
static ALWAYS_INLINE const DateLUTImpl & instance(const std::string & time_zone)
|
|
{
|
|
const auto & date_lut = getInstance();
|
|
if (time_zone.empty())
|
|
return *date_lut.default_impl.load(std::memory_order_acquire);
|
|
|
|
return date_lut.getImplementation(time_zone);
|
|
}
|
|
static void setDefaultTimezone(const std::string & time_zone)
|
|
{
|
|
auto & date_lut = getInstance();
|
|
const auto & impl = date_lut.getImplementation(time_zone);
|
|
date_lut.default_impl.store(&impl, std::memory_order_release);
|
|
}
|
|
|
|
protected:
|
|
DateLUT();
|
|
|
|
private:
|
|
static DateLUT & getInstance();
|
|
|
|
const DateLUTImpl & getImplementation(const std::string & time_zone) const;
|
|
|
|
using DateLUTImplPtr = std::unique_ptr<DateLUTImpl>;
|
|
|
|
/// Time zone name -> implementation.
|
|
mutable std::unordered_map<std::string, DateLUTImplPtr> impls;
|
|
mutable std::mutex mutex;
|
|
|
|
std::atomic<const DateLUTImpl *> default_impl;
|
|
};
|