21 #ifndef _libint2_src_bin_libint_entity_h_ 22 #define _libint2_src_bin_libint_entity_h_ 29 #include <class_registry.h> 36 namespace EntityTypes {
37 typedef enum {fp, integer} EntityTypeEnum;
39 template <
unsigned int TypeIndex>
41 static unsigned int type2int() {
49 static const unsigned int ntypes = 2;
53 template <
typename T,
typename U>
55 template <>
struct ProductType<int,int> {
typedef int result; };
56 template <>
struct ProductType<int,double> {
typedef double result; };
57 template <>
struct ProductType<double,int> {
typedef double result; };
58 template <>
struct ProductType<double,double> {
typedef double result; };
75 std::ostringstream oss; oss << std::scientific << std::setprecision(std::numeric_limits<T>::digits10 + 1) << x;
return oss.str();
86 const std::string&
id()
const {
return id_; }
89 Entity(
const std::string&
id) : id_(
id) {}
109 RTimeEntity(
const std::string&
id,
bool p =
true) :
113 key_ = KeyTypes::cast(SH.
hash(
id));
115 std::cout <<
"Allocated RTimeEntity id = " << this->
id() << std::endl;
122 std::cout <<
"Deallocated RTimeEntity id = " << this->
id() << std::endl;
127 unsigned int size()
const {
return 1; }
130 bool equiv(
const SafePtr<DGVertex>& a)
const 133 #if USE_INT_KEY_TO_COMPARE 134 return key() == a->key() &&
label() == a->label();
136 SafePtr<RTimeEntity> a_cast = static_pointer_cast<RTimeEntity,DGVertex>(a);
137 return id() == a_cast->id();
150 const std::string&
id()
const 158 os <<
"RTimeEntity: " <<
id();
159 const std::string descr = os.str();
163 typename DGVertex::KeyReturnType
key()
const {
169 bool this_precomputed()
const 195 std::cout <<
"Allocated CTimeEntity id = " << this->
id() <<
" value = " <<
value() << std::endl;
202 std::cout <<
"Deallocated CTimeEntity id = " << this->
id() <<
" value = " <<
value() << std::endl;
207 unsigned int size()
const {
return 1; }
210 bool equiv(
const SafePtr<DGVertex>& a)
const 213 #if USE_INT_KEY_TO_COMPARE 214 return key() == a->key();
216 SafePtr<CTimeEntity> a_cast = static_pointer_cast<CTimeEntity,DGVertex>(a);
217 return id() == a_cast->id();
230 const std::string&
id()
const 238 os <<
"CTimeEntity: " <<
id();
239 const std::string descr = os.str();
244 typename KeyTraits<T>::ReturnType
value()
const {
return value_; }
247 typename DGVertex::KeyReturnType
key()
const {
248 if (std::is_floating_point<T>::value) {
249 if (not std::is_same<T,double>::value)
250 throw std::runtime_error(
"CTimeEntity<Real> only supported when Real==double");
251 return static_cast<typename DGVertex::KeyReturnType>(*reinterpret_cast<const unsigned long*>(&value_));
254 return static_cast<typename DGVertex::KeyReturnType>(
value());
261 bool this_precomputed()
const 278 template <
typename T,
typename U>
279 SafePtr< CTimeEntity< typename ProductType<T,U>::result > >
283 return SafePtr<prodtype>(
new prodtype(A->value()*B->value()));
288 template <
typename T,
typename U>
289 SafePtr< RTimeEntity< typename ProductType<T,U>::result > >
294 oss << A->
id() <<
"*" << B->id();
296 const bool not_precomputed =
true;
297 return SafePtr<prodtype>(
new prodtype(oss.str(), not_precomputed));
303 template <
typename T,
typename U>
304 SafePtr< RTimeEntity< typename ProductType<T,U>::result > >
unsigned int size() const
Implementation of DGVertex::size()
Definition: entity.h:207
const std::string & id() const
Implementation of DGVertex::id()
Definition: entity.h:150
KeyTypes::InstanceID KeyType
DGVertex provides function key() which computes key of type KeyType and returns it using KeyReturnTyp...
Definition: dgvertex.h:61
CTimeEntity is an Entity of type T that exists at compile-time of the generated code (hence has a val...
Definition: entity.h:186
bool equiv(const SafePtr< DGVertex > &a) const
Implementation of DGVertex::equiv()
Definition: entity.h:130
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
SafePtr< CTimeEntity< typename ProductType< T, U >::result > > operator*(const SafePtr< CTimeEntity< T > > &A, const SafePtr< CTimeEntity< U > > &B)
Creates product A*B.
Definition: entity.h:280
Product of 2 types.
Definition: entity.h:54
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:43
const std::string & label() const
Implementation of DGVertex::label()
Definition: entity.h:145
unsigned int size() const
Implementation of DGVertex::size()
Definition: entity.h:127
DGVertex::KeyReturnType key() const
Implements Hashable::key()
Definition: entity.h:163
DGVertex(ClassID tid)
Sets typeid to tid.
Definition: dgvertex.cc:31
FNVStringHash uses Fowler/Noll/Vo algorithm to hash a char string to a 64-bit integer.
Definition: hashable.h:88
RTimeEntity is an Entity of type T that exists at runtime of the generated code (hence has no value k...
Definition: entity.h:102
Entity is a base class for all objects that exist at compile or runtime of the generated code.
Definition: entity.h:81
std::string to_string(const T &x)
Converts x to its string representation.
Definition: entity.h:74
DGVertex::KeyReturnType key() const
Implements Hashable::key()
Definition: entity.h:247
KeyTraits< T >::ReturnType value() const
returns the value
Definition: entity.h:244
const std::string & id() const
Implementation of DGVertex::id()
Definition: entity.h:230
const std::string & label() const
Implementation of DGVertex::label()
Definition: entity.h:225
Objects of this type provide limited information about the class at runtime.
Definition: class_registry.h:44
bool equiv(const SafePtr< DGVertex > &a) const
Implementation of DGVertex::equiv()
Definition: entity.h:210
const std::string & id() const
Return id string.
Definition: entity.h:86
std::string description() const
Implementation of DGVertex::description()
Definition: entity.h:235
LIBINT2_UINT_LEAST64 hash(const std::string &S)
Returns 64-bit integer hash of S.
Definition: hashable.h:111
ClassID typeid_
typeid stores the ClassID of the concrete type.
Definition: dgvertex.h:68
std::string description() const
Implementation of DGVertex::description()
Definition: entity.h:155