| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /* | 
|---|
| 9 | * ValueStorage.cpp | 
|---|
| 10 | * | 
|---|
| 11 | *  Created on: Jul 22, 2010 | 
|---|
| 12 | *      Author: heber | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | // include config.h | 
|---|
| 16 | #ifdef HAVE_CONFIG_H | 
|---|
| 17 | #include <config.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include "CodePatterns/Singleton_impl.hpp" | 
|---|
| 23 |  | 
|---|
| 24 | #include <iostream> | 
|---|
| 25 |  | 
|---|
| 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" | 
|---|
| 32 | #include "CodePatterns/Assert.hpp" | 
|---|
| 33 | #include "CodePatterns/Log.hpp" | 
|---|
| 34 | #include "CodePatterns/Verbose.hpp" | 
|---|
| 35 | #include "LinearAlgebra/BoxVector.hpp" | 
|---|
| 36 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| 37 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| 38 | #include "RandomNumbers/RandomNumberDistribution_Parameters.hpp" | 
|---|
| 39 | #include "Atom/atom.hpp" | 
|---|
| 40 | #include "Box.hpp" | 
|---|
| 41 | #include "Element/element.hpp" | 
|---|
| 42 | #include "molecule.hpp" | 
|---|
| 43 | #include "Element/periodentafel.hpp" | 
|---|
| 44 | #include "World.hpp" | 
|---|
| 45 |  | 
|---|
| 46 | ValueStorage::ValueStorage() : | 
|---|
| 47 | OptionRegistry_instance(MoleCuilder::OptionRegistry::getInstance()) | 
|---|
| 48 | {}; | 
|---|
| 49 |  | 
|---|
| 50 | ValueStorage::~ValueStorage() {}; | 
|---|
| 51 |  | 
|---|
| 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()) | 
|---|
| 63 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 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()) | 
|---|
| 68 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 69 | atomID = lexical_cast<int>(CurrentValueMap[name].c_str()); | 
|---|
| 70 | CurrentValueMap.erase(name); | 
|---|
| 71 | } else | 
|---|
| 72 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 73 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 74 | typeid(_T).name(), | 
|---|
| 75 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 76 | ); | 
|---|
| 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()) | 
|---|
| 84 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 85 | Z = lexical_cast<int>(CurrentValueMap[name].c_str()); | 
|---|
| 86 | CurrentValueMap.erase(name); | 
|---|
| 87 | } else | 
|---|
| 88 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 89 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 90 | typeid(_T).name(), | 
|---|
| 91 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 92 | ); | 
|---|
| 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()) | 
|---|
| 100 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 101 | molID = lexical_cast<int>(CurrentValueMap[name].c_str()); | 
|---|
| 102 | CurrentValueMap.erase(name); | 
|---|
| 103 | } else | 
|---|
| 104 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 105 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 106 | typeid(_T).name(), | 
|---|
| 107 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 108 | ); | 
|---|
| 109 | _T = World::getInstance().getMolecule(MoleculeById(molID)); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | void ValueStorage::queryCurrentValue(const char * name, class Box &_T) { | 
|---|
| 113 | RealSpaceMatrix M; | 
|---|
| 114 | double tmp; | 
|---|
| 115 | if (typeid( Box ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) { | 
|---|
| 116 | if (CurrentValueMap.find(name) == CurrentValueMap.end()) | 
|---|
| 117 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 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 | 
|---|
| 137 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 138 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 139 | typeid(_T).name(), | 
|---|
| 140 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 141 | ); | 
|---|
| 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); | 
|---|
| 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 | } | 
|---|
| 153 | } else | 
|---|
| 154 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 155 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 156 | typeid(_T).name(), | 
|---|
| 157 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 158 | ); | 
|---|
| 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); | 
|---|
| 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 | } | 
|---|
| 170 | } else | 
|---|
| 171 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 172 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 173 | typeid(_T).name(), | 
|---|
| 174 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 175 | ); | 
|---|
| 176 | } | 
|---|
| 177 |  | 
|---|
| 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]); | 
|---|
| 181 | LOG(0, "ValueStorage::queryCurrentValue() for "+toString(name)+" is "+CurrentValueMap[name]+"."); | 
|---|
| 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 | 
|---|
| 187 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 188 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 189 | typeid(_T).name(), | 
|---|
| 190 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 191 | ); | 
|---|
| 192 | } | 
|---|
| 193 |  | 
|---|
| 194 | void ValueStorage::queryCurrentValue(const char * name, std::vector<const atom *>&_T) | 
|---|
| 195 | { | 
|---|
| 196 | int atomID = -1; | 
|---|
| 197 | size_t count = 0; | 
|---|
| 198 | atom *Walker = NULL; | 
|---|
| 199 | if (typeid( std::vector<const atom *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) { | 
|---|
| 200 | if (CurrentValueMap.find(name) == CurrentValueMap.end()) | 
|---|
| 201 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 202 | std::istringstream stream(CurrentValueMap[name]); | 
|---|
| 203 | CurrentValueMap.erase(name); | 
|---|
| 204 | while (!stream.fail()) { | 
|---|
| 205 | stream >> atomID >> ws; | 
|---|
| 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 | } | 
|---|
| 216 | } | 
|---|
| 217 | } else | 
|---|
| 218 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 219 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 220 | typeid(_T).name(), | 
|---|
| 221 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 222 | ); | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | void ValueStorage::queryCurrentValue(const char * name, std::vector<const element *>&_T) | 
|---|
| 226 | { | 
|---|
| 227 | int Z = -1; | 
|---|
| 228 | size_t count = 0; | 
|---|
| 229 | const element *elemental = NULL; | 
|---|
| 230 | if (typeid( std::vector<const element *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) { | 
|---|
| 231 | if (CurrentValueMap.find(name) == CurrentValueMap.end()) | 
|---|
| 232 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 233 | std::istringstream stream(CurrentValueMap[name]); | 
|---|
| 234 | CurrentValueMap.erase(name); | 
|---|
| 235 | while (!stream.fail()) { | 
|---|
| 236 | stream >> Z >> ws; | 
|---|
| 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 | } | 
|---|
| 246 | } | 
|---|
| 247 | } else | 
|---|
| 248 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 249 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 250 | typeid(_T).name(), | 
|---|
| 251 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 252 | ); | 
|---|
| 253 | } | 
|---|
| 254 |  | 
|---|
| 255 | void ValueStorage::queryCurrentValue(const char * name, std::vector<const molecule *>&_T) | 
|---|
| 256 | { | 
|---|
| 257 | int molID = -1; | 
|---|
| 258 | size_t count = 0; | 
|---|
| 259 | molecule *mol = NULL; | 
|---|
| 260 | if (typeid( std::vector<const molecule *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) { | 
|---|
| 261 | if (CurrentValueMap.find(name) == CurrentValueMap.end()) | 
|---|
| 262 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 263 | std::istringstream stream(CurrentValueMap[name]); | 
|---|
| 264 | CurrentValueMap.erase(name); | 
|---|
| 265 | while (!stream.fail()) { | 
|---|
| 266 | stream >> molID >> ws; | 
|---|
| 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 | } | 
|---|
| 277 | } | 
|---|
| 278 | } else | 
|---|
| 279 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 280 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 281 | typeid(_T).name(), | 
|---|
| 282 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 283 | ); | 
|---|
| 284 | } | 
|---|
| 285 |  | 
|---|
| 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()) | 
|---|
| 291 | throw MissingValueException() << ValueStorageOptionName(name); | 
|---|
| 292 | std::istringstream stream(CurrentValueMap[name]); | 
|---|
| 293 | CurrentValueMap.erase(name); | 
|---|
| 294 | stream >> tmp >> ws; | 
|---|
| 295 | ASSERT(!stream.fail(), | 
|---|
| 296 | "ValueStorage::queryCurrentValue() - boost::filesystem::path is missing!"); | 
|---|
| 297 | _T = tmp; | 
|---|
| 298 | } else | 
|---|
| 299 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 300 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 301 | typeid(_T).name(), | 
|---|
| 302 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 303 | ); | 
|---|
| 304 | } | 
|---|
| 305 |  | 
|---|
| 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 | 
|---|
| 313 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 314 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 315 | typeid(_T).name(), | 
|---|
| 316 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 317 | ); | 
|---|
| 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 | 
|---|
| 327 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 328 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 329 | typeid(_T).name(), | 
|---|
| 330 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 331 | ); | 
|---|
| 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 | 
|---|
| 341 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 342 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 343 | typeid(_T).name(), | 
|---|
| 344 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 345 | ); | 
|---|
| 346 | } | 
|---|
| 347 |  | 
|---|
| 348 | void ValueStorage::setCurrentValue(const char * name, class Box &_T) | 
|---|
| 349 | { | 
|---|
| 350 | const RealSpaceMatrix &M = _T.getM(); | 
|---|
| 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 | 
|---|
| 361 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 362 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 363 | typeid(_T).name(), | 
|---|
| 364 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 365 | ); | 
|---|
| 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 | 
|---|
| 383 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 384 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 385 | typeid(_T).name(), | 
|---|
| 386 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 387 | ); | 
|---|
| 388 | } | 
|---|
| 389 |  | 
|---|
| 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(); | 
|---|
| 396 | LOG(0, "ValueStorage::setCurrentValue() for "+toString(name)+" to "+stream.str()+"."); | 
|---|
| 397 | } else | 
|---|
| 398 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 399 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 400 | typeid(_T).name(), | 
|---|
| 401 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 402 | ); | 
|---|
| 403 | } | 
|---|
| 404 |  | 
|---|
| 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 | 
|---|
| 414 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 415 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 416 | typeid(_T).name(), | 
|---|
| 417 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 418 | ); | 
|---|
| 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 | 
|---|
| 430 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 431 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 432 | typeid(_T).name(), | 
|---|
| 433 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 434 | ); | 
|---|
| 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 | 
|---|
| 446 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 447 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 448 | typeid(_T).name(), | 
|---|
| 449 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 450 | ); | 
|---|
| 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 | 
|---|
| 460 | throw IllegalTypeException() << ValueStorageOptionName(name) | 
|---|
| 461 | << ValueStoragePairTypeName(std::make_pair( | 
|---|
| 462 | typeid(_T).name(), | 
|---|
| 463 | OptionRegistry_instance.getOptionByName(name)->getTypeName().c_str()) | 
|---|
| 464 | ); | 
|---|
| 465 | } | 
|---|
| 466 |  | 
|---|
| 467 | const std::string ValueStorage::getCurrentValue(std::string actionname) { | 
|---|
| 468 | return CurrentValueMap[actionname]; | 
|---|
| 469 | } | 
|---|
| 470 |  | 
|---|
| 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 |  | 
|---|
| 482 | CONSTRUCT_SINGLETON(ValueStorage) | 
|---|