SST  7.1.0
StructuralSimulationToolkit
statfieldinfo.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-NA0003525 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
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 
17 namespace SST {
18 namespace Statistics {
19 
20 ////////////////////////////////////////////////////////////////////////////////
21 // Quick Support structures for checking type (Can's use std::is_same as it is only available in C++11)
22 template <typename, typename> struct is_type_same { static const bool value = false;};
23 template <typename T> struct is_type_same<T,T> { static const bool value = true;};
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 
27 /**
28  \class StatisticFieldInfo
29 
30  The class for representing Statistic Output Fields
31 */
33 {
34 public:
35  /** Supported Field Types */
36  enum fieldType_t {UNDEFINED, UINT32, UINT64, INT32, INT64, FLOAT, DOUBLE};
37  typedef int32_t fieldHandle_t;
38 
39 public:
40  /** Construct a StatisticFieldInfo
41  * @param statName - Name of the statistic registering this field.
42  * @param fieldName - Name of the Field to be assigned.
43  * @param fieldType - Data type of the field.
44  */
45  StatisticFieldInfo(const char* statName, const char* fieldName, fieldType_t fieldType);
46 
47  // Get Field Data
48  /** Return the statistic name related to this field info */
49  inline const std::string& getStatName() const {return m_statName;}
50  /** Return the field name related to this field info */
51  inline const std::string& getFieldName() const {return m_fieldName;}
52  /** Return the field type related to this field info */
53  fieldType_t getFieldType() const {return m_fieldType;}
54  /** Return the field type related to this field info */
55  std::string getFieldUniqueName() const;
56 
57  /** Compare two field info structures
58  * @param FieldInfo1 - a FieldInfo to compare against.
59  * @return True if the Field Info structures are the same.
60  */
61  bool operator==(StatisticFieldInfo& FieldInfo1);
62 
63  /** Set the field handle
64  * @param handle - The assigned field handle for this FieldInfo
65  */
66  void setFieldHandle(fieldHandle_t handle) {m_fieldHandle = handle;}
67 
68  /** Get the field handle
69  * @return The assigned field handle.
70  */
71  fieldHandle_t getFieldHandle() {return m_fieldHandle;}
72 
73  static const char* getFieldTypeShortName(fieldType_t type);
74  static const char* getFieldTypeFullName(fieldType_t type);
75 
76  template<typename T>
77  static fieldType_t getFieldTypeFromTemplate()
78  {
79  if (is_type_same<T, int32_t >::value){return INT32; }
80  if (is_type_same<T, uint32_t >::value){return UINT32;}
81  if (is_type_same<T, int64_t >::value){return INT64; }
82  if (is_type_same<T, uint64_t >::value){return UINT64;}
83  if (is_type_same<T, float >::value){return FLOAT; }
84  if (is_type_same<T, double >::value){return DOUBLE;}
85 
86  // If we get here, the data type is undefined
87  return UNDEFINED;
88  }
89 
90 protected:
91  StatisticFieldInfo(){}; // For serialization only
92 
93 private:
94  std::string m_statName;
95  std::string m_fieldName;
96  fieldType_t m_fieldType;
97  fieldHandle_t m_fieldHandle;
98 
99 };
100 
101 } //namespace Statistics
102 } //namespace SST
103 
104 #endif
The class for representing Statistic Output Fields
Definition: statfieldinfo.h:32
Definition: statfieldinfo.h:22
const std::string & getStatName() const
Return the statistic name related to this field info.
Definition: statfieldinfo.h:49
Definition: action.cc:17
fieldHandle_t getFieldHandle()
Get the field handle.
Definition: statfieldinfo.h:71
void setFieldHandle(fieldHandle_t handle)
Set the field handle.
Definition: statfieldinfo.h:66
fieldType_t getFieldType() const
Return the field type related to this field info.
Definition: statfieldinfo.h:53
const std::string & getFieldName() const
Return the field name related to this field info.
Definition: statfieldinfo.h:51
fieldType_t
Supported Field Types.
Definition: statfieldinfo.h:36