LIBINT  2.6.0
task.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_task_h_
22 #define _libint2_src_bin_libint_task_h_
23 
24 #include <string>
25 #include <vector>
26 #include <list>
27 #include <map>
28 #include <rr.h>
29 #include <default_params.h>
30 
31 namespace libint2 {
32 
33  class TaskExternSymbols;
34 
45  class LibraryTask {
46  public:
47  LibraryTask(const std::string& l, const SafePtr<TaskParameters>& p, const SafePtr<TaskExternSymbols>& s) :
48  label_(l), params_(p), symbols_(s) {
49  }
50  ~LibraryTask() {
51  }
52  const std::string& label() const { return label_; }
53  const SafePtr<TaskParameters>& params() const { return params_; }
54  const SafePtr<TaskExternSymbols>& symbols() const { return symbols_; }
55 
56  private:
57  std::string label_;
58  SafePtr<TaskParameters> params_;
59  SafePtr<TaskExternSymbols> symbols_;
60  };
61 
64  typedef std::vector<LibraryTask> Tasks;
65  typedef Tasks::const_iterator tasks_citer;
66 
67  public:
68  typedef Tasks::const_iterator TasksCIter;
69  typedef Tasks::iterator TasksIter;
70 
72  static LibraryTaskManager& Instance();
73  ~LibraryTaskManager() {}
74 
76  unsigned int ntask() const { return tasks_.size(); }
78  TasksCIter first() const { return tasks_.begin(); }
80  TasksCIter plast() const { return tasks_.end(); }
82  LibraryTask& task(unsigned int i) { return tasks_.at(i); }
84  void add(const std::string& task_label);
86  bool exists(const std::string& task_label) const;
88  TasksCIter find(const std::string& task_label) const;
90  void current(const std::string& task_label);
93 
94  private:
95 
97  Tasks tasks_;
98  int current_;
99 
100  static LibraryTaskManager LTM_obj_;
101  };
102 
108  public:
109  typedef std::list<std::string> SymbolList;
111  typedef RRStack::InstanceID RRid;
112  typedef std::list<RRid> RRList;
113 
114  TaskExternSymbols() {}
115  ~TaskExternSymbols() {}
116 
118  void add(const SymbolList& symbols);
121  const SymbolList& symbols() const;
123  void add(const RRList& rrlist);
125  bool find(const RRid& rrid) const;
127  RRList rrlist() const;
128 
129  private:
130  // Maintain symbols as a map since each symbol only needs to appear once
131  typedef std::map<std::string,bool> Symbols;
132  Symbols symbols_;
133  mutable SymbolList symbollist_; // only used to return a list
134 
135  // Maintain RR list as a map, although RRStack already handles them that way -- hopefully this will speed up searching somewhat
136  typedef std::map<RRid,bool> RRmap;
137  RRmap rrmap_;
138 
139  };
140 
141 };
142 
143 #endif // header guard
unsigned int ntask() const
Number of tasks.
Definition: task.h:76
bool find(const RRid &rrid) const
Is this RR found in the list?
Definition: task.cc:133
RRStack::InstanceID RRid
Recurrence relations are maintained by RRStack and characterized by their unique numeric ID.
Definition: task.h:111
LibraryTask & task(unsigned int i)
i-th tasks
Definition: task.h:82
Manages tasks. This is a Singleton.
Definition: task.h:63
LibraryTask & current()
Returns the current task.
Definition: task.cc:89
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
A key idea introduced here is that of "task".
Definition: task.h:45
void add(const SymbolList &symbols)
Add the symbols.
Definition: task.cc:100
bool exists(const std::string &task_label) const
Definition: task.cc:54
RRList rrlist() const
Definition: task.cc:141
const SymbolList & symbols() const
Return the symbols.
Definition: task.cc:120
void add(const std::string &task_label)
Adds a new task. Do nothing if the task exists already.
Definition: task.cc:40
TasksCIter first() const
returns iterator to the first task
Definition: task.h:78
TasksCIter plast() const
returns iterator to past the last task
Definition: task.h:80
static LibraryTaskManager & Instance()
LibraryTaskManager is a Singleton.
Definition: task.cc:34
This class maintains code symbols provided by the user, e.g.
Definition: task.h:107
TasksCIter find(const std::string &task_label) const
Find the task by name and return the iterator pointing to it. Throws ProgrammingError,...
Definition: task.cc:65