source: src/Potentials/PotentialDeserializer.cpp@ 97dff0

Last change on this file since 97dff0 was c5e63a, checked in by Frederik Heber <heber@…>, 12 years ago

Added De(serializer) functors for instanting potentials from stream info.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 Frederik Heber. All rights reserved.
5 * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * PotentialDeserializer.cpp
26 *
27 * Created on: 09.05.2013
28 * Author: heber
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "CodePatterns/MemDebug.hpp"
37
38#include "PotentialDeserializer.hpp"
39
40#include <iostream>
41#include <sstream>
42#include <string>
43
44#include "CodePatterns/Log.hpp"
45
46#include "Potentials/PotentialFactory.hpp"
47#include "Potentials/PotentialRegistry.hpp"
48
49void PotentialDeserializer::operator()()
50{
51 std::string linestring;
52 while (serialized.good()) {
53 getline(serialized, linestring);
54 const std::string whitespace(" \t");
55 const size_t strBegin = linestring.find_first_not_of(whitespace);
56 const size_t colonpos = linestring.find(":");
57 if ((strBegin != std::string::npos) && (colonpos != std::string::npos)) {
58 // get potential's token
59 const std::string token = linestring.substr(strBegin, colonpos);
60 std::stringstream potentialstream(linestring);
61
62 // instantiate type
63 EmpiricalPotential *potential =
64 PotentialFactory::getInstance().createInstance(
65 token, potentialstream);
66
67 // and register
68 PotentialRegistry::getInstance().registerInstance(potential);
69
70 } else {
71 ELOG(2, "Line '" << linestring << "' contains no potential.");
72 }
73 }
74}
Note: See TracBrowser for help on using the repository browser.