All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Static Public Member Functions | Private Types | Static Private Attributes | List of all members
testing::TestSharedGlobalResource< RES > Class Template Reference

Utility class providing singleton objects to the derived classes. More...

#include <unit_test_base.h>

Public Types

using ResourcePtr_t = std::shared_ptr< Resource_t >
 

Static Public Member Functions

template<typename... Args>
static ResourcePtr_t CreateResource (std::string res_name, Args &&...args)
 Constructs and registers a new resource with a specified name. More...
 
template<typename... Args>
static void CreateDefaultResource (Args &&...args)
 Constructs and registers a new resource with no name. More...
 
template<typename... Args>
static ResourcePtr_t ProposeSharedResource (std::string res_name, Args &&...args)
 Creates a shared resource only if none exists yet. More...
 
template<typename... Args>
static ResourcePtr_t ProposeDefaultSharedResource (Args &&...args)
 Creates a shared resource as default only if none exists yet. More...
 
static Resource_tDestroyResource (std::string name="")
 Destroys the specified resource (does nothing if no such resource) More...
 
Add and share resources
static void AddSharedResource (std::string res_name, ResourcePtr_t res_ptr)
 Adds a shared resource to the resource registry. More...
 
static void AddDefaultSharedResource (ResourcePtr_t res_ptr)
 Adds a shared resource to the resource registry (empty name) More...
 
template<typename... Args>
static ResourcePtr_t ProvideSharedResource (std::string res_name, ResourcePtr_t res_ptr)
 Registers a shared resource only if none exists yet. More...
 
template<typename... Args>
static ResourcePtr_t ProvideDefaultSharedResource (ResourcePtr_t res_ptr)
 Creates a shared resource as default only if none exists yet. More...
 
