-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathCommon.cpp
More file actions
57 lines (51 loc) · 1.51 KB
/
Copy pathCommon.cpp
File metadata and controls
57 lines (51 loc) · 1.51 KB
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
/*
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/
/// @file Common.cpp
/// @brief Common definitions and utilities for working with QDMI in C++.
/// @note This file will be upstreamed to the QDMI core library in the future.
#include "qdmi/common/Common.hpp"
#include <iostream>
#include <qdmi/constants.h>
#include <sstream>
#include <stdexcept>
#include <string>
namespace qdmi {
auto throwIfError(const int result, const std::string& msg) -> void {
switch (const auto res = static_cast<QDMI_STATUS>(result)) {
case QDMI_SUCCESS:
break;
case QDMI_WARN_GENERAL:
std::cerr << "Warning: " << msg << '\n';
break;
default:
std::ostringstream ss;
ss << msg << ": " << toString(res) << ".";
switch (res) {
case QDMI_ERROR_OUTOFMEM:
throw std::bad_alloc();
case QDMI_ERROR_OUTOFRANGE:
throw std::out_of_range(ss.str());
case QDMI_ERROR_INVALIDARGUMENT:
throw std::invalid_argument(ss.str());
case QDMI_ERROR_FATAL:
case QDMI_ERROR_NOTIMPLEMENTED:
case QDMI_ERROR_LIBNOTFOUND:
case QDMI_ERROR_NOTFOUND:
case QDMI_ERROR_PERMISSIONDENIED:
case QDMI_ERROR_NOTSUPPORTED:
case QDMI_ERROR_BADSTATE:
case QDMI_ERROR_TIMEOUT:
throw std::runtime_error(ss.str());
default:
throw std::runtime_error("Unknown QDMI error code. " + ss.str());
}
}
}
} // namespace qdmi