Line data Source code
1 : #pragma once 2 : 3 : namespace Envoy { 4 : 5 : /** 6 : * ConstSingleton allows easy global cross-thread access to a const object. 7 : * 8 : * This singleton should be used for data which is initialized once at 9 : * start-up and then be treated as immutable const data thereafter. 10 : */ 11 : template <class T> class ConstSingleton { 12 : public: 13 : /** 14 : * Obtain an instance of the singleton for class T. 15 : * @return const T& a reference to the singleton for class T. 16 : */ 17 700306 : static const T& get() { 18 700306 : static T* instance = new T(); 19 700306 : return *instance; 20 700306 : } 21 : }; 22 : 23 : } // namespace Envoy