CHROMA
key_val_db.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Key and values for DB
4  */
5 
6 #ifndef __key_val_db_h__
7 #define __key_val_db_h__
8 
9 #include "chromabase.h"
10 #include "qdp_db.h"
11 
12 namespace Chroma
13 {
14  using namespace FILEDB;
15 
16  //---------------------------------------------------------------------
17  //! Serializable key harness
18  /*! \ingroup ferm */
19  template<typename K>
20  class SerialDBKey : public DBKey
21  {
22  public:
23  //! Default constructor
25 
26  //! Constructor from data
27  SerialDBKey(const K& k) : key_(k) {}
28 
29  //! Setter
30  K& key() {return key_;}
31 
32  //! Getter
33  const K& key() const {return key_;}
34 
35  // Part of Serializable
36  const unsigned short serialID (void) const {return 456;}
37 
38  void writeObject (std::string& output) const throw (SerializeException) {
39  BinaryBufferWriter bin;
40  write(bin, key());
41  output = bin.strPrimaryNode();
42  }
43 
44  void readObject (const std::string& input) throw (SerializeException) {
45  BinaryBufferReader bin(input);
46  read(bin, key());
47  }
48 
49  // Part of DBKey
50  int hasHashFunc (void) const {return 0;}
51  int hasCompareFunc (void) const {return 0;}
52 
53  /**
54  * Empty hash and compare functions. We are using default functions.
55  */
56  static unsigned int hash (const void* bytes, unsigned int len) {return 0;}
57  static int compare (const FFDB_DBT* k1, const FFDB_DBT* k2) {return 0;}
58 
59  private:
61  };
62 
63 
64  //---------------------------------------------------------------------
65  //! Serializable value harness
66  /*! \ingroup ferm */
67  template<typename D>
68  class SerialDBData : public DBData
69  {
70  public:
71  //! Default constructor
73 
74  //! Constructor from data
75  SerialDBData(const D& d) : data_(d) {}
76 
77  //! Setter
78  D& data() {return data_;}
79 
80  //! Getter
81  const D& data() const {return data_;}
82 
83  // Part of Serializable
84  const unsigned short serialID (void) const {return 123;}
85 
86  void writeObject (std::string& output) const throw (SerializeException) {
87  BinaryBufferWriter bin;
88  write(bin, data());
89  output = bin.strPrimaryNode();
90  }
91 
92  void readObject (const std::string& input) throw (SerializeException) {
93  BinaryBufferReader bin(input);
94  read(bin, data());
95  }
96 
97  private:
98  D data_;
99  };
100 
101 } // namespace Chroma
102 
103 #endif
Primary include file for CHROMA library code.
Serializable value harness.
Definition: key_val_db.h:69
void readObject(const std::string &input)
Definition: key_val_db.h:92
const D & data() const
Getter.
Definition: key_val_db.h:81
SerialDBData(const D &d)
Constructor from data.
Definition: key_val_db.h:75
D & data()
Setter.
Definition: key_val_db.h:78
SerialDBData()
Default constructor.
Definition: key_val_db.h:72
const unsigned short serialID(void) const
Definition: key_val_db.h:84
void writeObject(std::string &output) const
Definition: key_val_db.h:86
Serializable key harness.
Definition: key_val_db.h:21
K & key()
Setter.
Definition: key_val_db.h:30
int hasCompareFunc(void) const
Definition: key_val_db.h:51
static unsigned int hash(const void *bytes, unsigned int len)
Definition: key_val_db.h:56
int hasHashFunc(void) const
Definition: key_val_db.h:50
SerialDBKey(const K &k)
Constructor from data.
Definition: key_val_db.h:27
static int compare(const FFDB_DBT *k1, const FFDB_DBT *k2)
Definition: key_val_db.h:57
void readObject(const std::string &input)
Definition: key_val_db.h:44
void writeObject(std::string &output) const
Definition: key_val_db.h:38
const unsigned short serialID(void) const
Definition: key_val_db.h:36
SerialDBKey()
Default constructor.
Definition: key_val_db.h:24
const K & key() const
Getter.
Definition: key_val_db.h:33
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
DComplex d
Definition: invbicg.cc:99
int k
Definition: invbicg.cc:119
::std::string string
Definition: gtest.h:1979
static INTERNAL_PRECISION K