10 #include <AtomsCore/Globals.h>
11 #include <AtomsCore/Metadata/Metadata.h>
12 #include <AtomsCore/Metadata/MetadataTraits.h>
16 #define METADATA_SPEC_DECLARE(TYPE) template class ATOMSCORE_EXPORT MetadataImpl<TYPE>;
18 #define METADATA_SPEC_DECLARE(TYPE)
21 #define DECLARE_METADATA(NAME, TYPE) \
22 typedef MetadataImpl<TYPE> NAME; \
23 template<> ATOMSCORE_EXPORT std::string MetadataImpl<TYPE>::staticTypeStr(); \
24 template<> ATOMSCORE_EXPORT unsigned int MetadataImpl<TYPE>::staticTypeId(); \
25 template<> ATOMSCORE_EXPORT std::string MetadataImpl<TYPE>::staticBaseTypeStr(); \
26 METADATA_SPEC_DECLARE(TYPE) \
28 #define DECLARE_METADATA_WITH_BLEND(NAME, TYPE) \
29 typedef MetadataImpl<TYPE> NAME; \
30 template<> ATOMSCORE_EXPORT std::string MetadataImpl<TYPE>::staticTypeStr(); \
31 template<> ATOMSCORE_EXPORT unsigned int MetadataImpl<TYPE>::staticTypeId(); \
32 template<> ATOMSCORE_EXPORT std::string MetadataImpl<TYPE>::staticBaseTypeStr(); \
33 template<> ATOMSCORE_EXPORT bool MetadataImpl<TYPE>::setWithValuesAndWeights(const std::vector<AtomsPtr<Metadata>> &values, const std::vector<double> &weights); \
34 template<> ATOMSCORE_EXPORT bool MetadataImpl<TYPE>::setWithValuesAndWeights(const std::vector<Metadata *> &values, const std::vector<double> &weights); \
35 METADATA_SPEC_DECLARE(TYPE) \
37 #define DEFINE_METADATA_TYPE(NAME, TYPE, ID) \
38 template<> std::string MetadataImpl<TYPE>::staticTypeStr() { return #NAME; } \
39 template<> unsigned int MetadataImpl<TYPE>::staticTypeId() { return ID; } \
40 template<> std::string MetadataImpl<TYPE>::staticBaseTypeStr() { return #TYPE; } \
41 template class MetadataImpl<TYPE>; \
43 #define DEFINE_METADATA_BASE_BLEND(TYPE, CAST_TYPE) \
44 template<> bool MetadataImpl<TYPE>::setWithValuesAndWeights(const std::vector<AtomsPtr<Metadata>> &values, const std::vector<double> &weights) \
46 size_t vSize = values.size(); \
47 size_t wSize = weights.size(); \
48 if (vSize == 0 || vSize != wSize) \
50 m_value = static_cast<TYPE>(static_cast<CAST_TYPE>(std::static_pointer_cast<MetadataImpl<TYPE>>(values[0])->get()) * weights[0]); \
51 for (size_t i = 1; i < vSize; ++i) \
52 m_value += static_cast<TYPE>(static_cast<CAST_TYPE>(std::static_pointer_cast<MetadataImpl<TYPE>>(values[i])->get()) * weights[i]); \
56 template<> bool MetadataImpl<TYPE>::setWithValuesAndWeights(const std::vector<Metadata *> &values, const std::vector<double> &weights) \
58 size_t vSize = values.size(); \
59 size_t wSize = weights.size(); \
60 if (vSize == 0 || vSize != wSize) \
62 m_value = static_cast<TYPE>(static_cast<CAST_TYPE>(static_cast<MetadataImpl<TYPE> *>(values[0])->get()) * weights[0]); \
63 for (size_t i = 1; i < vSize; ++i) \
64 m_value += static_cast<TYPE>(static_cast<CAST_TYPE>(static_cast<MetadataImpl<TYPE> *>(values[i])->get()) * weights[i]); \
68 #define DEFINE_METADATA_TYPE_WITH_BLEND(NAME, TYPE, ID) \
69 DEFINE_METADATA_TYPE(NAME, TYPE, ID) \
70 DEFINE_METADATA_BASE_BLEND(TYPE, double) \
72 #define DEFINE_METADATA_TYPE_WITH_VECTOR_TYPE_BLEND(NAME, TYPE, ID) \
73 DEFINE_METADATA_TYPE(NAME, TYPE, ID) \
74 DEFINE_METADATA_BASE_BLEND(TYPE, TYPE) \
76 #define DECLARE_MEADATA_COMPARISION(TYPE) \
77 template<> ATOMSCORE_EXPORT bool MetadataImpl<TYPE>::isEqual(Metadata* right, double err) const; \
78 template<> ATOMSCORE_EXPORT bool MetadataImpl<TYPE>::isGreater(Metadata* right) const; \
79 template<> ATOMSCORE_EXPORT bool MetadataImpl<TYPE>::isLess(Metadata* right) const; \
81 #define DEFINE_MEADATA_BASE_COMPARISION(TYPE) \
82 template<> bool MetadataImpl<TYPE>::isEqual(Metadata* right, double err) const \
84 if (this == right) return true; \
85 if (!right || right->typeId() != typeId()) return false; \
86 return m_value == static_cast<MetadataImpl<TYPE>*>(right)->get();\
89 template<> bool MetadataImpl<TYPE>::isGreater(Metadata* right) const \
91 if (this == right) return false; \
92 if (!right || right->typeId() != typeId()) return false; \
93 return m_value > static_cast<MetadataImpl<TYPE>*>(right)->get();\
96 template<> bool MetadataImpl<TYPE>::isLess(Metadata* right) const\
98 if (this == right) return false; \
99 if (!right || right->typeId() != typeId()) return false; \
100 return m_value < static_cast<MetadataImpl<TYPE>*>(right)->get();\
103 #define DEFINE_MEADATA_BASE_ABS_COMPARISION(TYPE) \
104 template<> bool MetadataImpl<TYPE>::isEqual(Metadata* right, double err) const \
106 if (this == right) return true; \
107 if (!right || right->typeId() != typeId()) return false; \
108 return std::abs(m_value - static_cast<MetadataImpl<TYPE>*>(right)->get()) < err;\
111 template<> bool MetadataImpl<TYPE>::isGreater(Metadata* right) const \
113 if (this == right) return false; \
114 if (!right || right->typeId() != typeId()) return false; \
115 return m_value > static_cast<MetadataImpl<TYPE>*>(right)->get();\
118 template<> bool MetadataImpl<TYPE>::isLess(Metadata* right) const\
120 if (this == right) return false; \
121 if (!right || right->typeId() != typeId()) return false; \
122 return m_value < static_cast<MetadataImpl<TYPE>*>(right)->get();\
125 #define DEFINE_MEADATA_VECTOR_COMPARISION(TYPE) \
126 template<> bool MetadataImpl<TYPE>::isEqual(Metadata* right, double err) const \
128 if (this == right) return true; \
129 if (right->typeId() != typeId()) return false; \
130 return m_value.equalWithAbsError(static_cast<MetadataImpl<TYPE>*>(right)->get(), err);\
133 template<> bool MetadataImpl<TYPE>::isGreater(Metadata* right) const \
135 if (this == right) return false; \
136 if (right->typeId() != typeId()) return false; \
137 auto& rightValue = static_cast<MetadataImpl<TYPE>*>(right)->get(); \
138 for (unsigned int i = 0; i < m_value.dimensions(); ++i) \
139 if (m_value[i] < rightValue[i]) return false; \
143 template<> bool MetadataImpl<TYPE>::isLess(Metadata* right) const\
145 if (this == right) return false; \
146 if (right->typeId() != typeId()) return false; \
147 auto& rightValue = static_cast<MetadataImpl<TYPE>*>(right)->get(); \
148 for (unsigned int i = 0; i < m_value.dimensions(); ++i) \
149 if (m_value[i] > rightValue[i]) return false; \
156 template <
typename T>
174 unsigned int typeId()
const;
214 virtual AtomsPtr<Metadata>
clone()
const;
220 virtual size_t memSize()
const;
235 const T&
get()
const;
245 virtual bool setWithValuesAndWeights(
const std::vector<AtomsPtr<Metadata>> &values,
const std::vector<double> &weights);
246 virtual bool setWithValuesAndWeights(
const std::vector<Metadata *> &values,
const std::vector<double> &weights);
261 virtual void* dataPtr() {
return reinterpret_cast<void*
>(&m_value); }
279 virtual void toString(std::stringstream& ss)
const;
288 #include "MetadataImpl.impl.h"
Archive class.
Definition: Serialiser.h:29
AtomsCore namespace.
Definition: Agent.h:344