| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [bcf653] | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [75dc28] | 8 | /*
 | 
|---|
 | 9 |  * ValueStorage.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Jul 22, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [75dc28] | 21 | 
 | 
|---|
| [ad011c] | 22 | #include "CodePatterns/Singleton_impl.hpp"
 | 
|---|
| [9d33ba] | 23 | 
 | 
|---|
| [e5ece4] | 24 | #include <iostream>
 | 
|---|
 | 25 | 
 | 
|---|
| [e4afb4] | 26 | #include "Actions/OptionTrait.hpp"
 | 
|---|
 | 27 | #include "Actions/OptionRegistry.hpp"
 | 
|---|
 | 28 | #include "Actions/Values.hpp"
 | 
|---|
 | 29 | #include "Actions/ValueStorage.hpp"
 | 
|---|
 | 30 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
 | 31 | #include "Descriptors/MoleculeIdDescriptor.hpp"
 | 
|---|
| [ad011c] | 32 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 33 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 34 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [e4afb4] | 35 | #include "LinearAlgebra/BoxVector.hpp"
 | 
|---|
| [cca9ef] | 36 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [e4afb4] | 37 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [0275ad] | 38 | #include "RandomNumbers/RandomNumberDistribution_Parameters.hpp"
 | 
|---|
| [6f0841] | 39 | #include "Atom/atom.hpp"
 | 
|---|
| [e4afb4] | 40 | #include "Box.hpp"
 | 
|---|
| [3bdb6d] | 41 | #include "Element/element.hpp"
 | 
|---|
| [e4afb4] | 42 | #include "molecule.hpp"
 | 
|---|
| [3bdb6d] | 43 | #include "Element/periodentafel.hpp"
 | 
|---|
| [e4afb4] | 44 | #include "World.hpp"
 | 
|---|
 | 45 | 
 | 
|---|
| [03c902] | 46 | ValueStorage::ValueStorage() :
 | 
|---|
| [ce7fdc] | 47 | OptionRegistry_instance(MoleCuilder::OptionRegistry::getInstance())
 | 
|---|
| [03c902] | 48 | {};
 | 
|---|
| [75dc28] | 49 | 
 | 
|---|
 | 50 | ValueStorage::~ValueStorage() {};
 | 
|---|
 | 51 | 
 | 
|---|
| [e4afb4] | 52 | 
 | 
|---|
 | 53 | bool ValueStorage::isCurrentValuePresent(const char *name) const
 | 
|---|
 | 54 | {
 | 
|---|
 | 55 |   return (CurrentValueMap.find(name) != CurrentValueMap.end());
 | 
|---|
 | 56 | }
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | void ValueStorage::queryCurrentValue(const char * name, const atom * &_T)
 | 
|---|
 | 59 | {
 | 
|---|
 | 60 |   int atomID = -1;
 | 
|---|
 | 61 |   if (typeid( atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 62 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 63 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 64 |     atomID = lexical_cast<int>(CurrentValueMap[name].c_str());
 | 
|---|
 | 65 |     CurrentValueMap.erase(name);
 | 
|---|
 | 66 |   } else if (typeid( const atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 67 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 68 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 69 |     atomID = lexical_cast<int>(CurrentValueMap[name].c_str());
 | 
|---|
 | 70 |     CurrentValueMap.erase(name);
 | 
|---|
 | 71 |   } else
 | 
|---|
| [882678] | 72 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 73 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 74 |             typeid(_T).name(),
 | 
|---|
 | 75 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 76 |             );
 | 
|---|
| [e4afb4] | 77 |   _T = World::getInstance().getAtom(AtomById(atomID));
 | 
|---|
 | 78 | }
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 | void ValueStorage::queryCurrentValue(const char * name, const element * &_T)  {
 | 
|---|
 | 81 |   int Z = -1;
 | 
|---|
 | 82 |   if (typeid(const element *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 83 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 84 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 85 |     Z = lexical_cast<int>(CurrentValueMap[name].c_str());
 | 
|---|
 | 86 |     CurrentValueMap.erase(name);
 | 
|---|
 | 87 |   } else
 | 
|---|
| [882678] | 88 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 89 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 90 |             typeid(_T).name(),
 | 
|---|
 | 91 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 92 |             );
 | 
|---|
| [e4afb4] | 93 |   _T = World::getInstance().getPeriode()->FindElement(Z);
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | void ValueStorage::queryCurrentValue(const char * name, const molecule * &_T) {
 | 
|---|
 | 97 |   int molID = -1;
 | 
|---|
 | 98 |   if (typeid( const molecule *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 99 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 100 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 101 |     molID = lexical_cast<int>(CurrentValueMap[name].c_str());
 | 
|---|
 | 102 |     CurrentValueMap.erase(name);
 | 
|---|
 | 103 |   } else
 | 
|---|
| [882678] | 104 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 105 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 106 |             typeid(_T).name(),
 | 
|---|
 | 107 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 108 |             );
 | 
|---|
| [e4afb4] | 109 |   _T = World::getInstance().getMolecule(MoleculeById(molID));
 | 
|---|
 | 110 | }
 | 
|---|
 | 111 | 
 | 
|---|
 | 112 | void ValueStorage::queryCurrentValue(const char * name, class Box &_T) {
 | 
|---|
| [cca9ef] | 113 |   RealSpaceMatrix M;
 | 
|---|
| [e4afb4] | 114 |   double tmp;
 | 
|---|
 | 115 |   if (typeid( Box ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 116 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 117 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 118 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
 | 119 |     stream >> tmp;
 | 
|---|
 | 120 |     M.set(0,0,tmp);
 | 
|---|
 | 121 |     stream >> tmp;
 | 
|---|
 | 122 |     M.set(0,1,tmp);
 | 
|---|
 | 123 |     M.set(1,0,tmp);
 | 
|---|
 | 124 |     stream >> tmp;
 | 
|---|
 | 125 |     M.set(0,2,tmp);
 | 
|---|
 | 126 |     M.set(2,0,tmp);
 | 
|---|
 | 127 |     stream >> tmp;
 | 
|---|
 | 128 |     M.set(1,1,tmp);
 | 
|---|
 | 129 |     stream >> tmp;
 | 
|---|
 | 130 |     M.set(1,2,tmp);
 | 
|---|
 | 131 |     M.set(2,1,tmp);
 | 
|---|
 | 132 |     stream >> tmp;
 | 
|---|
 | 133 |     M.set(2,2,tmp);
 | 
|---|
 | 134 |     _T = M;
 | 
|---|
 | 135 |     CurrentValueMap.erase(name);
 | 
|---|
 | 136 |   } else
 | 
|---|
| [882678] | 137 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 138 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 139 |             typeid(_T).name(),
 | 
|---|
 | 140 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 141 |             );
 | 
|---|
| [e4afb4] | 142 | }
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | void ValueStorage::queryCurrentValue(const char * name, class Vector &_T) {
 | 
|---|
 | 145 |   if (typeid( Vector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 146 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
 | 147 |     CurrentValueMap.erase(name);
 | 
|---|
| [78bb14] | 148 |     for (size_t i = 0; i < NDIM; ++i) {
 | 
|---|
 | 149 |       stream >> _T[i];
 | 
|---|
 | 150 |       ASSERT(!stream.fail(),
 | 
|---|
 | 151 |           "ValueStorage::queryCurrentValue() - Vector in value map has only "+toString(i)+" components!");
 | 
|---|
 | 152 |     }
 | 
|---|
| [e4afb4] | 153 |   } else
 | 
|---|
| [882678] | 154 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 155 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 156 |             typeid(_T).name(),
 | 
|---|
 | 157 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 158 |             );
 | 
|---|
| [e4afb4] | 159 | }
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 | void ValueStorage::queryCurrentValue(const char * name, class BoxVector &_T) {
 | 
|---|
 | 162 |   if (typeid( BoxVector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 163 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
 | 164 |     CurrentValueMap.erase(name);
 | 
|---|
| [78bb14] | 165 |     for (size_t i = 0; i < NDIM; ++i) {
 | 
|---|
 | 166 |       stream >> _T[i];
 | 
|---|
 | 167 |       ASSERT(!stream.fail(),
 | 
|---|
 | 168 |           "ValueStorage::queryCurrentValue() - BoxVector in value map has only "+toString(i)+" components!");
 | 
|---|
 | 169 |     }
 | 
|---|
| [e4afb4] | 170 |   } else
 | 
|---|
| [882678] | 171 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 172 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 173 |             typeid(_T).name(),
 | 
|---|
 | 174 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 175 |             );
 | 
|---|
| [e4afb4] | 176 | }
 | 
|---|
 | 177 | 
 | 
|---|
| [0275ad] | 178 | void ValueStorage::queryCurrentValue(const char * name, class RandomNumberDistribution_Parameters &_T) {
 | 
|---|
 | 179 |   if (typeid( RandomNumberDistribution_Parameters ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 180 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
| [47d041] | 181 |     LOG(0, "ValueStorage::queryCurrentValue() for "+toString(name)+" is "+CurrentValueMap[name]+".");
 | 
|---|
| [0275ad] | 182 |     CurrentValueMap.erase(name);
 | 
|---|
 | 183 |     stream >> _T;
 | 
|---|
 | 184 |     ASSERT(!stream.fail(),
 | 
|---|
 | 185 |         "ValueStorage::queryCurrentValue() - RandomNumberDistribution_Parameters in value map has only no components!");
 | 
|---|
 | 186 |   } else
 | 
|---|
| [882678] | 187 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 188 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 189 |             typeid(_T).name(),
 | 
|---|
 | 190 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 191 |             );
 | 
|---|
| [0275ad] | 192 | }
 | 
|---|
 | 193 | 
 | 
|---|
| [e4afb4] | 194 | void ValueStorage::queryCurrentValue(const char * name, std::vector<const atom *>&_T)
 | 
|---|
 | 195 | {
 | 
|---|
 | 196 |   int atomID = -1;
 | 
|---|
| [78bb14] | 197 |   size_t count = 0;
 | 
|---|
| [e4afb4] | 198 |   atom *Walker = NULL;
 | 
|---|
 | 199 |   if (typeid( std::vector<const atom *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 200 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 201 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 202 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
 | 203 |     CurrentValueMap.erase(name);
 | 
|---|
 | 204 |     while (!stream.fail()) {
 | 
|---|
 | 205 |       stream >> atomID >> ws;
 | 
|---|
| [78bb14] | 206 |       ASSERT((!stream.fail()) || (count != 0),
 | 
|---|
 | 207 |           "ValueStorage::queryCurrentValue() - Atom is missing id!");
 | 
|---|
 | 208 |       if (!stream.fail()) {
 | 
|---|
 | 209 |         Walker = World::getInstance().getAtom(AtomById(atomID));
 | 
|---|
 | 210 |         if (Walker != NULL)
 | 
|---|
 | 211 |           _T.push_back(Walker);
 | 
|---|
 | 212 |         atomID = -1;
 | 
|---|
 | 213 |         Walker = NULL;
 | 
|---|
 | 214 |         ++count;
 | 
|---|
 | 215 |       }
 | 
|---|
| [e4afb4] | 216 |     }
 | 
|---|
 | 217 |   } else
 | 
|---|
| [882678] | 218 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 219 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 220 |             typeid(_T).name(),
 | 
|---|
 | 221 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 222 |             );
 | 
|---|
| [e4afb4] | 223 | }
 | 
|---|
 | 224 | 
 | 
|---|
 | 225 | void ValueStorage::queryCurrentValue(const char * name, std::vector<const element *>&_T)
 | 
|---|
 | 226 | {
 | 
|---|
 | 227 |   int Z = -1;
 | 
|---|
| [78bb14] | 228 |   size_t count = 0;
 | 
|---|
| [e4afb4] | 229 |   const element *elemental = NULL;
 | 
|---|
 | 230 |   if (typeid( std::vector<const element *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 231 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 232 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 233 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
 | 234 |     CurrentValueMap.erase(name);
 | 
|---|
 | 235 |     while (!stream.fail()) {
 | 
|---|
 | 236 |       stream >> Z >> ws;
 | 
|---|
| [78bb14] | 237 |       ASSERT((!stream.fail()) || (count != 0),
 | 
|---|
 | 238 |           "ValueStorage::queryCurrentValue() - atomic number is missing!");
 | 
|---|
 | 239 |       if (!stream.fail()) {
 | 
|---|
 | 240 |         elemental = World::getInstance().getPeriode()->FindElement(Z);
 | 
|---|
 | 241 |         if (elemental != NULL)
 | 
|---|
 | 242 |           _T.push_back(elemental);
 | 
|---|
 | 243 |         Z = -1;
 | 
|---|
 | 244 |         ++count;
 | 
|---|
 | 245 |       }
 | 
|---|
| [e4afb4] | 246 |     }
 | 
|---|
 | 247 |   } else
 | 
|---|
| [882678] | 248 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 249 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 250 |             typeid(_T).name(),
 | 
|---|
 | 251 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 252 |             );
 | 
|---|
| [4885f85] | 253 | }
 | 
|---|
 | 254 | 
 | 
|---|
| [e4afb4] | 255 | void ValueStorage::queryCurrentValue(const char * name, std::vector<const molecule *>&_T)
 | 
|---|
 | 256 | {
 | 
|---|
 | 257 |   int molID = -1;
 | 
|---|
| [78bb14] | 258 |   size_t count = 0;
 | 
|---|
| [e4afb4] | 259 |   molecule *mol = NULL;
 | 
|---|
 | 260 |   if (typeid( std::vector<const molecule *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 261 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 262 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 263 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
 | 264 |     CurrentValueMap.erase(name);
 | 
|---|
 | 265 |     while (!stream.fail()) {
 | 
|---|
 | 266 |       stream >> molID >> ws;
 | 
|---|
| [78bb14] | 267 |       ASSERT((!stream.fail()) || (count != 0),
 | 
|---|
 | 268 |           "ValueStorage::queryCurrentValue() - molecule is missing id!");
 | 
|---|
 | 269 |       if (!stream.fail()) {
 | 
|---|
 | 270 |         mol = World::getInstance().getMolecule(MoleculeById(molID));
 | 
|---|
 | 271 |         if (mol != NULL)
 | 
|---|
 | 272 |           _T.push_back(mol);
 | 
|---|
 | 273 |         molID = -1;
 | 
|---|
 | 274 |         mol = NULL;
 | 
|---|
 | 275 |         ++count;
 | 
|---|
 | 276 |       }
 | 
|---|
| [e4afb4] | 277 |     }
 | 
|---|
 | 278 |   } else
 | 
|---|
| [882678] | 279 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 280 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 281 |             typeid(_T).name(),
 | 
|---|
 | 282 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 283 |             );
 | 
|---|
| [9d33ba] | 284 | }
 | 
|---|
 | 285 | 
 | 
|---|
| [e4afb4] | 286 | void ValueStorage::queryCurrentValue(const char * name, boost::filesystem::path&_T)
 | 
|---|
 | 287 | {
 | 
|---|
 | 288 |   std::string tmp;
 | 
|---|
 | 289 |   if (typeid( boost::filesystem::path ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 290 |     if (CurrentValueMap.find(name) == CurrentValueMap.end())
 | 
|---|
| [336e33] | 291 |       throw MissingValueException() << ValueStorageOptionName(name);
 | 
|---|
| [e4afb4] | 292 |     std::istringstream stream(CurrentValueMap[name]);
 | 
|---|
 | 293 |     CurrentValueMap.erase(name);
 | 
|---|
| [78bb14] | 294 |     stream >> tmp >> ws;
 | 
|---|
 | 295 |     ASSERT(!stream.fail(),
 | 
|---|
 | 296 |         "ValueStorage::queryCurrentValue() - boost::filesystem::path is missing!");
 | 
|---|
 | 297 |     _T = tmp;
 | 
|---|
| [e4afb4] | 298 |   } else
 | 
|---|
| [882678] | 299 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 300 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 301 |             typeid(_T).name(),
 | 
|---|
 | 302 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 303 |             );
 | 
|---|
| [4885f85] | 304 | }
 | 
|---|
 | 305 | 
 | 
|---|
| [e4afb4] | 306 | void ValueStorage::setCurrentValue(const char * name, const atom * &_T)
 | 
|---|
 | 307 | {
 | 
|---|
 | 308 |   if (typeid( const atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 309 |     std::ostringstream stream;
 | 
|---|
 | 310 |     stream << _T->getId();
 | 
|---|
 | 311 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 312 |   } else
 | 
|---|
| [882678] | 313 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 314 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 315 |             typeid(_T).name(),
 | 
|---|
 | 316 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 317 |             );
 | 
|---|
| [e4afb4] | 318 | }
 | 
|---|
 | 319 | 
 | 
|---|
 | 320 | void ValueStorage::setCurrentValue(const char * name, const element * &_T)
 | 
|---|
 | 321 | {
 | 
|---|
 | 322 |   if (typeid( const element *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 323 |     std::ostringstream stream;
 | 
|---|
 | 324 |     stream << _T->getAtomicNumber();
 | 
|---|
 | 325 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 326 |   } else
 | 
|---|
| [882678] | 327 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 328 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 329 |             typeid(_T).name(),
 | 
|---|
 | 330 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 331 |             );
 | 
|---|
| [e4afb4] | 332 | }
 | 
|---|
 | 333 | 
 | 
|---|
 | 334 | void ValueStorage::setCurrentValue(const char * name, const molecule * &_T)
 | 
|---|
 | 335 | {
 | 
|---|
 | 336 |   if (typeid( const molecule *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 337 |     std::ostringstream stream;
 | 
|---|
 | 338 |     stream << _T->getId();
 | 
|---|
 | 339 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 340 |   } else
 | 
|---|
| [882678] | 341 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 342 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 343 |             typeid(_T).name(),
 | 
|---|
 | 344 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 345 |             );
 | 
|---|
| [e4afb4] | 346 | }
 | 
|---|
 | 347 | 
 | 
|---|
 | 348 | void ValueStorage::setCurrentValue(const char * name, class Box &_T)
 | 
|---|
 | 349 | {
 | 
|---|
| [cca9ef] | 350 |   const RealSpaceMatrix &M = _T.getM();
 | 
|---|
| [e4afb4] | 351 |   if (typeid( Box ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 352 |     std::ostringstream stream;
 | 
|---|
 | 353 |     stream << M.at(0,0) << " ";
 | 
|---|
 | 354 |     stream << M.at(0,1) << " ";
 | 
|---|
 | 355 |     stream << M.at(0,2) << " ";
 | 
|---|
 | 356 |     stream << M.at(1,1) << " ";
 | 
|---|
 | 357 |     stream << M.at(1,2) << " ";
 | 
|---|
 | 358 |     stream << M.at(2,2) << " ";
 | 
|---|
 | 359 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 360 |   } else
 | 
|---|
| [882678] | 361 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 362 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 363 |             typeid(_T).name(),
 | 
|---|
 | 364 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 365 |             );
 | 
|---|
| [e4afb4] | 366 | }
 | 
|---|
 | 367 | 
 | 
|---|
 | 368 | void ValueStorage::setCurrentValue(const char * name, class Vector &_T)
 | 
|---|
 | 369 | {
 | 
|---|
 | 370 |   if (typeid( Vector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
 | 
|---|
 | 371 |     std::ostringstream stream;
 | 
|---|
 | 372 |     stream << _T[0] << " ";
 | 
|---|
 | 373 |     stream << _T[1] << " ";
 | 
|---|
 | 374 |     stream << _T[2] << " ";
 | 
|---|
 | 375 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 376 |   } else  if (typeid( BoxVector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
 | 
|---|
 | 377 |     std::ostringstream stream;
 | 
|---|
 | 378 |     stream << _T[0] << " ";
 | 
|---|
 | 379 |     stream << _T[1] << " ";
 | 
|---|
 | 380 |     stream << _T[2] << " ";
 | 
|---|
 | 381 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 382 |   } else
 | 
|---|
| [882678] | 383 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 384 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 385 |             typeid(_T).name(),
 | 
|---|
 | 386 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 387 |             );
 | 
|---|
| [e4afb4] | 388 | }
 | 
|---|
 | 389 | 
 | 
|---|
| [0275ad] | 390 | void ValueStorage::setCurrentValue(const char * name, class RandomNumberDistribution_Parameters &_T)
 | 
|---|
 | 391 | {
 | 
|---|
 | 392 |   if (typeid( RandomNumberDistribution_Parameters ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
 | 
|---|
 | 393 |     std::ostringstream stream;
 | 
|---|
 | 394 |     stream << _T;
 | 
|---|
 | 395 |     CurrentValueMap[name] = stream.str();
 | 
|---|
| [47d041] | 396 |     LOG(0, "ValueStorage::setCurrentValue() for "+toString(name)+" to "+stream.str()+".");
 | 
|---|
| [0275ad] | 397 |   } else
 | 
|---|
| [882678] | 398 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 399 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 400 |             typeid(_T).name(),
 | 
|---|
 | 401 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 402 |             );
 | 
|---|
| [0275ad] | 403 | }
 | 
|---|
 | 404 | 
 | 
|---|
| [e4afb4] | 405 | void ValueStorage::setCurrentValue(const char * name, std::vector<const atom *>&_T)
 | 
|---|
 | 406 | {
 | 
|---|
 | 407 |   if (typeid( std::vector<const atom *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 408 |     std::ostringstream stream;
 | 
|---|
 | 409 |     for (std::vector<const atom *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
 | 
|---|
 | 410 |       stream << (*iter)->getId() << " ";
 | 
|---|
 | 411 |     }
 | 
|---|
 | 412 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 413 |   } else
 | 
|---|
| [882678] | 414 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 415 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 416 |             typeid(_T).name(),
 | 
|---|
 | 417 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 418 |             );
 | 
|---|
| [e4afb4] | 419 | }
 | 
|---|
 | 420 | 
 | 
|---|
 | 421 | void ValueStorage::setCurrentValue(const char * name, std::vector<const element *>&_T)
 | 
|---|
 | 422 | {
 | 
|---|
 | 423 |   if (typeid( std::vector<const element *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 424 |     std::ostringstream stream;
 | 
|---|
 | 425 |     for (std::vector<const element *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
 | 
|---|
 | 426 |       stream << (*iter)->getAtomicNumber() << " ";
 | 
|---|
 | 427 |     }
 | 
|---|
 | 428 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 429 |   } else
 | 
|---|
| [882678] | 430 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 431 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 432 |             typeid(_T).name(),
 | 
|---|
 | 433 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 434 |             );
 | 
|---|
| [e4afb4] | 435 | }
 | 
|---|
 | 436 | 
 | 
|---|
 | 437 | void ValueStorage::setCurrentValue(const char * name, std::vector<const molecule *>&_T)
 | 
|---|
 | 438 | {
 | 
|---|
 | 439 |   if (typeid( std::vector<const molecule *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 440 |     std::ostringstream stream;
 | 
|---|
 | 441 |     for (std::vector<const molecule *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
 | 
|---|
 | 442 |       stream << (*iter)->getId() << " ";
 | 
|---|
 | 443 |     }
 | 
|---|
 | 444 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 445 |   } else
 | 
|---|
| [882678] | 446 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 447 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 448 |             typeid(_T).name(),
 | 
|---|
 | 449 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 450 |             );
 | 
|---|
| [e4afb4] | 451 | }
 | 
|---|
 | 452 | 
 | 
|---|
 | 453 | void ValueStorage::setCurrentValue(const char * name, boost::filesystem::path &_T)
 | 
|---|
 | 454 | {
 | 
|---|
 | 455 |   if (typeid( boost::filesystem::path ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
 | 
|---|
 | 456 |     std::ostringstream stream;
 | 
|---|
 | 457 |     stream << _T.string();
 | 
|---|
 | 458 |     CurrentValueMap[name] = stream.str();
 | 
|---|
 | 459 |   } else
 | 
|---|
| [882678] | 460 |     throw IllegalTypeException() << ValueStorageOptionName(name)
 | 
|---|
 | 461 |         << ValueStoragePairTypeName(std::make_pair(
 | 
|---|
 | 462 |             typeid(_T).name(),
 | 
|---|
 | 463 |             OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str())
 | 
|---|
 | 464 |             );
 | 
|---|
| [e4afb4] | 465 | }
 | 
|---|
 | 466 | 
 | 
|---|
 | 467 | const std::string ValueStorage::getCurrentValue(std::string actionname) {
 | 
|---|
 | 468 |   return CurrentValueMap[actionname];
 | 
|---|
| [4885f85] | 469 | }
 | 
|---|
 | 470 | 
 | 
|---|
| [e5ece4] | 471 | std::ostream & operator<<(std::ostream &ost, const ValueStorage &value)
 | 
|---|
 | 472 | {
 | 
|---|
 | 473 |   ost << "ValueStorage currently contains " << value.CurrentValueMap.size() << " elements:" << std::endl;
 | 
|---|
 | 474 |   for (std::map<std::string, std::string>::const_iterator iter = value.CurrentValueMap.begin();
 | 
|---|
 | 475 |       iter != value.CurrentValueMap.end();
 | 
|---|
 | 476 |       ++iter)
 | 
|---|
 | 477 |     ost << iter->first << "->" << iter->second << ", ";
 | 
|---|
 | 478 |   return ost;
 | 
|---|
 | 479 | }
 | 
|---|
 | 480 | 
 | 
|---|
 | 481 | 
 | 
|---|
| [75dc28] | 482 | CONSTRUCT_SINGLETON(ValueStorage)
 | 
|---|