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 "MantidKernel/System.h"
13#include <boost/python/dict.hpp>
14#include <boost/python/object.hpp>
15#include <map>
16
17namespace Mantid {
18namespace PythonInterface {
19namespace Converters {
20
21template <typename KeyType, typename ValueType> struct DLLExport MapToPyDictionary {
22
23public:
24 using MapType = std::map<KeyType, ValueType>;
25
26 MapToPyDictionary(const MapType &map) : m_map(map) {}
28 boost::python::dict operator()() {
29 using namespace boost::python;
30 boost::python::dict dictionary;
31 for (const auto &pair : this->m_map) {
32 dictionary[object(pair.first)] = object(pair.second);
33 }
34 return dictionary;
35 }
36
37private:
40};
41} // namespace Converters
42} // namespace PythonInterface
43} // namespace Mantid
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
Helper class which provides the Collimation Length for SANS instruments.
boost::python::dict operator()()
Produces a python dictionary.