1 #ifndef CYCLUS_SRC_TOOLKIT_RES_MAP_H_ 2 #define CYCLUS_SRC_TOOLKIT_RES_MAP_H_ 40 template <
class K,
class R>
43 ResMap() : dirty_quantity_(true), quantity_(0) {
44 Warn<EXPERIMENTAL_WARNING>(
"ResMap is experimental and its API may be " 50 typedef typename std::map<K, typename R::Ptr>
map_type;
51 typedef typename std::map<K, typename R::Ptr>::iterator
iterator;
52 typedef typename std::map<K, typename R::Ptr>::const_iterator
const_iterator;
63 inline int size()
const {
return resources_.size(); }
74 iterator it = resources_.begin();
75 for (; it != resources_.end(); ++it) {
76 obj_ids_[it->first] = it->second->obj_id();
83 dirty_quantity_ =
true;
87 inline bool empty()
const {
return resources_.empty(); }
95 dirty_quantity_ =
true;
101 dirty_quantity_ =
true;
102 return const_cast<map_type&
>(resources_)[k];
107 dirty_quantity_ =
true;
108 return resources_.begin();
112 const_iterator
begin()
const {
return resources_.begin(); }
115 const_iterator
cbegin()
const {
return resources_.begin(); }
119 dirty_quantity_ =
true;
120 return resources_.end();
124 const_iterator
end()
const {
return resources_.end(); }
127 const_iterator
cend()
const {
return resources_.end(); }
131 resources_.erase(position);
136 typename map_type::size_type
erase(
const K& k) {
137 typename map_type::size_type s = resources_.erase(k);
143 void erase(iterator first, iterator last) {
144 resources_.erase(first, last);
152 dirty_quantity_ =
true;
162 int n = resources_.size();
163 std::vector<typename R::Ptr> vals (n);
164 iterator it = resources_.begin();
165 while (it != resources_.end()) {
166 vals[i] = it->second;
179 void Values(std::vector<typename R::Ptr> vals) {
180 std::map<int, K> lookup;
181 obj_iterator oit = obj_ids_.begin();
182 for (; oit != obj_ids_.end(); ++oit) {
183 lookup[oit->second] = oit->first;
188 resources_[lookup[vals[i]->obj_id()]] = vals[i];
190 dirty_quantity_ =
true;
197 Values(cyclus::template ResCast<R>(vals));
201 typename R::Ptr
Pop(
const K key) {
202 iterator it = resources_.find(key);
203 if (it == resources_.end()) {
204 std::stringstream ss;
205 ss <<
"key " << key <<
" could not be found";
208 typename R::Ptr val = it->second;
209 resources_.erase(it);
210 dirty_quantity_ =
true;
216 void UpdateQuantity() {
218 iterator it = resources_.begin();
220 int n = resources_.size();
224 vector<double> qtys (n, 0.0);
225 while (it != resources_.end()) {
226 qtys[i] = (*(it->second)).quantity();
232 dirty_quantity_ =
false;
236 bool dirty_quantity_;
251 #endif // CYCLUS_SRC_TOOLKIT_RES_MAP_H_
static double KahanSum(std::vector< double > input)
sums the materials in the vector in an intelligent way, to avoid floating point issues.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Declares the CycArithmetic class, which holds arithmetic algorithms.
For failed retrieval/insertion of key-based data into/from data structures.