1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2017 Frederik Heber. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * DiffFragmentResultContainer.cpp
|
---|
25 | *
|
---|
26 | * Created on: Apr 5, 2017
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
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 headers that implement a archive in simple text format
|
---|
39 | #include <boost/archive/text_oarchive.hpp>
|
---|
40 | #include <boost/archive/text_iarchive.hpp>
|
---|
41 |
|
---|
42 | #include <boost/filesystem/operations.hpp>
|
---|
43 | #include <boost/filesystem/path.hpp>
|
---|
44 | #include <boost/bind.hpp>
|
---|
45 |
|
---|
46 | #include <algorithm>
|
---|
47 | #include <fstream>
|
---|
48 |
|
---|
49 | #include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
|
---|
50 |
|
---|
51 | static bool file_not_exists(const boost::filesystem::path &path) {
|
---|
52 | return !boost::filesystem::exists(path);
|
---|
53 | }
|
---|
54 |
|
---|
55 | int main(int argc, char **argv)
|
---|
56 | {
|
---|
57 | if (argc < 2) {
|
---|
58 | std::cout << "Usage:" << argv[0] << "<file 1> <file2>\n";
|
---|
59 | return 255;
|
---|
60 | }
|
---|
61 |
|
---|
62 | // parse two file names
|
---|
63 | std::vector<boost::filesystem::path> filenames;
|
---|
64 | filenames.reserve(2);
|
---|
65 | filenames.push_back(std::string(argv[1]));
|
---|
66 | filenames.push_back(std::string(argv[2]));
|
---|
67 |
|
---|
68 | // check whether both files exists
|
---|
69 | std::vector<boost::filesystem::path>::iterator iter =
|
---|
70 | std::find_if(
|
---|
71 | filenames.begin(), filenames.end(),
|
---|
72 | file_not_exists);
|
---|
73 | if (iter != filenames.end()) {
|
---|
74 | std::cerr << "The file " << iter->string() << " does not exist.\n";
|
---|
75 | return 255;
|
---|
76 | }
|
---|
77 |
|
---|
78 | // deserialize and compare
|
---|
79 | // Note that because FragmentationResultContainer is a singleton, we cannot
|
---|
80 | // compare two distinct instances. Therefore, we deserialize and serialize
|
---|
81 | // again both files in order to compare the strings on grounds of the same
|
---|
82 | // serialization function (and library).
|
---|
83 | std::stringstream outfile1;
|
---|
84 | std::stringstream outfile2;
|
---|
85 | FragmentationResultContainer::purgeInstance();
|
---|
86 | {
|
---|
87 | std::ifstream infile(filenames[0].string().c_str());
|
---|
88 | FragmentationResultContainer &results = FragmentationResultContainer::getInstance();
|
---|
89 | boost::archive::text_iarchive ia(infile);
|
---|
90 | boost::archive::text_oarchive oa(outfile1);
|
---|
91 | ia >> results;
|
---|
92 | oa << results;
|
---|
93 | }
|
---|
94 | FragmentationResultContainer::purgeInstance();
|
---|
95 | {
|
---|
96 | std::ifstream infile(filenames[1].string().c_str());
|
---|
97 | FragmentationResultContainer &results = FragmentationResultContainer::getInstance();
|
---|
98 | boost::archive::text_iarchive ia(infile);
|
---|
99 | boost::archive::text_oarchive oa(outfile2);
|
---|
100 | ia >> results;
|
---|
101 | oa << results;
|
---|
102 | }
|
---|
103 |
|
---|
104 | // because container is a singleton, we can only copy the memory
|
---|
105 |
|
---|
106 | if (outfile1.str() != outfile2.str()) {
|
---|
107 | std::cout << "The two containers differ:\n";
|
---|
108 | std::cout << outfile1.str() << std::endl;
|
---|
109 | std::cout << outfile2.str() << std::endl;
|
---|
110 | return 5;
|
---|
111 | }
|
---|
112 |
|
---|
113 | return 0;
|
---|
114 | }
|
---|