SST  11.1.0
StructuralSimulationToolkit
statfieldinfo.h
1 // Copyright 2009-2021 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2021, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_STATAPI_STATFIELDINFO_H
13 #define SST_CORE_STATAPI_STATFIELDINFO_H
14 
15 #include "sst/core/sst_types.h"
16 
17 #include <map>
18 #include <string>
19 
20 namespace SST {
21 namespace Statistics {
22 
23 using fieldType_t = uint32_t;
24 
25 /**
26  \class StatisticFieldInfo
27 
28  The class for representing Statistic Output Fields
29 */
30 
32 {
33 public:
34  virtual const char* fieldName() const = 0;
35  virtual const char* shortName() const = 0;
36 
37  virtual ~StatisticFieldTypeBase() {}
38 
39  static StatisticFieldTypeBase* getField(fieldType_t fieldType);
40 
41  static void checkRegisterConflict(const char* oldName, const char* newName);
42 
43  static fieldType_t allocateFieldEnum();
44 
45 protected:
46  static void addField(fieldType_t id, StatisticFieldTypeBase* base);
47 
48 private:
49  static std::map<fieldType_t, StatisticFieldTypeBase*>* fields_;
50  static fieldType_t enumCounter_;
51 };
52 
53 template <class T>
55 {
56 public:
57  // constructor for initializing data
58  StatisticFieldType(const char* name, const char* shortName)
59  {
60  checkRegisterConflict(fieldName_, name);
61  checkRegisterConflict(shortName_, shortName);
62  fieldName_ = name;
63  shortName_ = shortName;
64  if ( fieldEnum_ == 0 ) { fieldEnum_ = allocateFieldEnum(); }
65 
66  fieldName_ = name;
67  shortName_ = shortName;
68  addField(fieldEnum_, this);
69  }
70 
71  static const char* getFieldName() { return fieldName_; }
72 
73  static const char* getShortName() { return shortName_; }
74 
75  static fieldType_t id() { return fieldEnum_; }
76 
77  const char* fieldName() const override { return getFieldName(); }
78 
79  const char* shortName() const override { return getShortName(); }
80 
81 private:
82  static Statistics::fieldType_t fieldEnum_;
83  static const char* fieldName_;
84  static const char* shortName_;
85 };
86 template <class T>
87 fieldType_t StatisticFieldType<T>::fieldEnum_ = 0;
88 template <class T>
89 const char* StatisticFieldType<T>::fieldName_ = nullptr;
90 template <class T>
91 const char* StatisticFieldType<T>::shortName_ = nullptr;
92 
94 {
95 public:
96  using fieldType_t = ::SST::Statistics::fieldType_t;
97  using fieldHandle_t = int32_t;
98 
99 public:
100  /** Construct a StatisticFieldInfo
101  * @param statName - Name of the statistic registering this field.
102  * @param fieldName - Name of the Field to be assigned.
103  * @param fieldType - Data type of the field.
104  */
105  StatisticFieldInfo(const char* statName, const char* fieldName, fieldType_t fieldType);
106 
107  // Get Field Data
108  /** Return the statistic name related to this field info */
109  inline const std::string& getStatName() const { return m_statName; }
110  /** Return the field name related to this field info */
111  inline const std::string& getFieldName() const { return m_fieldName; }
112  /** Return the field type related to this field info */
113  fieldType_t getFieldType() const { return m_fieldType; }
114  /** Return the field type related to this field info */
115  std::string getFieldUniqueName() const;
116 
117  /** Compare two field info structures
118  * @param FieldInfo1 - a FieldInfo to compare against.
119  * @return True if the Field Info structures are the same.
120  */
121  bool operator==(StatisticFieldInfo& FieldInfo1);
122 
123  /** Set the field handle
124  * @param handle - The assigned field handle for this FieldInfo
125  */
126  void setFieldHandle(fieldHandle_t handle) { m_fieldHandle = handle; }
127 
128  /** Get the field handle
129  * @return The assigned field handle.
130  */
131  fieldHandle_t getFieldHandle() { return m_fieldHandle; }
132 
133  static const char* getFieldTypeShortName(fieldType_t type)
134  {
135  return StatisticFieldTypeBase::getField(type)->shortName();
136  }
137 
138  static const char* getFieldTypeFullName(fieldType_t type)
139  {
140  return StatisticFieldTypeBase::getField(type)->fieldName();
141  }
142 
143  template <typename T>
144  static fieldType_t getFieldTypeFromTemplate()
145  {
146  return StatisticFieldType<T>::id();
147  }
148 
149 protected:
150  StatisticFieldInfo() {} // For serialization only
151 
152 private:
153  std::string m_statName;
154  std::string m_fieldName;
155  fieldType_t m_fieldType;
156  fieldHandle_t m_fieldHandle;
157 };
158 
159 } // namespace Statistics
160 } // namespace SST
161 
162 #endif // SST_CORE_STATAPI_STATFIELDINFO_H
The class for representing Statistic Output Fields.
Definition: statfieldinfo.h:93
fieldType_t getFieldType() const
Return the field type related to this field info.
Definition: statfieldinfo.h:113
const std::string & getStatName() const
Return the statistic name related to this field info.
Definition: statfieldinfo.h:109
fieldHandle_t getFieldHandle()
Get the field handle.
Definition: statfieldinfo.h:131
void setFieldHandle(fieldHandle_t handle)
Set the field handle.
Definition: statfieldinfo.h:126
bool operator==(StatisticFieldInfo &FieldInfo1)
Compare two field info structures.
Definition: statfieldinfo.cc:35
StatisticFieldInfo(const char *statName, const char *fieldName, fieldType_t fieldType)
Construct a StatisticFieldInfo.
Definition: statfieldinfo.cc:26
const std::string & getFieldName() const
Return the field name related to this field info.
Definition: statfieldinfo.h:111
Definition: statfieldinfo.h:31
Definition: statfieldinfo.h:54
std::string getFieldUniqueName() const
Return the field type related to this field info.
Definition: statfieldinfo.cc:41