Public Member Functions | Private Attributes | List of all members
cet::sqlite::ConnectionFactory Class Reference

#include <ConnectionFactory.h>

Public Member Functions

template<typename DatabaseOpenPolicy = detail::DefaultDatabaseOpenPolicy, typename... PolicyArgs>
auto make_connection (std::string const &file_name, PolicyArgs &&...) -> Connection *
 
template<typename DatabaseOpenPolicy , typename... PolicyArgs>
auto make_connection (std::string const &filename, PolicyArgs &&...policyArgs) -> Connection *
 

Private Attributes

std::map< std::string, std::weak_ptr< std::recursive_mutex > > databaseLocks_
 
std::recursive_mutex mutex_
 

Detailed Description

Definition at line 43 of file ConnectionFactory.h.

Member Function Documentation

template<typename DatabaseOpenPolicy = detail::DefaultDatabaseOpenPolicy, typename... PolicyArgs>
auto cet::sqlite::ConnectionFactory::make_connection ( std::string const &  file_name,
PolicyArgs &&  ... 
) -> Connection *
template<typename DatabaseOpenPolicy , typename... PolicyArgs>
auto cet::sqlite::ConnectionFactory::make_connection ( std::string const &  filename,
PolicyArgs &&...  policyArgs 
) -> Connection*

Definition at line 57 of file ConnectionFactory.h.

59  {
60  // Implementation a la Herb Sutter's favorite 10-liner
61  std::lock_guard sentry{mutex_};
62  // Note: Convert the weak_ptr to a shared_ptr using the member
63  // function lock(), this is not an operation on the mutex.
64  auto shared_ptr_to_mutex = databaseLocks_[filename].lock();
65  if (!shared_ptr_to_mutex) {
66  using namespace std::string_literals;
67  databaseLocks_[filename] = shared_ptr_to_mutex =
68  std::make_shared<std::recursive_mutex>();
69  }
70  auto ret = new Connection{
71  filename,
72  shared_ptr_to_mutex,
73  DatabaseOpenPolicy{std::forward<PolicyArgs>(policyArgs)...}};
74  return ret;
75  }
string filename
Definition: train.py:213
std::map< std::string, std::weak_ptr< std::recursive_mutex > > databaseLocks_

Member Data Documentation

std::map<std::string, std::weak_ptr<std::recursive_mutex> > cet::sqlite::ConnectionFactory::databaseLocks_
private

Definition at line 51 of file ConnectionFactory.h.

std::recursive_mutex cet::sqlite::ConnectionFactory::mutex_
private

Definition at line 52 of file ConnectionFactory.h.


The documentation for this class was generated from the following file: