Intel clGPU
primitive_db.hpp
1 // Copyright (c) 2017-2018 Intel Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 #include <unordered_map>
17 #include <initializer_list>
18 #include <algorithm>
19 #include <string>
20 
21 namespace iclgpu
22 {
25 {
26 public:
27  using db_type = std::unordered_map<std::string, std::string>;
28  using value_type = db_type::value_type;
29 
30  virtual ~primitive_db() = default;
31 
33  std::string get(const std::string& id);
34 
35 
37  virtual void insert(const value_type& value);
38 
40  template <class InputIt>
41  std::enable_if_t<std::is_convertible<decltype(*std::declval<InputIt>()), value_type>::value>
42  insert_range(InputIt first, InputIt last)
43  {
44  std::for_each(first, last, [this](const value_type& p) -> void { insert(p); });
45  }
46 
48  template <class Range>
49  std::enable_if_t<std::is_convertible<decltype(*std::cbegin(std::declval<Range>())), value_type>::value>
50  insert(const Range& range)
51  {
52  insert_range(std::cbegin(range), std::cend(range));
53  }
54 
56  void insert(const std::initializer_list<value_type>& ilist)
57  {
58  insert_range(std::cbegin(ilist), std::cend(ilist));
59  }
60 
61 protected:
62  db_type _db;
63 };
64 
65 }
std::enable_if_t< std::is_convertible< decltype(*std::declval< InputIt >)), value_type >::value > insert_range(InputIt first, InputIt last)
Add kernel sources to the DB.
void insert(const std::initializer_list< value_type > &ilist)
Add kernel sources to the DB.
Helper class to store kernel sources.
virtual void insert(const value_type &value)
Add kernel source to the DB.
std::enable_if_t< std::is_convertible< decltype(*std::cbegin(std::declval< Range >))), value_type >::value > insert(const Range &range)
Add kernel sources to the DB.