-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathskuwa_factory.h
104 lines (93 loc) · 3.28 KB
/
skuwa_factory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file skuwa_factory.h
//! \brief Defines one template class for the management of SKU/WA/SystemInfo
//!
#ifndef _SKUWA_FACTORY_H_
#define _SKUWA_FACTORY_H_
#include <map>
#include <vector>
#include <utility>
#include <cstdarg>
#include <cstdint>
#include "media_class_trace.h"
//!
//! \class DeviceInfoFactory
//! \brief Device info factory
//!
template <class T>
class DeviceInfoFactory
{
public:
typedef T* Type;
typedef uint32_t KeyType;
typedef std::map<KeyType, Type> Creators;
typedef typename Creators::iterator iterator;
//!
//! \brief register one value with key.
//!
//! \param [in] key
//! KeyType, the type alias of uint32_t
//! \param [in] value
//! T *, the type of info related with key
//!
//!
//! \return true is returned if it is successfully registerted with @param key
//! false is returned if @param key is already registered and doesn't register
//!
static bool RegisterDevice(KeyType key, Type value)
{
std::pair<iterator, bool> result = GetCreators().emplace(key, value);
return result.second;
}
//!
//! \brief Get the pointer of DeviceInfo registered with key.
//!
//! \param [in] key
//! KeyType, the type alias of std::string.
//!
//! \return the pointer of DeviceInfo is returned if @param key is found.
//! nullptr is returned if @param key is not found
//!
static Type LookupDevice(KeyType key)
{
Creators &creators = GetCreators();
iterator creator = creators.find(key);
if (creator != creators.end())
return creator->second;
return nullptr;
}
private:
//!
//! \brief obtain the static pair table of param@ key and callback function
//! \details obtain the static pair table that is registerted with key and callback function
//!
//! \return return the static pair table about the param @key and callback function
static Creators &GetCreators()
{
static Creators creators;
return creators;
}
MEDIA_CLASS_DEFINE_END(DeviceInfoFactory)
};
#endif /* _SKUWA_FACTORY_H_ */