#pragma once #include "of_def.hpp" #include #include #include #include #include #include #include namespace ofen { template class OfSingleton { public: OfSingleton(const OfSingleton&) = delete; OfSingleton& operator=(const OfSingleton&) = delete; static std::shared_ptr getInstance() { std::call_once(init_flag, []() { instance.reset(new T()); }); return instance; } protected: OfSingleton() = default; virtual ~OfSingleton() = default; private: static std::shared_ptr instance; static std::once_flag init_flag; }; template std::shared_ptr OfSingleton::instance = nullptr; template std::once_flag OfSingleton::init_flag; class CMutBuffer { public: CMutBuffer() = default; public: void push(const char* data, int len); int index_of(const char* data, int len, int start_pos = 0); const char* get_data() const; int get_len() const; void remove_of(int start_pos, int len); void clear(); private: std::vector buffer_; std::mutex mutex_; }; } // namespace ofen