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