Mantid
Loading...
Searching...
No Matches
item_struct.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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
9#include <map>
10#include <string>
11
13template <typename T>
14// cppcheck-suppress noConstructor
16public:
18 struct item_t {
19 const T *value;
21 const int *dim0;
22 const int *dim1;
24 item_t(const T *v, bool da, const int *d0, const int *d1) : value(v), det_average(da), dim0(d0), dim1(d1) {}
25 };
26
27 item_struct() : m_items(), m_spec_array(nullptr), m_ndet(0){};
28
29private:
30 using items_map_t = std::map<std::string,
31 item_t>;
33 unsigned long *m_spec_array;
35 long m_ndet;
36public:
45 int addItem(const std::string &name, const T *value, bool det_average = false, const int *dim0 = nullptr,
46 const int *dim1 = nullptr) {
47 std::pair<typename items_map_t::iterator, bool> insert_ret;
48 insert_ret = m_items.insert(typename items_map_t::value_type(name, item_t(value, det_average, dim0, dim1)));
49 if (!insert_ret.second) {
50 return -1; // duplicate
51 } else {
52 return 0;
53 }
54 }
55
61 const item_t *findItem(const std::string &item_name, bool det_average) {
62 typename items_map_t::const_iterator iter;
63 iter = m_items.find(item_name);
64 if ((iter != m_items.end()) && (iter->second.det_average == det_average)) {
65 return &(iter->second);
66 } else {
67 return NULL;
68 }
69 }
70
71 int getItem(const std::string &item_name, T &value);
72 int getItem(const std::string &item_name, const long *spec_array, int nspec, T *lVal);
73 int getArrayItemSize(const std::string &item_name, int *dims_array, int &ndims);
74 int getArrayItem(const std::string &item_name, int nspec, T *larray);
75 int getArrayItem(const std::string &item_name, T *larray);
76};
double value
The value of the point.
Definition: FitMW.cpp:51
structure to hold a dae item
Definition: item_struct.h:15
unsigned long * m_spec_array
length m_ndet; used for averaging values
Definition: item_struct.h:33
long m_ndet
with det_average
Definition: item_struct.h:35
int addItem(const std::string &name, const T *value, bool det_average=false, const int *dim0=nullptr, const int *dim1=nullptr)
Adds an item.
Definition: item_struct.h:45
int getArrayItem(const std::string &item_name, int nspec, T *larray)
Gets an array of items.
int getArrayItemSize(const std::string &item_name, int *dims_array, int &ndims)
Gets the size of an array of items.
Definition: item_struct.cpp:92
const item_t * findItem(const std::string &item_name, bool det_average)
finds an item
Definition: item_struct.h:61
std::map< std::string, item_t > items_map_t
Type def of internal map of named items.
Definition: item_struct.h:31
items_map_t m_items
internal map of named items
Definition: item_struct.h:32
int getItem(const std::string &item_name, T &value)
Gets an item.
Definition: item_struct.cpp:18
structure to hold a dae item
Definition: item_struct.h:18
const int * dim1
dimension one array
Definition: item_struct.h:22
const T * value
array of type T
Definition: item_struct.h:19
item_t(const T *v, bool da, const int *d0, const int *d1)
Constructor.
Definition: item_struct.h:24
bool det_average
can be averaged over detectors via m_spec_array
Definition: item_struct.h:20
const int * dim0
dimension zero array
Definition: item_struct.h:21