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