#pragma once #include #include "String.DString.hpp" #include "String.WString.hpp" using namespace eSTR::Literals; #include "DDateTime.hpp" #ifndef LOCALE_EXPORTS #define _Localet_API _declspec(dllimport) #else #define _Localet_API _declspec(dllexport) #endif #ifndef LOCALE_EXPORTS #ifdef _WIN64 #ifdef _DEBUG #pragma comment (lib, "ECOM.Utility.Locale64D.lib") #else #pragma comment (lib, "ECOM.Utility.Locale64.lib") #endif #else // X86 #ifdef _DEBUG #pragma comment (lib, "ECOM.Utility.LocaleD.lib") #else #pragma comment (lib, "ECOM.Utility.Locale.lib") #endif #endif #endif // LOCALE_EXPORTS namespace ECOM { namespace Utility { class LocaleFormat : public ECOM::Utility::String::_string_format_detail { _locale_t m_Locale; public: inline LocaleFormat (char * buf, int NbOfChar, _locale_t loc) : _string_format_detail (buf, NbOfChar) { m_Locale = loc; } public: template inline int _my_sprintf (char * buf, int NbOfChar, const char * fmt, arg a) { return _sprintf_s_l (buf, NbOfChar, fmt, m_Locale, a); } }; //----------------------------------------------------------------------------- // Locale //----------------------------------------------------------------------------- class _Localet_API Locale { template static constexpr bool dependent_false = false; public: static Locale FromOS (); public: Locale (CV_String & Name); Locale (const eSTR::DString & Name); ~Locale (); public: Locale (const Locale & from) = delete; Locale (Locale && from); Locale & operator = (const Locale & from) = delete; Locale & operator = (Locale && from); public: template inline eSTR::DString ToString (const char * szFormat, Args... args) const { constexpr int MaxLen = 8192; eSTR::DString rc; auto pc = rc.GetBufferSetLength (MaxLen); auto len = ECOM::Utility::LocaleFormat (pc, MaxLen, m_Locale).Format (szFormat, args...); rc.ReleaseBuffer (len); return std::move (rc); } public: enum enDateTime { enShortDate = 1, enLongDate = 2, enShortTime = 3, enLongTime = 4 }; public: eSTR::WString ToString (const DDateTime & dt, enDateTime type) const; eSTR::WString ToString (const DDateTime & dt, CV_String & fmt) const; public: template static T GetFormatOf (enDateTime type) { static_assert (dependent_false ); } template <> static eSTR::WStringView GetFormatOf (enDateTime type); template <> static eSTR::DStringView GetFormatOf (enDateTime type); public: eSTR::DString GetName () const; _locale_t GetLocale () const; private: eSTR::DString m_LocName; _locale_t m_Locale; }; } }