mqt-core 3.3.2__cp314-cp314t-macosx_11_0_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mqt/core/__init__.py +77 -0
- mqt/core/__main__.py +55 -0
- mqt/core/_commands.py +52 -0
- mqt/core/_compat/__init__.py +11 -0
- mqt/core/_compat/typing.py +29 -0
- mqt/core/_version.py +34 -0
- mqt/core/_version.pyi +12 -0
- mqt/core/dd.cpython-314t-darwin.so +0 -0
- mqt/core/dd.pyi +1016 -0
- mqt/core/dd_evaluation.py +368 -0
- mqt/core/fomac.cpython-314t-darwin.so +0 -0
- mqt/core/fomac.pyi +125 -0
- mqt/core/include/mqt-core/algorithms/BernsteinVazirani.hpp +39 -0
- mqt/core/include/mqt-core/algorithms/GHZState.hpp +18 -0
- mqt/core/include/mqt-core/algorithms/Grover.hpp +33 -0
- mqt/core/include/mqt-core/algorithms/QFT.hpp +21 -0
- mqt/core/include/mqt-core/algorithms/QPE.hpp +30 -0
- mqt/core/include/mqt-core/algorithms/RandomCliffordCircuit.hpp +22 -0
- mqt/core/include/mqt-core/algorithms/StatePreparation.hpp +43 -0
- mqt/core/include/mqt-core/algorithms/WState.hpp +18 -0
- mqt/core/include/mqt-core/algorithms/mqt_core_algorithms_export.h +43 -0
- mqt/core/include/mqt-core/boost/config/abi/borland_prefix.hpp +27 -0
- mqt/core/include/mqt-core/boost/config/abi/borland_suffix.hpp +12 -0
- mqt/core/include/mqt-core/boost/config/abi/msvc_prefix.hpp +22 -0
- mqt/core/include/mqt-core/boost/config/abi/msvc_suffix.hpp +8 -0
- mqt/core/include/mqt-core/boost/config/abi_prefix.hpp +25 -0
- mqt/core/include/mqt-core/boost/config/abi_suffix.hpp +25 -0
- mqt/core/include/mqt-core/boost/config/assert_cxx03.hpp +211 -0
- mqt/core/include/mqt-core/boost/config/assert_cxx11.hpp +212 -0
- mqt/core/include/mqt-core/boost/config/assert_cxx14.hpp +47 -0
- mqt/core/include/mqt-core/boost/config/assert_cxx17.hpp +65 -0
- mqt/core/include/mqt-core/boost/config/assert_cxx20.hpp +59 -0
- mqt/core/include/mqt-core/boost/config/assert_cxx23.hpp +41 -0
- mqt/core/include/mqt-core/boost/config/assert_cxx98.hpp +23 -0
- mqt/core/include/mqt-core/boost/config/auto_link.hpp +525 -0
- mqt/core/include/mqt-core/boost/config/compiler/borland.hpp +342 -0
- mqt/core/include/mqt-core/boost/config/compiler/clang.hpp +370 -0
- mqt/core/include/mqt-core/boost/config/compiler/clang_version.hpp +89 -0
- mqt/core/include/mqt-core/boost/config/compiler/codegear.hpp +389 -0
- mqt/core/include/mqt-core/boost/config/compiler/comeau.hpp +59 -0
- mqt/core/include/mqt-core/boost/config/compiler/common_edg.hpp +185 -0
- mqt/core/include/mqt-core/boost/config/compiler/compaq_cxx.hpp +19 -0
- mqt/core/include/mqt-core/boost/config/compiler/cray.hpp +446 -0
- mqt/core/include/mqt-core/boost/config/compiler/diab.hpp +26 -0
- mqt/core/include/mqt-core/boost/config/compiler/digitalmars.hpp +146 -0
- mqt/core/include/mqt-core/boost/config/compiler/gcc.hpp +386 -0
- mqt/core/include/mqt-core/boost/config/compiler/gcc_xml.hpp +115 -0
- mqt/core/include/mqt-core/boost/config/compiler/greenhills.hpp +28 -0
- mqt/core/include/mqt-core/boost/config/compiler/hp_acc.hpp +153 -0
- mqt/core/include/mqt-core/boost/config/compiler/intel.hpp +577 -0
- mqt/core/include/mqt-core/boost/config/compiler/kai.hpp +33 -0
- mqt/core/include/mqt-core/boost/config/compiler/metrowerks.hpp +201 -0
- mqt/core/include/mqt-core/boost/config/compiler/mpw.hpp +143 -0
- mqt/core/include/mqt-core/boost/config/compiler/nvcc.hpp +64 -0
- mqt/core/include/mqt-core/boost/config/compiler/pathscale.hpp +141 -0
- mqt/core/include/mqt-core/boost/config/compiler/pgi.hpp +23 -0
- mqt/core/include/mqt-core/boost/config/compiler/sgi_mipspro.hpp +29 -0
- mqt/core/include/mqt-core/boost/config/compiler/sunpro_cc.hpp +225 -0
- mqt/core/include/mqt-core/boost/config/compiler/vacpp.hpp +189 -0
- mqt/core/include/mqt-core/boost/config/compiler/visualc.hpp +398 -0
- mqt/core/include/mqt-core/boost/config/compiler/xlcpp.hpp +303 -0
- mqt/core/include/mqt-core/boost/config/compiler/xlcpp_zos.hpp +174 -0
- mqt/core/include/mqt-core/boost/config/detail/cxx_composite.hpp +218 -0
- mqt/core/include/mqt-core/boost/config/detail/posix_features.hpp +95 -0
- mqt/core/include/mqt-core/boost/config/detail/select_compiler_config.hpp +157 -0
- mqt/core/include/mqt-core/boost/config/detail/select_platform_config.hpp +147 -0
- mqt/core/include/mqt-core/boost/config/detail/select_stdlib_config.hpp +121 -0
- mqt/core/include/mqt-core/boost/config/detail/suffix.hpp +1334 -0
- mqt/core/include/mqt-core/boost/config/header_deprecated.hpp +26 -0
- mqt/core/include/mqt-core/boost/config/helper_macros.hpp +37 -0
- mqt/core/include/mqt-core/boost/config/no_tr1/cmath.hpp +28 -0
- mqt/core/include/mqt-core/boost/config/no_tr1/complex.hpp +28 -0
- mqt/core/include/mqt-core/boost/config/no_tr1/functional.hpp +28 -0
- mqt/core/include/mqt-core/boost/config/no_tr1/memory.hpp +28 -0
- mqt/core/include/mqt-core/boost/config/no_tr1/utility.hpp +28 -0
- mqt/core/include/mqt-core/boost/config/platform/aix.hpp +33 -0
- mqt/core/include/mqt-core/boost/config/platform/amigaos.hpp +15 -0
- mqt/core/include/mqt-core/boost/config/platform/beos.hpp +26 -0
- mqt/core/include/mqt-core/boost/config/platform/bsd.hpp +83 -0
- mqt/core/include/mqt-core/boost/config/platform/cloudabi.hpp +18 -0
- mqt/core/include/mqt-core/boost/config/platform/cray.hpp +18 -0
- mqt/core/include/mqt-core/boost/config/platform/cygwin.hpp +71 -0
- mqt/core/include/mqt-core/boost/config/platform/haiku.hpp +31 -0
- mqt/core/include/mqt-core/boost/config/platform/hpux.hpp +87 -0
- mqt/core/include/mqt-core/boost/config/platform/irix.hpp +31 -0
- mqt/core/include/mqt-core/boost/config/platform/linux.hpp +106 -0
- mqt/core/include/mqt-core/boost/config/platform/macos.hpp +87 -0
- mqt/core/include/mqt-core/boost/config/platform/qnxnto.hpp +31 -0
- mqt/core/include/mqt-core/boost/config/platform/solaris.hpp +31 -0
- mqt/core/include/mqt-core/boost/config/platform/symbian.hpp +97 -0
- mqt/core/include/mqt-core/boost/config/platform/vms.hpp +25 -0
- mqt/core/include/mqt-core/boost/config/platform/vxworks.hpp +422 -0
- mqt/core/include/mqt-core/boost/config/platform/wasm.hpp +23 -0
- mqt/core/include/mqt-core/boost/config/platform/win32.hpp +90 -0
- mqt/core/include/mqt-core/boost/config/platform/zos.hpp +32 -0
- mqt/core/include/mqt-core/boost/config/pragma_message.hpp +31 -0
- mqt/core/include/mqt-core/boost/config/requires_threads.hpp +92 -0
- mqt/core/include/mqt-core/boost/config/stdlib/dinkumware.hpp +324 -0
- mqt/core/include/mqt-core/boost/config/stdlib/libcomo.hpp +93 -0
- mqt/core/include/mqt-core/boost/config/stdlib/libcpp.hpp +180 -0
- mqt/core/include/mqt-core/boost/config/stdlib/libstdcpp3.hpp +482 -0
- mqt/core/include/mqt-core/boost/config/stdlib/modena.hpp +79 -0
- mqt/core/include/mqt-core/boost/config/stdlib/msl.hpp +98 -0
- mqt/core/include/mqt-core/boost/config/stdlib/roguewave.hpp +208 -0
- mqt/core/include/mqt-core/boost/config/stdlib/sgi.hpp +168 -0
- mqt/core/include/mqt-core/boost/config/stdlib/stlport.hpp +258 -0
- mqt/core/include/mqt-core/boost/config/stdlib/vacpp.hpp +74 -0
- mqt/core/include/mqt-core/boost/config/stdlib/xlcpp_zos.hpp +61 -0
- mqt/core/include/mqt-core/boost/config/user.hpp +133 -0
- mqt/core/include/mqt-core/boost/config/warning_disable.hpp +47 -0
- mqt/core/include/mqt-core/boost/config/workaround.hpp +305 -0
- mqt/core/include/mqt-core/boost/config.hpp +67 -0
- mqt/core/include/mqt-core/boost/cstdint.hpp +556 -0
- mqt/core/include/mqt-core/boost/cxx11_char_types.hpp +70 -0
- mqt/core/include/mqt-core/boost/detail/workaround.hpp +10 -0
- mqt/core/include/mqt-core/boost/limits.hpp +146 -0
- mqt/core/include/mqt-core/boost/multiprecision/complex128.hpp +24 -0
- mqt/core/include/mqt-core/boost/multiprecision/complex_adaptor.hpp +1046 -0
- mqt/core/include/mqt-core/boost/multiprecision/concepts/mp_number_archetypes.hpp +257 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_bin_float/io.hpp +698 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_bin_float/transcendental.hpp +157 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_bin_float.hpp +2297 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_complex.hpp +12 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_dec_float.hpp +3690 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/add.hpp +368 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/add_unsigned.hpp +387 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/bitwise.hpp +889 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/checked.hpp +178 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/comparison.hpp +374 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/cpp_int_config.hpp +161 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/divide.hpp +703 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/import_export.hpp +248 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/intel_intrinsics.hpp +138 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/limits.hpp +282 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/literals.hpp +295 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/misc.hpp +1457 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/multiply.hpp +848 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/serialize.hpp +211 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int/value_pack.hpp +42 -0
- mqt/core/include/mqt-core/boost/multiprecision/cpp_int.hpp +2360 -0
- mqt/core/include/mqt-core/boost/multiprecision/debug_adaptor.hpp +760 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/assert.hpp +29 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/atomic.hpp +62 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/bitscan.hpp +317 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/check_cpp11_config.hpp +64 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/constexpr.hpp +88 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/default_ops.hpp +4052 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/digits.hpp +49 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/dynamic_array.hpp +44 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/empty_value.hpp +87 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/endian.hpp +35 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/et_ops.hpp +1831 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/float128_functions.hpp +95 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/float_string_cvt.hpp +333 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/fpclassify.hpp +101 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/functions/constants.hpp +288 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/functions/pow.hpp +905 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/functions/trig.hpp +1058 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/functions/trunc.hpp +82 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/generic_interconvert.hpp +687 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/hash.hpp +56 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/integer_ops.hpp +474 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/itos.hpp +39 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/min_max.hpp +106 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/no_et_ops.hpp +661 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/no_exceptions_support.hpp +55 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/number_base.hpp +1656 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/number_compare.hpp +848 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/precision.hpp +313 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/rebind.hpp +19 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/standalone_config.hpp +148 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/static_array.hpp +42 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/string_helpers.hpp +48 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/tables.hpp +80 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/ublas_interop.hpp +75 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/uniform_int_distribution.hpp +212 -0
- mqt/core/include/mqt-core/boost/multiprecision/detail/utype_helper.hpp +374 -0
- mqt/core/include/mqt-core/boost/multiprecision/eigen.hpp +248 -0
- mqt/core/include/mqt-core/boost/multiprecision/float128.hpp +920 -0
- mqt/core/include/mqt-core/boost/multiprecision/fwd.hpp +268 -0
- mqt/core/include/mqt-core/boost/multiprecision/gmp.hpp +4060 -0
- mqt/core/include/mqt-core/boost/multiprecision/integer.hpp +363 -0
- mqt/core/include/mqt-core/boost/multiprecision/logged_adaptor.hpp +834 -0
- mqt/core/include/mqt-core/boost/multiprecision/miller_rabin.hpp +221 -0
- mqt/core/include/mqt-core/boost/multiprecision/mpc.hpp +1721 -0
- mqt/core/include/mqt-core/boost/multiprecision/mpfi.hpp +2559 -0
- mqt/core/include/mqt-core/boost/multiprecision/mpfr.hpp +3644 -0
- mqt/core/include/mqt-core/boost/multiprecision/number.hpp +2500 -0
- mqt/core/include/mqt-core/boost/multiprecision/random.hpp +23 -0
- mqt/core/include/mqt-core/boost/multiprecision/rational_adaptor.hpp +1289 -0
- mqt/core/include/mqt-core/boost/multiprecision/tommath.hpp +1034 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/explicit_conversion.hpp +67 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/extract_exponent_type.hpp +28 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/is_backend.hpp +91 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/is_byte_container.hpp +51 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/is_complex.hpp +22 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/is_convertible_arithmetic.hpp +51 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/is_restricted_conversion.hpp +47 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/is_variable_precision.hpp +25 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/max_digits10.hpp +79 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/std_integer_traits.hpp +90 -0
- mqt/core/include/mqt-core/boost/multiprecision/traits/transcendental_reduction_type.hpp +21 -0
- mqt/core/include/mqt-core/boost/version.hpp +32 -0
- mqt/core/include/mqt-core/circuit_optimizer/CircuitOptimizer.hpp +119 -0
- mqt/core/include/mqt-core/circuit_optimizer/mqt_core_circuit_optimizer_export.h +43 -0
- mqt/core/include/mqt-core/datastructures/DirectedAcyclicGraph.hpp +117 -0
- mqt/core/include/mqt-core/datastructures/DirectedGraph.hpp +158 -0
- mqt/core/include/mqt-core/datastructures/DisjointSet.hpp +50 -0
- mqt/core/include/mqt-core/datastructures/Layer.hpp +172 -0
- mqt/core/include/mqt-core/datastructures/SymmetricMatrix.hpp +57 -0
- mqt/core/include/mqt-core/datastructures/UndirectedGraph.hpp +227 -0
- mqt/core/include/mqt-core/datastructures/mqt_core_ds_export.h +43 -0
- mqt/core/include/mqt-core/dd/Approximation.hpp +45 -0
- mqt/core/include/mqt-core/dd/CachedEdge.hpp +174 -0
- mqt/core/include/mqt-core/dd/Complex.hpp +165 -0
- mqt/core/include/mqt-core/dd/ComplexNumbers.hpp +150 -0
- mqt/core/include/mqt-core/dd/ComplexValue.hpp +184 -0
- mqt/core/include/mqt-core/dd/ComputeTable.hpp +183 -0
- mqt/core/include/mqt-core/dd/DDDefinitions.hpp +139 -0
- mqt/core/include/mqt-core/dd/DDpackageConfig.hpp +104 -0
- mqt/core/include/mqt-core/dd/DensityNoiseTable.hpp +114 -0
- mqt/core/include/mqt-core/dd/Edge.hpp +416 -0
- mqt/core/include/mqt-core/dd/Export.hpp +438 -0
- mqt/core/include/mqt-core/dd/FunctionalityConstruction.hpp +75 -0
- mqt/core/include/mqt-core/dd/GateMatrixDefinitions.hpp +43 -0
- mqt/core/include/mqt-core/dd/LinkedListBase.hpp +45 -0
- mqt/core/include/mqt-core/dd/MemoryManager.hpp +193 -0
- mqt/core/include/mqt-core/dd/Node.hpp +223 -0
- mqt/core/include/mqt-core/dd/NoiseFunctionality.hpp +144 -0
- mqt/core/include/mqt-core/dd/Operations.hpp +306 -0
- mqt/core/include/mqt-core/dd/Package.hpp +2036 -0
- mqt/core/include/mqt-core/dd/Package_fwd.hpp +22 -0
- mqt/core/include/mqt-core/dd/RealNumber.hpp +255 -0
- mqt/core/include/mqt-core/dd/RealNumberUniqueTable.hpp +217 -0
- mqt/core/include/mqt-core/dd/Simulation.hpp +98 -0
- mqt/core/include/mqt-core/dd/StateGeneration.hpp +143 -0
- mqt/core/include/mqt-core/dd/StochasticNoiseOperationTable.hpp +88 -0
- mqt/core/include/mqt-core/dd/UnaryComputeTable.hpp +121 -0
- mqt/core/include/mqt-core/dd/UniqueTable.hpp +243 -0
- mqt/core/include/mqt-core/dd/mqt_core_dd_export.h +43 -0
- mqt/core/include/mqt-core/dd/statistics/MemoryManagerStatistics.hpp +84 -0
- mqt/core/include/mqt-core/dd/statistics/PackageStatistics.hpp +55 -0
- mqt/core/include/mqt-core/dd/statistics/Statistics.hpp +48 -0
- mqt/core/include/mqt-core/dd/statistics/TableStatistics.hpp +79 -0
- mqt/core/include/mqt-core/dd/statistics/UniqueTableStatistics.hpp +31 -0
- mqt/core/include/mqt-core/fomac/FoMaC.hpp +568 -0
- mqt/core/include/mqt-core/ir/Definitions.hpp +108 -0
- mqt/core/include/mqt-core/ir/Permutation.hpp +213 -0
- mqt/core/include/mqt-core/ir/QuantumComputation.hpp +596 -0
- mqt/core/include/mqt-core/ir/Register.hpp +125 -0
- mqt/core/include/mqt-core/ir/mqt_core_ir_export.h +43 -0
- mqt/core/include/mqt-core/ir/operations/AodOperation.hpp +92 -0
- mqt/core/include/mqt-core/ir/operations/CompoundOperation.hpp +212 -0
- mqt/core/include/mqt-core/ir/operations/Control.hpp +142 -0
- mqt/core/include/mqt-core/ir/operations/Expression.hpp +847 -0
- mqt/core/include/mqt-core/ir/operations/IfElseOperation.hpp +169 -0
- mqt/core/include/mqt-core/ir/operations/NonUnitaryOperation.hpp +118 -0
- mqt/core/include/mqt-core/ir/operations/OpType.hpp +120 -0
- mqt/core/include/mqt-core/ir/operations/OpType.inc +76 -0
- mqt/core/include/mqt-core/ir/operations/Operation.hpp +247 -0
- mqt/core/include/mqt-core/ir/operations/StandardOperation.hpp +140 -0
- mqt/core/include/mqt-core/ir/operations/SymbolicOperation.hpp +144 -0
- mqt/core/include/mqt-core/mqt_na_qdmi/device.h +602 -0
- mqt/core/include/mqt-core/mqt_na_qdmi/types.h +78 -0
- mqt/core/include/mqt-core/na/NAComputation.hpp +185 -0
- mqt/core/include/mqt-core/na/device/Device.hpp +410 -0
- mqt/core/include/mqt-core/na/device/DeviceMemberInitializers.hpp +724 -0
- mqt/core/include/mqt-core/na/device/Generator.hpp +447 -0
- mqt/core/include/mqt-core/na/entities/Atom.hpp +62 -0
- mqt/core/include/mqt-core/na/entities/Location.hpp +154 -0
- mqt/core/include/mqt-core/na/entities/Zone.hpp +95 -0
- mqt/core/include/mqt-core/na/fomac/Device.hpp +169 -0
- mqt/core/include/mqt-core/na/mqt_core_na_export.h +43 -0
- mqt/core/include/mqt-core/na/operations/GlobalCZOp.hpp +38 -0
- mqt/core/include/mqt-core/na/operations/GlobalOp.hpp +58 -0
- mqt/core/include/mqt-core/na/operations/GlobalRYOp.hpp +42 -0
- mqt/core/include/mqt-core/na/operations/LoadOp.hpp +89 -0
- mqt/core/include/mqt-core/na/operations/LocalOp.hpp +56 -0
- mqt/core/include/mqt-core/na/operations/LocalRZOp.hpp +42 -0
- mqt/core/include/mqt-core/na/operations/LocalUOp.hpp +49 -0
- mqt/core/include/mqt-core/na/operations/MoveOp.hpp +66 -0
- mqt/core/include/mqt-core/na/operations/Op.hpp +62 -0
- mqt/core/include/mqt-core/na/operations/ShuttlingOp.hpp +51 -0
- mqt/core/include/mqt-core/na/operations/StoreOp.hpp +87 -0
- mqt/core/include/mqt-core/qasm3/Exception.hpp +85 -0
- mqt/core/include/mqt-core/qasm3/Gate.hpp +65 -0
- mqt/core/include/mqt-core/qasm3/Importer.hpp +192 -0
- mqt/core/include/mqt-core/qasm3/InstVisitor.hpp +145 -0
- mqt/core/include/mqt-core/qasm3/NestedEnvironment.hpp +41 -0
- mqt/core/include/mqt-core/qasm3/Parser.hpp +170 -0
- mqt/core/include/mqt-core/qasm3/Scanner.hpp +73 -0
- mqt/core/include/mqt-core/qasm3/Statement.hpp +486 -0
- mqt/core/include/mqt-core/qasm3/Statement_fwd.hpp +39 -0
- mqt/core/include/mqt-core/qasm3/StdGates.hpp +232 -0
- mqt/core/include/mqt-core/qasm3/Token.hpp +198 -0
- mqt/core/include/mqt-core/qasm3/Types.hpp +238 -0
- mqt/core/include/mqt-core/qasm3/Types_fwd.hpp +22 -0
- mqt/core/include/mqt-core/qasm3/mqt_core_qasm_export.h +43 -0
- mqt/core/include/mqt-core/qasm3/passes/CompilerPass.hpp +22 -0
- mqt/core/include/mqt-core/qasm3/passes/ConstEvalPass.hpp +102 -0
- mqt/core/include/mqt-core/qasm3/passes/TypeCheckPass.hpp +124 -0
- mqt/core/include/mqt-core/qdmi/Driver.hpp +431 -0
- mqt/core/include/mqt-core/zx/FunctionalityConstruction.hpp +125 -0
- mqt/core/include/mqt-core/zx/Rational.hpp +318 -0
- mqt/core/include/mqt-core/zx/Rules.hpp +132 -0
- mqt/core/include/mqt-core/zx/Simplify.hpp +182 -0
- mqt/core/include/mqt-core/zx/Utils.hpp +212 -0
- mqt/core/include/mqt-core/zx/ZXDefinitions.hpp +93 -0
- mqt/core/include/mqt-core/zx/ZXDiagram.hpp +480 -0
- mqt/core/include/mqt-core/zx/mqt_core_zx_export.h +43 -0
- mqt/core/include/nlohmann/adl_serializer.hpp +55 -0
- mqt/core/include/nlohmann/byte_container_with_subtype.hpp +103 -0
- mqt/core/include/nlohmann/detail/abi_macros.hpp +111 -0
- mqt/core/include/nlohmann/detail/conversions/from_json.hpp +577 -0
- mqt/core/include/nlohmann/detail/conversions/to_chars.hpp +1118 -0
- mqt/core/include/nlohmann/detail/conversions/to_json.hpp +479 -0
- mqt/core/include/nlohmann/detail/exceptions.hpp +291 -0
- mqt/core/include/nlohmann/detail/hash.hpp +129 -0
- mqt/core/include/nlohmann/detail/input/binary_reader.hpp +3068 -0
- mqt/core/include/nlohmann/detail/input/input_adapters.hpp +549 -0
- mqt/core/include/nlohmann/detail/input/json_sax.hpp +986 -0
- mqt/core/include/nlohmann/detail/input/lexer.hpp +1643 -0
- mqt/core/include/nlohmann/detail/input/parser.hpp +519 -0
- mqt/core/include/nlohmann/detail/input/position_t.hpp +37 -0
- mqt/core/include/nlohmann/detail/iterators/internal_iterator.hpp +35 -0
- mqt/core/include/nlohmann/detail/iterators/iter_impl.hpp +760 -0
- mqt/core/include/nlohmann/detail/iterators/iteration_proxy.hpp +235 -0
- mqt/core/include/nlohmann/detail/iterators/iterator_traits.hpp +61 -0
- mqt/core/include/nlohmann/detail/iterators/json_reverse_iterator.hpp +130 -0
- mqt/core/include/nlohmann/detail/iterators/primitive_iterator.hpp +132 -0
- mqt/core/include/nlohmann/detail/json_custom_base_class.hpp +39 -0
- mqt/core/include/nlohmann/detail/json_pointer.hpp +988 -0
- mqt/core/include/nlohmann/detail/json_ref.hpp +78 -0
- mqt/core/include/nlohmann/detail/macro_scope.hpp +595 -0
- mqt/core/include/nlohmann/detail/macro_unscope.hpp +46 -0
- mqt/core/include/nlohmann/detail/meta/call_std/begin.hpp +17 -0
- mqt/core/include/nlohmann/detail/meta/call_std/end.hpp +17 -0
- mqt/core/include/nlohmann/detail/meta/cpp_future.hpp +171 -0
- mqt/core/include/nlohmann/detail/meta/detected.hpp +70 -0
- mqt/core/include/nlohmann/detail/meta/identity_tag.hpp +21 -0
- mqt/core/include/nlohmann/detail/meta/is_sax.hpp +159 -0
- mqt/core/include/nlohmann/detail/meta/std_fs.hpp +29 -0
- mqt/core/include/nlohmann/detail/meta/type_traits.hpp +795 -0
- mqt/core/include/nlohmann/detail/meta/void_t.hpp +24 -0
- mqt/core/include/nlohmann/detail/output/binary_writer.hpp +1850 -0
- mqt/core/include/nlohmann/detail/output/output_adapters.hpp +147 -0
- mqt/core/include/nlohmann/detail/output/serializer.hpp +988 -0
- mqt/core/include/nlohmann/detail/string_concat.hpp +146 -0
- mqt/core/include/nlohmann/detail/string_escape.hpp +72 -0
- mqt/core/include/nlohmann/detail/string_utils.hpp +37 -0
- mqt/core/include/nlohmann/detail/value_t.hpp +118 -0
- mqt/core/include/nlohmann/json.hpp +5306 -0
- mqt/core/include/nlohmann/json_fwd.hpp +75 -0
- mqt/core/include/nlohmann/ordered_map.hpp +359 -0
- mqt/core/include/nlohmann/thirdparty/hedley/hedley.hpp +2045 -0
- mqt/core/include/nlohmann/thirdparty/hedley/hedley_undef.hpp +158 -0
- mqt/core/include/qdmi/qdmi/client.h +990 -0
- mqt/core/include/qdmi/qdmi/constants.h +1139 -0
- mqt/core/include/qdmi/qdmi/device.h +602 -0
- mqt/core/include/qdmi/qdmi/types.h +78 -0
- mqt/core/include/spdlog/async.h +99 -0
- mqt/core/include/spdlog/async_logger-inl.h +84 -0
- mqt/core/include/spdlog/async_logger.h +74 -0
- mqt/core/include/spdlog/cfg/argv.h +40 -0
- mqt/core/include/spdlog/cfg/env.h +36 -0
- mqt/core/include/spdlog/cfg/helpers-inl.h +107 -0
- mqt/core/include/spdlog/cfg/helpers.h +29 -0
- mqt/core/include/spdlog/common-inl.h +68 -0
- mqt/core/include/spdlog/common.h +406 -0
- mqt/core/include/spdlog/details/backtracer-inl.h +63 -0
- mqt/core/include/spdlog/details/backtracer.h +45 -0
- mqt/core/include/spdlog/details/circular_q.h +115 -0
- mqt/core/include/spdlog/details/console_globals.h +28 -0
- mqt/core/include/spdlog/details/file_helper-inl.h +153 -0
- mqt/core/include/spdlog/details/file_helper.h +61 -0
- mqt/core/include/spdlog/details/fmt_helper.h +141 -0
- mqt/core/include/spdlog/details/log_msg-inl.h +44 -0
- mqt/core/include/spdlog/details/log_msg.h +40 -0
- mqt/core/include/spdlog/details/log_msg_buffer-inl.h +54 -0
- mqt/core/include/spdlog/details/log_msg_buffer.h +32 -0
- mqt/core/include/spdlog/details/mpmc_blocking_q.h +177 -0
- mqt/core/include/spdlog/details/null_mutex.h +35 -0
- mqt/core/include/spdlog/details/os-inl.h +606 -0
- mqt/core/include/spdlog/details/os.h +127 -0
- mqt/core/include/spdlog/details/periodic_worker-inl.h +26 -0
- mqt/core/include/spdlog/details/periodic_worker.h +58 -0
- mqt/core/include/spdlog/details/registry-inl.h +270 -0
- mqt/core/include/spdlog/details/registry.h +131 -0
- mqt/core/include/spdlog/details/synchronous_factory.h +22 -0
- mqt/core/include/spdlog/details/tcp_client-windows.h +135 -0
- mqt/core/include/spdlog/details/tcp_client.h +127 -0
- mqt/core/include/spdlog/details/thread_pool-inl.h +126 -0
- mqt/core/include/spdlog/details/thread_pool.h +117 -0
- mqt/core/include/spdlog/details/udp_client-windows.h +98 -0
- mqt/core/include/spdlog/details/udp_client.h +81 -0
- mqt/core/include/spdlog/details/windows_include.h +11 -0
- mqt/core/include/spdlog/fmt/bin_to_hex.h +224 -0
- mqt/core/include/spdlog/fmt/bundled/args.h +220 -0
- mqt/core/include/spdlog/fmt/bundled/base.h +2989 -0
- mqt/core/include/spdlog/fmt/bundled/chrono.h +2330 -0
- mqt/core/include/spdlog/fmt/bundled/color.h +637 -0
- mqt/core/include/spdlog/fmt/bundled/compile.h +539 -0
- mqt/core/include/spdlog/fmt/bundled/core.h +5 -0
- mqt/core/include/spdlog/fmt/bundled/fmt.license.rst +27 -0
- mqt/core/include/spdlog/fmt/bundled/format-inl.h +1948 -0
- mqt/core/include/spdlog/fmt/bundled/format.h +4244 -0
- mqt/core/include/spdlog/fmt/bundled/os.h +427 -0
- mqt/core/include/spdlog/fmt/bundled/ostream.h +167 -0
- mqt/core/include/spdlog/fmt/bundled/printf.h +633 -0
- mqt/core/include/spdlog/fmt/bundled/ranges.h +850 -0
- mqt/core/include/spdlog/fmt/bundled/std.h +728 -0
- mqt/core/include/spdlog/fmt/bundled/xchar.h +369 -0
- mqt/core/include/spdlog/fmt/chrono.h +23 -0
- mqt/core/include/spdlog/fmt/compile.h +23 -0
- mqt/core/include/spdlog/fmt/fmt.h +30 -0
- mqt/core/include/spdlog/fmt/ostr.h +23 -0
- mqt/core/include/spdlog/fmt/ranges.h +23 -0
- mqt/core/include/spdlog/fmt/std.h +24 -0
- mqt/core/include/spdlog/fmt/xchar.h +23 -0
- mqt/core/include/spdlog/formatter.h +17 -0
- mqt/core/include/spdlog/fwd.h +18 -0
- mqt/core/include/spdlog/logger-inl.h +198 -0
- mqt/core/include/spdlog/logger.h +379 -0
- mqt/core/include/spdlog/mdc.h +52 -0
- mqt/core/include/spdlog/pattern_formatter-inl.h +1340 -0
- mqt/core/include/spdlog/pattern_formatter.h +118 -0
- mqt/core/include/spdlog/sinks/android_sink.h +137 -0
- mqt/core/include/spdlog/sinks/ansicolor_sink-inl.h +142 -0
- mqt/core/include/spdlog/sinks/ansicolor_sink.h +116 -0
- mqt/core/include/spdlog/sinks/base_sink-inl.h +59 -0
- mqt/core/include/spdlog/sinks/base_sink.h +51 -0
- mqt/core/include/spdlog/sinks/basic_file_sink-inl.h +48 -0
- mqt/core/include/spdlog/sinks/basic_file_sink.h +66 -0
- mqt/core/include/spdlog/sinks/callback_sink.h +56 -0
- mqt/core/include/spdlog/sinks/daily_file_sink.h +254 -0
- mqt/core/include/spdlog/sinks/dist_sink.h +81 -0
- mqt/core/include/spdlog/sinks/dup_filter_sink.h +91 -0
- mqt/core/include/spdlog/sinks/hourly_file_sink.h +193 -0
- mqt/core/include/spdlog/sinks/kafka_sink.h +119 -0
- mqt/core/include/spdlog/sinks/mongo_sink.h +108 -0
- mqt/core/include/spdlog/sinks/msvc_sink.h +68 -0
- mqt/core/include/spdlog/sinks/null_sink.h +41 -0
- mqt/core/include/spdlog/sinks/ostream_sink.h +43 -0
- mqt/core/include/spdlog/sinks/qt_sinks.h +304 -0
- mqt/core/include/spdlog/sinks/ringbuffer_sink.h +67 -0
- mqt/core/include/spdlog/sinks/rotating_file_sink-inl.h +179 -0
- mqt/core/include/spdlog/sinks/rotating_file_sink.h +93 -0
- mqt/core/include/spdlog/sinks/sink-inl.h +22 -0
- mqt/core/include/spdlog/sinks/sink.h +34 -0
- mqt/core/include/spdlog/sinks/stdout_color_sinks-inl.h +38 -0
- mqt/core/include/spdlog/sinks/stdout_color_sinks.h +49 -0
- mqt/core/include/spdlog/sinks/stdout_sinks-inl.h +127 -0
- mqt/core/include/spdlog/sinks/stdout_sinks.h +84 -0
- mqt/core/include/spdlog/sinks/syslog_sink.h +104 -0
- mqt/core/include/spdlog/sinks/systemd_sink.h +121 -0
- mqt/core/include/spdlog/sinks/tcp_sink.h +75 -0
- mqt/core/include/spdlog/sinks/udp_sink.h +69 -0
- mqt/core/include/spdlog/sinks/win_eventlog_sink.h +260 -0
- mqt/core/include/spdlog/sinks/wincolor_sink-inl.h +172 -0
- mqt/core/include/spdlog/sinks/wincolor_sink.h +82 -0
- mqt/core/include/spdlog/spdlog-inl.h +96 -0
- mqt/core/include/spdlog/spdlog.h +357 -0
- mqt/core/include/spdlog/stopwatch.h +66 -0
- mqt/core/include/spdlog/tweakme.h +148 -0
- mqt/core/include/spdlog/version.h +11 -0
- mqt/core/ir/__init__.pyi +2078 -0
- mqt/core/ir/operations.pyi +1011 -0
- mqt/core/ir/registers.pyi +91 -0
- mqt/core/ir/symbolic.pyi +177 -0
- mqt/core/ir.cpython-314t-darwin.so +0 -0
- mqt/core/lib/libmqt-core-algorithms.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-algorithms.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-algorithms.dylib +0 -0
- mqt/core/lib/libmqt-core-circuit-optimizer.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-circuit-optimizer.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-circuit-optimizer.dylib +0 -0
- mqt/core/lib/libmqt-core-dd.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-dd.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-dd.dylib +0 -0
- mqt/core/lib/libmqt-core-ds.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-ds.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-ds.dylib +0 -0
- mqt/core/lib/libmqt-core-fomac.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-fomac.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-fomac.dylib +0 -0
- mqt/core/lib/libmqt-core-ir.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-ir.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-ir.dylib +0 -0
- mqt/core/lib/libmqt-core-na-fomac.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-na-fomac.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-na-fomac.dylib +0 -0
- mqt/core/lib/libmqt-core-na.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-na.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-na.dylib +0 -0
- mqt/core/lib/libmqt-core-qasm.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-qasm.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-qasm.dylib +0 -0
- mqt/core/lib/libmqt-core-qdmi-driver.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-qdmi-driver.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-qdmi-driver.dylib +0 -0
- mqt/core/lib/libmqt-core-qdmi-na-device-gen.a +0 -0
- mqt/core/lib/libmqt-core-qdmi-na-device.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-qdmi-na-device.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-qdmi-na-device.dylib +0 -0
- mqt/core/lib/libmqt-core-zx.3.3.2.dylib +0 -0
- mqt/core/lib/libmqt-core-zx.3.3.dylib +0 -0
- mqt/core/lib/libmqt-core-zx.dylib +0 -0
- mqt/core/lib/libspdlog.a +0 -0
- mqt/core/lib/pkgconfig/spdlog.pc +13 -0
- mqt/core/na/__init__.py +12 -0
- mqt/core/na/fomac.cpython-314t-darwin.so +0 -0
- mqt/core/na/fomac.pyi +117 -0
- mqt/core/plugins/__init__.py +9 -0
- mqt/core/plugins/qiskit/__init__.py +19 -0
- mqt/core/plugins/qiskit/mqt_to_qiskit.py +420 -0
- mqt/core/plugins/qiskit/qiskit_to_mqt.py +562 -0
- mqt/core/py.typed +2 -0
- mqt/core/share/cmake/mqt-core/AddMQTPythonBinding.cmake +55 -0
- mqt/core/share/cmake/mqt-core/Cache.cmake +33 -0
- mqt/core/share/cmake/mqt-core/FindGMP.cmake +103 -0
- mqt/core/share/cmake/mqt-core/PackageAddTest.cmake +46 -0
- mqt/core/share/cmake/mqt-core/PreventInSourceBuilds.cmake +25 -0
- mqt/core/share/cmake/mqt-core/StandardProjectSettings.cmake +87 -0
- mqt/core/share/cmake/mqt-core/mqt-core-config-version.cmake +85 -0
- mqt/core/share/cmake/mqt-core/mqt-core-config.cmake +52 -0
- mqt/core/share/cmake/mqt-core/mqt-core-targets-release.cmake +141 -0
- mqt/core/share/cmake/mqt-core/mqt-core-targets.cmake +446 -0
- mqt/core/share/cmake/nlohmann_json/nlohmann_jsonConfig.cmake +15 -0
- mqt/core/share/cmake/nlohmann_json/nlohmann_jsonConfigVersion.cmake +20 -0
- mqt/core/share/cmake/nlohmann_json/nlohmann_jsonTargets.cmake +109 -0
- mqt/core/share/cmake/qdmi/Cache.cmake +44 -0
- mqt/core/share/cmake/qdmi/PrefixHandling.cmake +78 -0
- mqt/core/share/cmake/qdmi/prefix_defs.txt +26 -0
- mqt/core/share/cmake/qdmi/qdmi-config-version.cmake +85 -0
- mqt/core/share/cmake/qdmi/qdmi-config.cmake +42 -0
- mqt/core/share/cmake/qdmi/qdmi-targets.cmake +129 -0
- mqt/core/share/cmake/spdlog/spdlogConfig.cmake +44 -0
- mqt/core/share/cmake/spdlog/spdlogConfigTargets-release.cmake +19 -0
- mqt/core/share/cmake/spdlog/spdlogConfigTargets.cmake +118 -0
- mqt/core/share/cmake/spdlog/spdlogConfigVersion.cmake +65 -0
- mqt/core/share/pkgconfig/nlohmann_json.pc +7 -0
- mqt_core-3.3.2.dist-info/METADATA +210 -0
- mqt_core-3.3.2.dist-info/RECORD +546 -0
- mqt_core-3.3.2.dist-info/WHEEL +6 -0
- mqt_core-3.3.2.dist-info/entry_points.txt +4 -0
- mqt_core-3.3.2.dist-info/licenses/LICENSE.md +22 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
2
|
+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#define WIN32_LEAN_AND_MEAN
|
|
7
|
+
// tcp client helper
|
|
8
|
+
#include <spdlog/common.h>
|
|
9
|
+
#include <spdlog/details/os.h>
|
|
10
|
+
|
|
11
|
+
#include <stdio.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <windows.h>
|
|
15
|
+
#include <winsock2.h>
|
|
16
|
+
#include <ws2tcpip.h>
|
|
17
|
+
|
|
18
|
+
#pragma comment(lib, "Ws2_32.lib")
|
|
19
|
+
#pragma comment(lib, "Mswsock.lib")
|
|
20
|
+
#pragma comment(lib, "AdvApi32.lib")
|
|
21
|
+
|
|
22
|
+
namespace spdlog {
|
|
23
|
+
namespace details {
|
|
24
|
+
class tcp_client {
|
|
25
|
+
SOCKET socket_ = INVALID_SOCKET;
|
|
26
|
+
|
|
27
|
+
static void init_winsock_() {
|
|
28
|
+
WSADATA wsaData;
|
|
29
|
+
auto rv = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
|
30
|
+
if (rv != 0) {
|
|
31
|
+
throw_winsock_error_("WSAStartup failed", ::WSAGetLastError());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static void throw_winsock_error_(const std::string &msg, int last_error) {
|
|
36
|
+
char buf[512];
|
|
37
|
+
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
|
38
|
+
last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf,
|
|
39
|
+
(sizeof(buf) / sizeof(char)), NULL);
|
|
40
|
+
|
|
41
|
+
throw_spdlog_ex(fmt_lib::format("tcp_sink - {}: {}", msg, buf));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public:
|
|
45
|
+
tcp_client() { init_winsock_(); }
|
|
46
|
+
|
|
47
|
+
~tcp_client() {
|
|
48
|
+
close();
|
|
49
|
+
::WSACleanup();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bool is_connected() const { return socket_ != INVALID_SOCKET; }
|
|
53
|
+
|
|
54
|
+
void close() {
|
|
55
|
+
::closesocket(socket_);
|
|
56
|
+
socket_ = INVALID_SOCKET;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
SOCKET fd() const { return socket_; }
|
|
60
|
+
|
|
61
|
+
// try to connect or throw on failure
|
|
62
|
+
void connect(const std::string &host, int port) {
|
|
63
|
+
if (is_connected()) {
|
|
64
|
+
close();
|
|
65
|
+
}
|
|
66
|
+
struct addrinfo hints {};
|
|
67
|
+
ZeroMemory(&hints, sizeof(hints));
|
|
68
|
+
|
|
69
|
+
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
|
70
|
+
hints.ai_socktype = SOCK_STREAM; // TCP
|
|
71
|
+
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
|
72
|
+
hints.ai_protocol = 0;
|
|
73
|
+
|
|
74
|
+
auto port_str = std::to_string(port);
|
|
75
|
+
struct addrinfo *addrinfo_result;
|
|
76
|
+
auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result);
|
|
77
|
+
int last_error = 0;
|
|
78
|
+
if (rv != 0) {
|
|
79
|
+
last_error = ::WSAGetLastError();
|
|
80
|
+
WSACleanup();
|
|
81
|
+
throw_winsock_error_("getaddrinfo failed", last_error);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Try each address until we successfully connect(2).
|
|
85
|
+
|
|
86
|
+
for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) {
|
|
87
|
+
socket_ = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
|
88
|
+
if (socket_ == INVALID_SOCKET) {
|
|
89
|
+
last_error = ::WSAGetLastError();
|
|
90
|
+
WSACleanup();
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (::connect(socket_, rp->ai_addr, (int)rp->ai_addrlen) == 0) {
|
|
94
|
+
break;
|
|
95
|
+
} else {
|
|
96
|
+
last_error = ::WSAGetLastError();
|
|
97
|
+
close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
::freeaddrinfo(addrinfo_result);
|
|
101
|
+
if (socket_ == INVALID_SOCKET) {
|
|
102
|
+
WSACleanup();
|
|
103
|
+
throw_winsock_error_("connect failed", last_error);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// set TCP_NODELAY
|
|
107
|
+
int enable_flag = 1;
|
|
108
|
+
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag),
|
|
109
|
+
sizeof(enable_flag));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Send exactly n_bytes of the given data.
|
|
113
|
+
// On error close the connection and throw.
|
|
114
|
+
void send(const char *data, size_t n_bytes) {
|
|
115
|
+
size_t bytes_sent = 0;
|
|
116
|
+
while (bytes_sent < n_bytes) {
|
|
117
|
+
const int send_flags = 0;
|
|
118
|
+
auto write_result =
|
|
119
|
+
::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags);
|
|
120
|
+
if (write_result == SOCKET_ERROR) {
|
|
121
|
+
int last_error = ::WSAGetLastError();
|
|
122
|
+
close();
|
|
123
|
+
throw_winsock_error_("send failed", last_error);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (write_result == 0) // (probably should not happen but in any case..)
|
|
127
|
+
{
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
bytes_sent += static_cast<size_t>(write_result);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
} // namespace details
|
|
135
|
+
} // namespace spdlog
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
2
|
+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#ifdef _WIN32
|
|
7
|
+
#error include tcp_client-windows.h instead
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
// tcp client helper
|
|
11
|
+
#include <spdlog/common.h>
|
|
12
|
+
#include <spdlog/details/os.h>
|
|
13
|
+
|
|
14
|
+
#include <arpa/inet.h>
|
|
15
|
+
#include <netdb.h>
|
|
16
|
+
#include <netinet/in.h>
|
|
17
|
+
#include <netinet/tcp.h>
|
|
18
|
+
#include <sys/socket.h>
|
|
19
|
+
#include <unistd.h>
|
|
20
|
+
|
|
21
|
+
#include <string>
|
|
22
|
+
|
|
23
|
+
namespace spdlog {
|
|
24
|
+
namespace details {
|
|
25
|
+
class tcp_client {
|
|
26
|
+
int socket_ = -1;
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
bool is_connected() const { return socket_ != -1; }
|
|
30
|
+
|
|
31
|
+
void close() {
|
|
32
|
+
if (is_connected()) {
|
|
33
|
+
::close(socket_);
|
|
34
|
+
socket_ = -1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
int fd() const { return socket_; }
|
|
39
|
+
|
|
40
|
+
~tcp_client() { close(); }
|
|
41
|
+
|
|
42
|
+
// try to connect or throw on failure
|
|
43
|
+
void connect(const std::string &host, int port) {
|
|
44
|
+
close();
|
|
45
|
+
struct addrinfo hints {};
|
|
46
|
+
memset(&hints, 0, sizeof(struct addrinfo));
|
|
47
|
+
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
|
48
|
+
hints.ai_socktype = SOCK_STREAM; // TCP
|
|
49
|
+
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
|
50
|
+
hints.ai_protocol = 0;
|
|
51
|
+
|
|
52
|
+
auto port_str = std::to_string(port);
|
|
53
|
+
struct addrinfo *addrinfo_result;
|
|
54
|
+
auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result);
|
|
55
|
+
if (rv != 0) {
|
|
56
|
+
throw_spdlog_ex(fmt_lib::format("::getaddrinfo failed: {}", gai_strerror(rv)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Try each address until we successfully connect(2).
|
|
60
|
+
int last_errno = 0;
|
|
61
|
+
for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) {
|
|
62
|
+
#if defined(SOCK_CLOEXEC)
|
|
63
|
+
const int flags = SOCK_CLOEXEC;
|
|
64
|
+
#else
|
|
65
|
+
const int flags = 0;
|
|
66
|
+
#endif
|
|
67
|
+
socket_ = ::socket(rp->ai_family, rp->ai_socktype | flags, rp->ai_protocol);
|
|
68
|
+
if (socket_ == -1) {
|
|
69
|
+
last_errno = errno;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
rv = ::connect(socket_, rp->ai_addr, rp->ai_addrlen);
|
|
73
|
+
if (rv == 0) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
last_errno = errno;
|
|
77
|
+
::close(socket_);
|
|
78
|
+
socket_ = -1;
|
|
79
|
+
}
|
|
80
|
+
::freeaddrinfo(addrinfo_result);
|
|
81
|
+
if (socket_ == -1) {
|
|
82
|
+
throw_spdlog_ex("::connect failed", last_errno);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// set TCP_NODELAY
|
|
86
|
+
int enable_flag = 1;
|
|
87
|
+
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag),
|
|
88
|
+
sizeof(enable_flag));
|
|
89
|
+
|
|
90
|
+
// prevent sigpipe on systems where MSG_NOSIGNAL is not available
|
|
91
|
+
#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
|
92
|
+
::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast<char *>(&enable_flag),
|
|
93
|
+
sizeof(enable_flag));
|
|
94
|
+
#endif
|
|
95
|
+
|
|
96
|
+
#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
|
97
|
+
#error "tcp_sink would raise SIGPIPE since neither SO_NOSIGPIPE nor MSG_NOSIGNAL are available"
|
|
98
|
+
#endif
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Send exactly n_bytes of the given data.
|
|
102
|
+
// On error close the connection and throw.
|
|
103
|
+
void send(const char *data, size_t n_bytes) {
|
|
104
|
+
size_t bytes_sent = 0;
|
|
105
|
+
while (bytes_sent < n_bytes) {
|
|
106
|
+
#if defined(MSG_NOSIGNAL)
|
|
107
|
+
const int send_flags = MSG_NOSIGNAL;
|
|
108
|
+
#else
|
|
109
|
+
const int send_flags = 0;
|
|
110
|
+
#endif
|
|
111
|
+
auto write_result =
|
|
112
|
+
::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags);
|
|
113
|
+
if (write_result < 0) {
|
|
114
|
+
close();
|
|
115
|
+
throw_spdlog_ex("write(2) failed", errno);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (write_result == 0) // (probably should not happen but in any case..)
|
|
119
|
+
{
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
bytes_sent += static_cast<size_t>(write_result);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
} // namespace details
|
|
127
|
+
} // namespace spdlog
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
2
|
+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#ifndef SPDLOG_HEADER_ONLY
|
|
7
|
+
#include <spdlog/details/thread_pool.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
#include <cassert>
|
|
11
|
+
#include <spdlog/common.h>
|
|
12
|
+
|
|
13
|
+
namespace spdlog {
|
|
14
|
+
namespace details {
|
|
15
|
+
|
|
16
|
+
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items,
|
|
17
|
+
size_t threads_n,
|
|
18
|
+
std::function<void()> on_thread_start,
|
|
19
|
+
std::function<void()> on_thread_stop)
|
|
20
|
+
: q_(q_max_items) {
|
|
21
|
+
if (threads_n == 0 || threads_n > 1000) {
|
|
22
|
+
throw_spdlog_ex(
|
|
23
|
+
"spdlog::thread_pool(): invalid threads_n param (valid "
|
|
24
|
+
"range is 1-1000)");
|
|
25
|
+
}
|
|
26
|
+
for (size_t i = 0; i < threads_n; i++) {
|
|
27
|
+
threads_.emplace_back([this, on_thread_start, on_thread_stop] {
|
|
28
|
+
on_thread_start();
|
|
29
|
+
this->thread_pool::worker_loop_();
|
|
30
|
+
on_thread_stop();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items,
|
|
36
|
+
size_t threads_n,
|
|
37
|
+
std::function<void()> on_thread_start)
|
|
38
|
+
: thread_pool(q_max_items, threads_n, on_thread_start, [] {}) {}
|
|
39
|
+
|
|
40
|
+
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
|
41
|
+
: thread_pool(q_max_items, threads_n, [] {}, [] {}) {}
|
|
42
|
+
|
|
43
|
+
// message all threads to terminate gracefully join them
|
|
44
|
+
SPDLOG_INLINE thread_pool::~thread_pool() {
|
|
45
|
+
SPDLOG_TRY {
|
|
46
|
+
for (size_t i = 0; i < threads_.size(); i++) {
|
|
47
|
+
post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (auto &t : threads_) {
|
|
51
|
+
t.join();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
SPDLOG_CATCH_STD
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr,
|
|
58
|
+
const details::log_msg &msg,
|
|
59
|
+
async_overflow_policy overflow_policy) {
|
|
60
|
+
async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg);
|
|
61
|
+
post_async_msg_(std::move(async_m), overflow_policy);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
void SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr,
|
|
65
|
+
async_overflow_policy overflow_policy) {
|
|
66
|
+
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
size_t SPDLOG_INLINE thread_pool::overrun_counter() { return q_.overrun_counter(); }
|
|
70
|
+
|
|
71
|
+
void SPDLOG_INLINE thread_pool::reset_overrun_counter() { q_.reset_overrun_counter(); }
|
|
72
|
+
|
|
73
|
+
size_t SPDLOG_INLINE thread_pool::discard_counter() { return q_.discard_counter(); }
|
|
74
|
+
|
|
75
|
+
void SPDLOG_INLINE thread_pool::reset_discard_counter() { q_.reset_discard_counter(); }
|
|
76
|
+
|
|
77
|
+
size_t SPDLOG_INLINE thread_pool::queue_size() { return q_.size(); }
|
|
78
|
+
|
|
79
|
+
void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg,
|
|
80
|
+
async_overflow_policy overflow_policy) {
|
|
81
|
+
if (overflow_policy == async_overflow_policy::block) {
|
|
82
|
+
q_.enqueue(std::move(new_msg));
|
|
83
|
+
} else if (overflow_policy == async_overflow_policy::overrun_oldest) {
|
|
84
|
+
q_.enqueue_nowait(std::move(new_msg));
|
|
85
|
+
} else {
|
|
86
|
+
assert(overflow_policy == async_overflow_policy::discard_new);
|
|
87
|
+
q_.enqueue_if_have_room(std::move(new_msg));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
void SPDLOG_INLINE thread_pool::worker_loop_() {
|
|
92
|
+
while (process_next_msg_()) {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// process next message in the queue
|
|
97
|
+
// return true if this thread should still be active (while no terminate msg
|
|
98
|
+
// was received)
|
|
99
|
+
bool SPDLOG_INLINE thread_pool::process_next_msg_() {
|
|
100
|
+
async_msg incoming_async_msg;
|
|
101
|
+
q_.dequeue(incoming_async_msg);
|
|
102
|
+
|
|
103
|
+
switch (incoming_async_msg.msg_type) {
|
|
104
|
+
case async_msg_type::log: {
|
|
105
|
+
incoming_async_msg.worker_ptr->backend_sink_it_(incoming_async_msg);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
case async_msg_type::flush: {
|
|
109
|
+
incoming_async_msg.worker_ptr->backend_flush_();
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
case async_msg_type::terminate: {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
default: {
|
|
118
|
+
assert(false);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
} // namespace details
|
|
126
|
+
} // namespace spdlog
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
2
|
+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <spdlog/details/log_msg_buffer.h>
|
|
7
|
+
#include <spdlog/details/mpmc_blocking_q.h>
|
|
8
|
+
#include <spdlog/details/os.h>
|
|
9
|
+
|
|
10
|
+
#include <chrono>
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <thread>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
namespace spdlog {
|
|
17
|
+
class async_logger;
|
|
18
|
+
|
|
19
|
+
namespace details {
|
|
20
|
+
|
|
21
|
+
using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
|
|
22
|
+
|
|
23
|
+
enum class async_msg_type { log, flush, terminate };
|
|
24
|
+
|
|
25
|
+
// Async msg to move to/from the queue
|
|
26
|
+
// Movable only. should never be copied
|
|
27
|
+
struct async_msg : log_msg_buffer {
|
|
28
|
+
async_msg_type msg_type{async_msg_type::log};
|
|
29
|
+
async_logger_ptr worker_ptr;
|
|
30
|
+
|
|
31
|
+
async_msg() = default;
|
|
32
|
+
~async_msg() = default;
|
|
33
|
+
|
|
34
|
+
// should only be moved in or out of the queue..
|
|
35
|
+
async_msg(const async_msg &) = delete;
|
|
36
|
+
|
|
37
|
+
// support for vs2013 move
|
|
38
|
+
#if defined(_MSC_VER) && _MSC_VER <= 1800
|
|
39
|
+
async_msg(async_msg &&other)
|
|
40
|
+
: log_msg_buffer(std::move(other)),
|
|
41
|
+
msg_type(other.msg_type),
|
|
42
|
+
worker_ptr(std::move(other.worker_ptr)) {}
|
|
43
|
+
|
|
44
|
+
async_msg &operator=(async_msg &&other) {
|
|
45
|
+
*static_cast<log_msg_buffer *>(this) = std::move(other);
|
|
46
|
+
msg_type = other.msg_type;
|
|
47
|
+
worker_ptr = std::move(other.worker_ptr);
|
|
48
|
+
return *this;
|
|
49
|
+
}
|
|
50
|
+
#else // (_MSC_VER) && _MSC_VER <= 1800
|
|
51
|
+
async_msg(async_msg &&) = default;
|
|
52
|
+
async_msg &operator=(async_msg &&) = default;
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
// construct from log_msg with given type
|
|
56
|
+
async_msg(async_logger_ptr &&worker, async_msg_type the_type, const details::log_msg &m)
|
|
57
|
+
: log_msg_buffer{m},
|
|
58
|
+
msg_type{the_type},
|
|
59
|
+
worker_ptr{std::move(worker)} {}
|
|
60
|
+
|
|
61
|
+
async_msg(async_logger_ptr &&worker, async_msg_type the_type)
|
|
62
|
+
: log_msg_buffer{},
|
|
63
|
+
msg_type{the_type},
|
|
64
|
+
worker_ptr{std::move(worker)} {}
|
|
65
|
+
|
|
66
|
+
explicit async_msg(async_msg_type the_type)
|
|
67
|
+
: async_msg{nullptr, the_type} {}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
class SPDLOG_API thread_pool {
|
|
71
|
+
public:
|
|
72
|
+
using item_type = async_msg;
|
|
73
|
+
using q_type = details::mpmc_blocking_queue<item_type>;
|
|
74
|
+
|
|
75
|
+
thread_pool(size_t q_max_items,
|
|
76
|
+
size_t threads_n,
|
|
77
|
+
std::function<void()> on_thread_start,
|
|
78
|
+
std::function<void()> on_thread_stop);
|
|
79
|
+
thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start);
|
|
80
|
+
thread_pool(size_t q_max_items, size_t threads_n);
|
|
81
|
+
|
|
82
|
+
// message all threads to terminate gracefully and join them
|
|
83
|
+
~thread_pool();
|
|
84
|
+
|
|
85
|
+
thread_pool(const thread_pool &) = delete;
|
|
86
|
+
thread_pool &operator=(thread_pool &&) = delete;
|
|
87
|
+
|
|
88
|
+
void post_log(async_logger_ptr &&worker_ptr,
|
|
89
|
+
const details::log_msg &msg,
|
|
90
|
+
async_overflow_policy overflow_policy);
|
|
91
|
+
void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy);
|
|
92
|
+
size_t overrun_counter();
|
|
93
|
+
void reset_overrun_counter();
|
|
94
|
+
size_t discard_counter();
|
|
95
|
+
void reset_discard_counter();
|
|
96
|
+
size_t queue_size();
|
|
97
|
+
|
|
98
|
+
private:
|
|
99
|
+
q_type q_;
|
|
100
|
+
|
|
101
|
+
std::vector<std::thread> threads_;
|
|
102
|
+
|
|
103
|
+
void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy);
|
|
104
|
+
void worker_loop_();
|
|
105
|
+
|
|
106
|
+
// process next message in the queue
|
|
107
|
+
// return true if this thread should still be active (while no terminate msg
|
|
108
|
+
// was received)
|
|
109
|
+
bool process_next_msg_();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
} // namespace details
|
|
113
|
+
} // namespace spdlog
|
|
114
|
+
|
|
115
|
+
#ifdef SPDLOG_HEADER_ONLY
|
|
116
|
+
#include "thread_pool-inl.h"
|
|
117
|
+
#endif
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
2
|
+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
// Helper RAII over winsock udp client socket.
|
|
7
|
+
// Will throw on construction if socket creation failed.
|
|
8
|
+
|
|
9
|
+
#include <spdlog/common.h>
|
|
10
|
+
#include <spdlog/details/os.h>
|
|
11
|
+
#include <spdlog/details/windows_include.h>
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <winsock2.h>
|
|
16
|
+
#include <ws2tcpip.h>
|
|
17
|
+
|
|
18
|
+
#if defined(_MSC_VER)
|
|
19
|
+
#pragma comment(lib, "Ws2_32.lib")
|
|
20
|
+
#pragma comment(lib, "Mswsock.lib")
|
|
21
|
+
#pragma comment(lib, "AdvApi32.lib")
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
namespace spdlog {
|
|
25
|
+
namespace details {
|
|
26
|
+
class udp_client {
|
|
27
|
+
static constexpr int TX_BUFFER_SIZE = 1024 * 10;
|
|
28
|
+
SOCKET socket_ = INVALID_SOCKET;
|
|
29
|
+
sockaddr_in addr_ = {};
|
|
30
|
+
|
|
31
|
+
static void init_winsock_() {
|
|
32
|
+
WSADATA wsaData;
|
|
33
|
+
auto rv = ::WSAStartup(MAKEWORD(2, 2), &wsaData);
|
|
34
|
+
if (rv != 0) {
|
|
35
|
+
throw_winsock_error_("WSAStartup failed", ::WSAGetLastError());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static void throw_winsock_error_(const std::string &msg, int last_error) {
|
|
40
|
+
char buf[512];
|
|
41
|
+
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
|
42
|
+
last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf,
|
|
43
|
+
(sizeof(buf) / sizeof(char)), NULL);
|
|
44
|
+
|
|
45
|
+
throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void cleanup_() {
|
|
49
|
+
if (socket_ != INVALID_SOCKET) {
|
|
50
|
+
::closesocket(socket_);
|
|
51
|
+
}
|
|
52
|
+
socket_ = INVALID_SOCKET;
|
|
53
|
+
::WSACleanup();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
udp_client(const std::string &host, uint16_t port) {
|
|
58
|
+
init_winsock_();
|
|
59
|
+
|
|
60
|
+
addr_.sin_family = PF_INET;
|
|
61
|
+
addr_.sin_port = htons(port);
|
|
62
|
+
addr_.sin_addr.s_addr = INADDR_ANY;
|
|
63
|
+
if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1) {
|
|
64
|
+
int last_error = ::WSAGetLastError();
|
|
65
|
+
::WSACleanup();
|
|
66
|
+
throw_winsock_error_("error: Invalid address!", last_error);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
socket_ = ::socket(PF_INET, SOCK_DGRAM, 0);
|
|
70
|
+
if (socket_ == INVALID_SOCKET) {
|
|
71
|
+
int last_error = ::WSAGetLastError();
|
|
72
|
+
::WSACleanup();
|
|
73
|
+
throw_winsock_error_("error: Create Socket failed", last_error);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
int option_value = TX_BUFFER_SIZE;
|
|
77
|
+
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
|
|
78
|
+
reinterpret_cast<const char *>(&option_value), sizeof(option_value)) < 0) {
|
|
79
|
+
int last_error = ::WSAGetLastError();
|
|
80
|
+
cleanup_();
|
|
81
|
+
throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
~udp_client() { cleanup_(); }
|
|
86
|
+
|
|
87
|
+
SOCKET fd() const { return socket_; }
|
|
88
|
+
|
|
89
|
+
void send(const char *data, size_t n_bytes) {
|
|
90
|
+
socklen_t tolen = sizeof(struct sockaddr);
|
|
91
|
+
if (::sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_,
|
|
92
|
+
tolen) == -1) {
|
|
93
|
+
throw_spdlog_ex("sendto(2) failed", errno);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
} // namespace details
|
|
98
|
+
} // namespace spdlog
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
2
|
+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
// Helper RAII over unix udp client socket.
|
|
7
|
+
// Will throw on construction if the socket creation failed.
|
|
8
|
+
|
|
9
|
+
#ifdef _WIN32
|
|
10
|
+
#error "include udp_client-windows.h instead"
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#include <arpa/inet.h>
|
|
14
|
+
#include <cstring>
|
|
15
|
+
#include <netdb.h>
|
|
16
|
+
#include <netinet/in.h>
|
|
17
|
+
#include <netinet/udp.h>
|
|
18
|
+
#include <spdlog/common.h>
|
|
19
|
+
#include <spdlog/details/os.h>
|
|
20
|
+
#include <sys/socket.h>
|
|
21
|
+
#include <unistd.h>
|
|
22
|
+
|
|
23
|
+
#include <string>
|
|
24
|
+
|
|
25
|
+
namespace spdlog {
|
|
26
|
+
namespace details {
|
|
27
|
+
|
|
28
|
+
class udp_client {
|
|
29
|
+
static constexpr int TX_BUFFER_SIZE = 1024 * 10;
|
|
30
|
+
int socket_ = -1;
|
|
31
|
+
struct sockaddr_in sockAddr_;
|
|
32
|
+
|
|
33
|
+
void cleanup_() {
|
|
34
|
+
if (socket_ != -1) {
|
|
35
|
+
::close(socket_);
|
|
36
|
+
socket_ = -1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
udp_client(const std::string &host, uint16_t port) {
|
|
42
|
+
socket_ = ::socket(PF_INET, SOCK_DGRAM, 0);
|
|
43
|
+
if (socket_ < 0) {
|
|
44
|
+
throw_spdlog_ex("error: Create Socket Failed!");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
int option_value = TX_BUFFER_SIZE;
|
|
48
|
+
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
|
|
49
|
+
reinterpret_cast<const char *>(&option_value), sizeof(option_value)) < 0) {
|
|
50
|
+
cleanup_();
|
|
51
|
+
throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
sockAddr_.sin_family = AF_INET;
|
|
55
|
+
sockAddr_.sin_port = htons(port);
|
|
56
|
+
|
|
57
|
+
if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) {
|
|
58
|
+
cleanup_();
|
|
59
|
+
throw_spdlog_ex("error: Invalid address!");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
::memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
~udp_client() { cleanup_(); }
|
|
66
|
+
|
|
67
|
+
int fd() const { return socket_; }
|
|
68
|
+
|
|
69
|
+
// Send exactly n_bytes of the given data.
|
|
70
|
+
// On error close the connection and throw.
|
|
71
|
+
void send(const char *data, size_t n_bytes) {
|
|
72
|
+
ssize_t toslen = 0;
|
|
73
|
+
socklen_t tolen = sizeof(struct sockaddr);
|
|
74
|
+
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) ==
|
|
75
|
+
-1) {
|
|
76
|
+
throw_spdlog_ex("sendto(2) failed", errno);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
} // namespace details
|
|
81
|
+
} // namespace spdlog
|