Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // Copyright 2019-2022 Cambridge Quantum Computing | |||
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 | #include <map> | |||
16 | #include <string> | |||
17 | ||||
18 | #include "OpType.hpp" | |||
19 | #include "OpTypeInfo.hpp" | |||
20 | ||||
21 | namespace tket { | |||
22 | ||||
23 | // map from OpType name to OpType | |||
24 | // Relies on unique OpType names. | |||
25 | 7630 | const std::map<std::string, OpType>& name_to_optype() { | ||
26 | 1 | auto mapfiller = []() { | ||
27 | 1 | std::map<std::string, OpType> fill_map; | ||
28 |
3/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 96 times.
✓ Branch 8 taken 1 times.
|
0/1? Decision couldn't be analyzed.
|
97 | for (const auto& info : optypeinfo()) { |
29 |
2/4✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 96 times.
✗ Branch 5 not taken.
|
96 | fill_map.insert({info.second.name, info.first}); | |
30 | } | |||
31 | 1 | return fill_map; | ||
32 | ✗ | }; | ||
33 | static auto final_map = | |||
34 |
5/10✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7629 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
7630 | std::make_unique<const std::map<std::string, OpType>>(mapfiller()); | |
35 | 15260 | return *final_map; | ||
36 | } | |||
37 | ||||
38 | 433 | void to_json(nlohmann::json& j, const OpType& type) { | ||
39 | 433 | j = optypeinfo().at(type).name; | ||
40 | 433 | } | ||
41 | ||||
42 | 3815 | void from_json(const nlohmann::json& j, OpType& type) { | ||
43 |
1/2✓ Branch 1 taken 3815 times.
✗ Branch 2 not taken.
|
3815 | const std::string name = j.get<std::string>(); | |
44 |
2/4✓ Branch 1 taken 3815 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3815 times.
✗ Branch 5 not taken.
|
3815 | const auto result = name_to_optype().find(name); | |
45 |
3/4✓ Branch 1 taken 3815 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 3814 times.
|
2/2✓ Decision 'true' taken 1 times.
✓ Decision 'false' taken 3814 times.
|
3815 | if (result == name_to_optype().end()) { |
46 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | throw JsonError("No OpType with name " + name); | |
47 | } | |||
48 | ||||
49 | 3814 | type = result->second; | ||
50 | 3815 | } | ||
51 | ||||
52 | } // namespace tket | |||
53 |