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> class item_struct {
14public:
16 struct item_t {
17 const T *value;
19 const int *dim0;
20 const int *dim1;
22 item_t(const T *v, bool da, const int *d0, const int *d1) : value(v), det_average(da), dim0(d0), dim1(d1) {}
23 };
24
25 item_struct() : m_items(), m_spec_array(nullptr), m_ndet(0) {};
26
27private:
28 using items_map_t = std::map<std::string,
29 item_t>;
31 unsigned long *m_spec_array;
33 long m_ndet;
34public:
43 int addItem(const std::string &name, const T *value, bool det_average = false, const int *dim0 = nullptr,
44 const int *dim1 = nullptr) {
45 std::pair<typename items_map_t::iterator, bool> insert_ret;
46 insert_ret = m_items.insert(typename items_map_t::value_type(name, item_t(value, det_average, dim0, dim1)));
47 if (!insert_ret.second) {
48 return -1; // duplicate
49 } else {
50 return 0;
51 }
52 }
53
59 const item_t *findItem(const std::string &item_name, bool det_average) {
60 typename items_map_t::const_iterator iter;
61 iter = m_items.find(item_name);
62 if ((iter != m_items.end()) && (iter->second.det_average == det_average)) {
63 return &(iter->second);
64 } else {
65 return NULL;
66 }
67 }
68
69 int getItem(const std::string &item_name, T &value);
70 int getItem(const std::string &item_name, const long *spec_array, int nspec, T *lVal);
71 int getArrayItemSize(const std::string &item_name, int *dims_array, int &ndims);
72 int getArrayItem(const std::string &item_name, int nspec, T *larray);
73 int getArrayItem(const std::string &item_name, T *larray);
74};
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
structure to hold a dae item
Definition item_struct.h:13
unsigned long * m_spec_array
length m_ndet; used for averaging values
Definition item_struct.h:31
long m_ndet
with det_average
Definition item_struct.h:33
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:43
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.
const item_t * findItem(const std::string &item_name, bool det_average)
finds an item
Definition item_struct.h:59
std::map< std::string, item_t > items_map_t
Type def of internal map of named items.
Definition item_struct.h:29
items_map_t m_items
internal map of named items
Definition item_struct.h:30
int getItem(const std::string &item_name, T &value)
Gets an item.
structure to hold a dae item
Definition item_struct.h:16
const int * dim1
dimension one array
Definition item_struct.h:20
const T * value
array of type T
Definition item_struct.h:17
item_t(const T *v, bool da, const int *d0, const int *d1)
Constructor.
Definition item_struct.h:22
bool det_average
can be averaged over detectors via m_spec_array
Definition item_struct.h:18
const int * dim0
dimension zero array
Definition item_struct.h:19