votca 2024.2-dev
Loading...
Searching...
No Matches
votca_property.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18// Standard includes
19#include <iostream>
20
21// Third party includes
22#include <boost/algorithm/string/replace.hpp>
23#include <boost/format.hpp>
24#include <boost/program_options.hpp>
25
26// Local VOTCA includes
28#include "votca/tools/globals.h"
31#include "votca/tools/version.h"
32
33using namespace std;
34using namespace votca::tools;
35namespace po = boost::program_options;
36
37class VotcaProperty final : public Application {
38
39 public:
40 VotcaProperty() = default;
41 ~VotcaProperty() = default;
42
43 string ProgramName() { return "votca_property"; }
44
45 void HelpText(ostream& out) { out << "Helper for parsing XML files"; }
46
47 void Initialize() {
48
49 format = "XML";
50 level = 1;
51
52 AddProgramOptions()("file", po::value<string>(), "xml file to parse")(
53 "format", po::value<string>(), "output format [XML TXT]")(
54 "level", po::value<votca::Index>(), "output from this level ");
55 };
56
58 CheckRequired("file", "Missing XML file");
59 return true;
60 };
61
62 void Run() {
63
64 file = OptionsMap()["file"].as<string>();
65
66 if (OptionsMap().count("format")) {
67 format = OptionsMap()["format"].as<string>();
68 }
69 if (OptionsMap().count("level")) {
70 level = OptionsMap()["level"].as<votca::Index>();
71 }
72
73 try {
74
75 Property p;
76 map<string, PropertyIOManipulator*> mformat_;
77 mformat_["XML"] = &XML;
78 mformat_["TXT"] = &TXT;
79 mformat_["HLP"] = &HLP;
81
82 if (mformat_.find(format) != mformat_.end()) {
83 PropertyIOManipulator* piom = mformat_.find(format)->second;
84 piom->setLevel(level);
85 piom->setIndentation("");
86 piom->setColorScheme<csRGB>();
87 cout << *piom << p;
88 } else {
89 cout << "format " << format << " not supported \n";
90 }
91
92 } catch (std::exception& error) {
93 cerr << "an error occurred:\n" << error.what() << endl;
94 }
95 };
96
97 private:
98 string file;
99 string format;
101};
102
103int main(int argc, char** argv) {
104 VotcaProperty vp;
105 return vp.Exec(argc, argv);
106}
VotcaProperty()=default
~VotcaProperty()=default
void Run()
Main body of application.
void HelpText(ostream &out)
help text of application without version information
votca::Index level
bool EvaluateOptions()
Process command line options.
string ProgramName()
program name
void Initialize()
Initialize application data.
int Exec(int argc, char **argv)
executes the program
boost::program_options::variables_map & OptionsMap()
get available program options & descriptions
boost::program_options::options_description_easy_init AddProgramOptions(const std::string &group="")
add option for command line
void CheckRequired(const std::string &option_name, const std::string &error_msg="")
Check weather required option is set.
Manipulates the format state of the output stream.
void setIndentation(std::string indentation)
class to manage program options with xml serialization functionality
Definition property.h:55
void LoadFromXML(std::string filename)
Definition property.cc:238
STL namespace.
PropertyIOManipulator TXT
PropertyIOManipulator XML
PropertyIOManipulator HLP
Eigen::Index Index
Definition types.h:26
int main(int argc, char **argv)