Ocean
Loading...
Searching...
No Matches
TestDataManager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TEST_DATA_MANAGER_H
9#define META_OCEAN_TEST_TEST_DATA_MANAGER_H
10
11#include "ocean/test/Test.h"
13
14#include "ocean/base/Lock.h"
17
18namespace Ocean
19{
20
21namespace Test
22{
23
24/**
25 * The class implements the manager for test data collections as a singleton object.
26 * @ingroup test
27 */
28class OCEAN_TEST_EXPORT TestDataManager : public Singleton<TestDataManager>
29{
30 friend class Singleton<TestDataManager>;
31 friend class TestDataCollection;
32
33 public:
34
35 /**
36 * Definition of a scoped subscription object for for data collections.
37 */
39
40 /**
41 * Definition of a vector holding scoped subscription objects.
42 */
43 using ScopedSubscriptions = std::vector<ScopedSubscription>;
44
45 protected:
46
47 /**
48 * Definition of a pair combining a counter with a shared pointer.
49 */
50 using TestDataCollectionPair = std::pair<unsigned int, std::shared_ptr<TestDataCollection>>;
51
52 /**
53 * Definition of an unordered map mapping collection names to collection objects.
54 */
55 using TestDataCollectionMap = std::unordered_map<std::string, TestDataCollectionPair>;
56
57 public:
58
59 /**
60 * Returns a specific test data collection.
61 * @param name The name of the test data collection to return, must be valid
62 * @return The requested test data collection, nullptr if it does not exist
63 */
64 SharedTestDataCollection testDataCollection(const std::string& name) const;
65
66 /**
67 * Registers a new test data collection.
68 * @param name The name of the new collection, be valid, must not exist already
69 * @param testDataCollection The new test data collection to register, must be valid
70 * @return The scoped subscription object associated with the data collection, the collection will be registered as long as the scoped subscription object exists
71 */
72 [[nodiscard]] ScopedSubscription registerTestDataCollection(const std::string& name, std::unique_ptr<TestDataCollection>&& testDataCollection);
73
74 protected:
75
76 /**
77 * Protected default constructor.
78 */
80
81 /**
82 * Unregisters a registered data collection.
83 * @param name The name of the data collection to unregister, must be valid
84 */
85 void unregisterTestDataCollection(const std::string& name);
86
87 protected:
88
89 /// The map mapping collection names to collection objects.
91
92 /// The manager's lock.
93 mutable Lock lock_;
94};
95
96}
97
98}
99
100#endif // META_OCEAN_TEST_TEST_DATA_MANAGER_H
This class implements a recursive lock object.
Definition Lock.h:31
This class implements a subscription object which can be used unique subscriptions to e....
Definition ScopedSubscription.h:28
This template class is the base class for all singleton objects.
Definition Singleton.h:71
This class is the base class for all TestDataCollection objects.
Definition TestDataCollection.h:35
The class implements the manager for test data collections as a singleton object.
Definition TestDataManager.h:29
TestDataCollectionMap testDataCollectionMap_
The map mapping collection names to collection objects.
Definition TestDataManager.h:90
Lock lock_
The manager's lock.
Definition TestDataManager.h:93
std::vector< ScopedSubscription > ScopedSubscriptions
Definition of a vector holding scoped subscription objects.
Definition TestDataManager.h:43
std::unordered_map< std::string, TestDataCollectionPair > TestDataCollectionMap
Definition of an unordered map mapping collection names to collection objects.
Definition TestDataManager.h:55
ScopedSubscription registerTestDataCollection(const std::string &name, std::unique_ptr< TestDataCollection > &&testDataCollection)
Registers a new test data collection.
std::pair< unsigned int, std::shared_ptr< TestDataCollection > > TestDataCollectionPair
Definition of a pair combining a counter with a shared pointer.
Definition TestDataManager.h:50
SharedTestDataCollection testDataCollection(const std::string &name) const
Returns a specific test data collection.
void unregisterTestDataCollection(const std::string &name)
Unregisters a registered data collection.
TestDataManager()
Protected default constructor.
std::shared_ptr< TestDataCollection > SharedTestDataCollection
Definition of a shared pointer holding data TestDataCollection object.
Definition TestDataCollection.h:27
The namespace covering the entire Ocean framework.
Definition Accessor.h:15