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