LIBINT  2.6.0
iface.h
1 /*
2  * Copyright (C) 2004-2019 Edward F. Valeev
3  *
4  * This file is part of Libint.
5  *
6  * Libint is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Libint is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef _libint2_src_bin_libint_iface_h_
22 #define _libint2_src_bin_libint_iface_h_
23 
24 #include <ostream>
25 #include <sstream>
26 #include <smart_ptr.h>
27 #include <default_params.h>
28 #include <context.h>
29 #include <task.h>
30 
31 using namespace std;
32 
33 namespace libint2 {
43  class Libint2Iface {
44  public:
45  typedef std::vector<std::string> Tasks;
46  Libint2Iface(const SafePtr<CompilationParameters>& cparams,
47  const SafePtr<CodeContext>& ctext);
48  ~Libint2Iface();
49 
51  void to_types(const std::string& s) {
52  th_ << s << endl;
53  }
55  void to_params(const std::string& s) {
56  ph_ << s << endl;
57  }
59  void to_iface(const std::string& s) {
60  ih_ << s << endl;
61  }
63  void to_int_iface(const std::string& s) {
64  ii_ << s << endl;
65  }
67  void to_static_init(const std::string& s) {
68  si_ << s << endl;
69  }
71  void to_static_cleanup(const std::string& s) {
72  sc_ << s << endl;
73  }
75  //void to_libint_init(const std::string& s) {
76  // li_ << s << endl;
77  //}
78 
79  std::string macro(const std::string& label) {
80  std::string result("LIBINT2_"); result += label;
81  return result;
82  }
83 
84  std::string macro(const std::string& task_label, const std::string& label) {
85  std::string result("LIBINT2_"); result += label; if (task_label != "") { result += "_"; result += task_label; }
86  return result;
87  }
88 
89  template <typename T> std::string macro_define(const std::string& label, const T& value) {
90  oss_ .str(null_str_);
91  oss_ << "#ifndef " << macro(label) << endl;
92  oss_ << "# define " << macro(label) << " " << value << endl;
93  oss_ << "#endif" << endl;
94  return oss_.str();
95  }
96 
97  template <typename T> std::string macro_define(const std::string& task_label, const std::string& label, const T& value) {
98  oss_ .str(null_str_);
99  oss_ << "#define " << macro(task_label,label) << " " << value << endl;
100  return oss_.str();
101  }
102 
103  template <typename T> std::string var_declare_v(const std::string& label) {
104  return ctext_->declare_v(ctext_->type_name<T>(),ctext_->label_to_name(label),macro("MAX_VECLEN"));
105  }
106 
107  private:
108  std::string null_str_;
109  std::ostringstream oss_;
110  SafePtr<CompilationParameters> cparams_;
111  SafePtr<CodeContext> ctext_;
112 
113  // computation-specific functions are libint2_init_xxx, libint2_cleanup_xxx, etc. -- these are their declarations,
114  // e.g. "libint2_init_xxx(Libint_t* libint, int max_am, LIBINT2_REALTYPE* buf)"
115  std::vector<std::string> li_decls_; // _init_
116  std::vector<std::string> lm_decls_; // _need_memory_
117  std::vector<std::string> lc_decls_; // _cleanup_
118 
119  std::string lf_decl_; // _init_flopcounter
120 
121  typedef std::basic_ofstream<char> fstream;
122 
123  fstream th_;
124  fstream ph_;
125  fstream ih_;
126  fstream ii_;
127  fstream si_;
128  fstream sc_;
129  fstream li_;
130 
131  void generate_inteval_type(std::ostream& os);
132 
133  };
134 };
135 
136 #endif
137 
void to_static_init(const std::string &s)
Writes string s to the static init code.
Definition: iface.h:67
Libint2Iface is used to generate Libint2 interfaces.
Definition: iface.h:43
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
void to_int_iface(const std::string &s)
Writes string s to the internal iface header.
Definition: iface.h:63
void to_params(const std::string &s)
Writes string s to the params header.
Definition: iface.h:55
void to_types(const std::string &s)
Writes string s to the types header.
Definition: iface.h:51
void to_iface(const std::string &s)
Writes string s to the iface header.
Definition: iface.h:59
void to_static_cleanup(const std::string &s)
Writes string s to the static cleanup code.
Definition: iface.h:71
std::string macro(const std::string &label)
Writes string s to the Libint_t init code.
Definition: iface.h:79