Mantid
Loading...
Searching...
No Matches
MapToPyDictionary.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2015 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
12#include <boost/python/dict.hpp>
13#include <boost/python/object.hpp>
14#include <map>
15
16namespace Mantid {
17namespace PythonInterface {
18namespace Converters {
19
20template <typename KeyType, typename ValueType> struct MapToPyDictionary {
21
22public:
23 using MapType = std::map<KeyType, ValueType>;
24
25 MapToPyDictionary(const MapType &map) : m_map(map) {}
27 boost::python::dict operator()() {
28 using namespace boost::python;
29 boost::python::dict dictionary;
30 for (const auto &pair : this->m_map) {
31 dictionary[object(pair.first)] = object(pair.second);
32 }
33 return dictionary;
34 }
35
36private:
39};
40} // namespace Converters
41} // namespace PythonInterface
42} // namespace Mantid
Helper class which provides the Collimation Length for SANS instruments.
boost::python::dict operator()()
Produces a python dictionary.