10Duke Enterprise C++ SDK
Toggle main menu visibility
Loading...
Searching...
No Matches
OneItemPerName.h
1
#ifndef TENDUKE_EE_LICENSING_IMPL_ONEITEMPERNAME_H
2
#define TENDUKE_EE_LICENSING_IMPL_ONEITEMPERNAME_H
3
4
#include "log/log.h"
5
6
#include <cstddef>
7
#include <map>
8
#include <string>
9
#include <vector>
10
11
namespace
tenduke
{
namespace
ee
{
namespace
licensing
{
namespace
impl
{
12
27
template
<
typename
ITEM>
28
std::vector<ITEM>
oneItemPerName
(
const
std::vector<ITEM> &items,
const
char
*requestType)
29
{
30
std::map<std::string, std::size_t> lastIndexByName;
31
std::map<std::string, std::size_t> countByName;
32
for
(std::size_t i = 0; i < items.size(); ++i) {
33
lastIndexByName[items[i].name] = i;
34
++countByName[items[i].name];
35
}
36
if
(lastIndexByName.size() == items.size()) {
37
return
items;
38
}
39
40
std::vector<ITEM> result;
41
result.reserve(lastIndexByName.size());
42
for
(
const
auto
&item : items) {
43
const
auto
lastIndex = lastIndexByName.find(item.name);
44
if
(lastIndex == lastIndexByName.end()) {
45
continue
;
// Already added
46
}
47
result.push_back(items[lastIndex->second]);
48
lastIndexByName.erase(lastIndex);
49
50
const
auto
count = countByName[item.name];
51
if
(count > 1) {
52
::tenduke::log::warning
(
53
std::string(
"The "
) + requestType +
" request names licensed item \""
+ item.name +
"\" "
54
+ std::to_string(count) +
" times: a response has at most one lease per licensed item. Sending "
55
+
"only the last one"
56
);
57
}
58
}
59
return
result;
60
}
61
62
}}}}
63
64
#endif
//TENDUKE_EE_LICENSING_IMPL_ONEITEMPERNAME_H
tenduke::ee::licensing::impl
Implementations of licensing related services.
Definition
DefaultLicenseTokens.h:21
tenduke::ee::licensing::impl::oneItemPerName
std::vector< ITEM > oneItemPerName(const std::vector< ITEM > &items, const char *requestType)
Returns the items with one item per licensed item name: if a name occurs several times,...
Definition
OneItemPerName.h:28
tenduke::ee::licensing
Classes, functions and globals related to 10Duke Enterprise licensing.
Definition
AuthzLicensingClient.h:13
tenduke::ee
Classes, functions and globals of 10Duke Enterprise C++ Client.
Definition
APIRequest.h:4
tenduke::log::warning
void warning(const char *message)
Write message to global logger at WARNING-level.
Definition
log.cpp:106
tenduke
Root for classes, functions and globals of 10Duke C++ Client.
Definition
APIRequest.h:4
client
enterprise
api
src
licensing
impl
OneItemPerName.h
Generated by
1.17.0