20 #ifndef _libint2_src_bin_libint_entity_h_ 21 #define _libint2_src_bin_libint_entity_h_ 26 #include <class_registry.h> 33 namespace EntityTypes {
34 typedef enum {fp, integer} EntityTypeEnum;
36 template <
unsigned int TypeIndex>
38 static unsigned int type2int() {
46 static const unsigned int ntypes = 2;
50 template <
typename T,
typename U>
52 template <>
struct ProductType<int,int> {
typedef int result; };
53 template <>
struct ProductType<int,double> {
typedef double result; };
54 template <>
struct ProductType<double,int> {
typedef double result; };
55 template <>
struct ProductType<double,double> {
typedef double result; };
72 std::ostringstream oss; oss << x;
return oss.str();
83 const std::string&
id()
const {
return id_; }
86 Entity(
const std::string&
id) : id_(
id) {}
106 RTimeEntity(
const std::string&
id,
bool p =
true) :
110 key_ = KeyTypes::cast(SH.
hash(
id));
112 std::cout <<
"Allocated RTimeEntity id = " << this->id() << std::endl;
119 std::cout <<
"Deallocated RTimeEntity id = " << this->id() << std::endl;
124 unsigned int size()
const {
return 1; }
127 bool equiv(
const SafePtr<DGVertex>& a)
const 129 if (a->typeid_ == typeid_) {
130 #if USE_INT_KEY_TO_COMPARE 131 return key() == a->key() && label() == a->label();
134 return id() == a_cast->
id();
147 const std::string&
id()
const 155 os <<
"RTimeEntity: " << id();
156 const std::string descr = os.str();
160 typename DGVertex::KeyReturnType
key()
const {
166 bool this_precomputed()
const 192 std::cout <<
"Allocated CTimeEntity id = " << this->id() <<
" value = " << value() << std::endl;
199 std::cout <<
"Deallocated CTimeEntity id = " << this->id() <<
" value = " << value() << std::endl;
204 unsigned int size()
const {
return 1; }
207 bool equiv(
const SafePtr<DGVertex>& a)
const 209 if (a->typeid_ == typeid_) {
210 #if USE_INT_KEY_TO_COMPARE 211 return key() == a->key();
214 return id() == a_cast->
id();
227 const std::string&
id()
const 235 os <<
"CTimeEntity: " << id();
236 const std::string descr = os.str();
241 typename KeyTraits<T>::ReturnType
value()
const {
return value_; }
244 typename DGVertex::KeyReturnType
key()
const {
245 if (std::is_floating_point<T>::value) {
246 if (not std::is_same<T,double>::value)
247 throw std::runtime_error(
"CTimeEntity<Real> only supported when Real==double");
248 return static_cast<typename DGVertex::KeyReturnType
>(*
reinterpret_cast<const unsigned long*
>(&value_));
251 return static_cast<typename DGVertex::KeyReturnType
>(value());
258 bool this_precomputed()
const 275 template <
typename T,
typename U>
276 SafePtr< CTimeEntity< typename ProductType<T,U>::result > >
280 return SafePtr<prodtype>(
new prodtype(A->value()*B->value()));
285 template <
typename T,
typename U>
286 SafePtr< RTimeEntity< typename ProductType<T,U>::result > >
291 oss << A->
id() <<
"*" << B->id();
293 const bool not_precomputed =
true;
294 return SafePtr<prodtype>(
new prodtype(oss.str(), not_precomputed));
300 template <
typename T,
typename U>
301 SafePtr< RTimeEntity< typename ProductType<T,U>::result > >
bool equiv(const SafePtr< DGVertex > &a) const
Implementation of DGVertex::equiv()
Definition: entity.h:127
bool equiv(const SafePtr< DGVertex > &a) const
Implementation of DGVertex::equiv()
Definition: entity.h:207
KeyTypes::InstanceID KeyType
DGVertex provides function key() which computes key of type KeyType and returns it using KeyReturnTyp...
Definition: dgvertex.h:60
CTimeEntity is an Entity of type T that exists at compile-time of the generated code (hence has a val...
Definition: entity.h:183
unsigned int size() const
Implementation of DGVertex::size()
Definition: entity.h:124
const std::string & id() const
Implementation of DGVertex::id()
Definition: entity.h:147
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
const std::string & id() const
Implementation of DGVertex::id()
Definition: entity.h:227
const std::string & label() const
Implementation of DGVertex::label()
Definition: entity.h:222
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:277
const std::string & id() const
Return id string.
Definition: entity.h:83
Product of 2 types.
Definition: entity.h:51
This is a vertex of a Directed Graph (DG)
Definition: dgvertex.h:42
std::string description() const
Implementation of DGVertex::description()
Definition: entity.h:232
KeyTraits< T >::ReturnType value() const
returns the value
Definition: entity.h:241
FNVStringHash uses Fowler/Noll/Vo algorithm to hash a char string to a 64-bit integer.
Definition: hashable.h:87
DGVertex::KeyReturnType key() const
Implements Hashable::key()
Definition: entity.h:160
RTimeEntity is an Entity of type T that exists at runtime of the generated code (hence has no value k...
Definition: entity.h:99
Entity is a base class for all objects that exist at compile or runtime of the generated code...
Definition: entity.h:78
std::string to_string(const T &x)
Converts x to its string representation.
Definition: entity.h:71
std::string description() const
Implementation of DGVertex::description()
Definition: entity.h:152
const std::string & label() const
Implementation of DGVertex::label()
Definition: entity.h:142
Objects of this type provide limited information about the class at runtime.
Definition: class_registry.h:43
unsigned int size() const
Implementation of DGVertex::size()
Definition: entity.h:204
virtual const std::string & id() const =0
id() returns a very short label of DGVertex which is (almost) guaranteed to be a symbol (e...
DGVertex::KeyReturnType key() const
Implements Hashable::key()
Definition: entity.h:244
LIBINT2_UINT_LEAST64 hash(const std::string &S)
Returns 64-bit integer hash of S.
Definition: hashable.h:110