static bool ReplaceSharedResource (std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
 Adds a shared resource only if it is old_res_ptr. More...
 
static bool ReplaceSharedResource (std::string res_name, ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
 
static bool ReplaceDefaultSharedResource (Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
 Adds a shared resource as default resource only if it is old_res_ptr. More...
 
static bool ReplaceDefaultSharedResource (ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
 
Resource access
static bool hasResource (std::string name="")
 
static ResourcePtr_t ShareResource (std::string name="")
 Retrieves the specified resource for sharing (nullptr if none) More...
 
static Resource_tResource (std::string name="")
 Retrieves the specified resource, or throws if not available. More...
 

Private Types

using Resource_t = RES
 

Static Private Attributes

static std::map< std::string,
ResourcePtr_t
Resources
 

Detailed Description

template<typename RES>
class testing::TestSharedGlobalResource< RES >

Utility class providing singleton objects to the derived classes.


Template Parameters
RESthe type of object (include constantness if needed)

The object is expected to be shared.

Definition at line 388 of file unit_test_base.h.

Member Typedef Documentation

template<typename RES >
using testing::TestSharedGlobalResource< RES >::Resource_t = RES
private

Definition at line 389 of file unit_test_base.h.

template<typename RES >
using testing::TestSharedGlobalResource< RES >::ResourcePtr_t = std::shared_ptr<Resource_t>

Definition at line 392 of file unit_test_base.h.

Member Function Documentation

template<typename RES >
static void testing::TestSharedGlobalResource< RES >::AddDefaultSharedResource ( ResourcePtr_t  res_ptr)
inlinestatic

Adds a shared resource to the resource registry (empty name)

Definition at line 402 of file unit_test_base.h.

403  { AddSharedResource(std::string(), res_ptr); }
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static void testing::TestSharedGlobalResource< RES >::AddSharedResource ( std::string  res_name,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource to the resource registry.

Definition at line 398 of file unit_test_base.h.

399  { Resources[res_name] = res_ptr; }
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
template<typename... Args>
static void testing::TestSharedGlobalResource< RES >::CreateDefaultResource ( Args &&...  args)
inlinestatic

Constructs and registers a new resource with no name.

Definition at line 458 of file unit_test_base.h.

459  { CreateResource(std::string(), std::forward<Args>(args)...); }
static ResourcePtr_t CreateResource(std::string res_name, Args &&...args)
Constructs and registers a new resource with a specified name.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::CreateResource ( std::string  res_name,
Args &&...  args 
)
inlinestatic

Constructs and registers a new resource with a specified name.

Definition at line 449 of file unit_test_base.h.

450  {
451  ResourcePtr_t res_ptr(new Resource_t(std::forward<Args>(args)...));
452  AddSharedResource(res_name, res_ptr);
453  return res_ptr;
454  }
std::shared_ptr< Resource_t > ResourcePtr_t
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static Resource_t& testing::TestSharedGlobalResource< RES >::DestroyResource ( std::string  name = "")
inlinestatic

Destroys the specified resource (does nothing if no such resource)

Definition at line 507 of file unit_test_base.h.

508  { Resources.erase(name); }
static std::map< std::string, ResourcePtr_t > Resources
then echo fcl name
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::hasResource ( std::string  name = "")
inlinestatic

Returns whether a resource exists

Exceptions
std::out_of_rangeif not available

Definition at line 487 of file unit_test_base.h.

488  {
489  auto iRes = Resources.find(name);
490  return (iRes != Resources.end()) && bool(iRes->second);
491  }
static std::map< std::string, ResourcePtr_t > Resources
then echo fcl name
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProposeDefaultSharedResource ( Args &&...  args)
inlinestatic

Creates a shared resource as default only if none exists yet.

Definition at line 474 of file unit_test_base.h.

475  {
476  return ProposeSharedResource
477  (std::string(), std::forward<Args>(args)...);
478  }
static ResourcePtr_t ProposeSharedResource(std::string res_name, Args &&...args)
Creates a shared resource only if none exists yet.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProposeSharedResource ( std::string  res_name,
Args &&...  args 
)
inlinestatic

Creates a shared resource only if none exists yet.

Definition at line 465 of file unit_test_base.h.

466  {
467  return hasResource(res_name)?
468  ResourcePtr_t():
469  CreateResource(res_name, std::forward<Args>(args)...);
470  }
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
std::shared_ptr< Resource_t > ResourcePtr_t
static bool hasResource(std::string name="")
static ResourcePtr_t CreateResource(std::string res_name, Args &&...args)
Constructs and registers a new resource with a specified name.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProvideDefaultSharedResource ( ResourcePtr_t  res_ptr)
inlinestatic

Creates a shared resource as default only if none exists yet.

Definition at line 417 of file unit_test_base.h.

418  { return ProvideSharedResource(std::string(), res_ptr); }
static ResourcePtr_t ProvideSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Registers a shared resource only if none exists yet.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProvideSharedResource ( std::string  res_name,
ResourcePtr_t  res_ptr 
)
inlinestatic

Registers a shared resource only if none exists yet.

Definition at line 408 of file unit_test_base.h.

409  {
410  if (hasResource(res_name)) return ResourcePtr_t();
411  AddSharedResource(res_name, res_ptr);
412  return res_ptr;
413  }
std::shared_ptr< Resource_t > ResourcePtr_t
static bool hasResource(std::string name="")
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceDefaultSharedResource ( Resource_t const *  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource as default resource only if it is old_res_ptr.

Definition at line 440 of file unit_test_base.h.

441  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceDefaultSharedResource ( ResourcePtr_t  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Definition at line 443 of file unit_test_base.h.

444  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceSharedResource ( std::string  res_name,
Resource_t const *  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource only if it is old_res_ptr.

Definition at line 422 of file unit_test_base.h.

426  {
427  ResourcePtr_t current_res_ptr = ShareResource();
428  if (current_res_ptr.get() != old_res_ptr) return false;
429  AddSharedResource(res_name, res_ptr);
430  return true;
431  }
std::shared_ptr< Resource_t > ResourcePtr_t
static ResourcePtr_t ShareResource(std::string name="")
Retrieves the specified resource for sharing (nullptr if none)
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceSharedResource ( std::string  res_name,
ResourcePtr_t  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Definition at line 433 of file unit_test_base.h.

434  { return ReplaceSharedResource(res_name, old_res_ptr.get(), res_ptr); }
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static Resource_t& testing::TestSharedGlobalResource< RES >::Resource ( std::string  name = "")
inlinestatic

Retrieves the specified resource, or throws if not available.

Definition at line 501 of file unit_test_base.h.

502  { return *(Resources.at(name).get()); }
static std::map< std::string, ResourcePtr_t > Resources
then echo fcl name
template<typename RES >
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ShareResource ( std::string  name = "")
inlinestatic

Retrieves the specified resource for sharing (nullptr if none)

Definition at line 494 of file unit_test_base.h.

495  {
496  auto iRes = Resources.find(name);
497  return (iRes == Resources.end())? ResourcePtr_t(): iRes->second;
498  }
std::shared_ptr< Resource_t > ResourcePtr_t
static std::map< std::string, ResourcePtr_t > Resources
then echo fcl name

Member Data Documentation

template<typename RES >
std::map< std::string, typename TestSharedGlobalResource< RES >::ResourcePtr_t > testing::TestSharedGlobalResource< RES >::Resources
staticprivate

Definition at line 511 of file unit_test_base.h.


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