Skip to content
Snippets Groups Projects
Commit efafd301 authored by Jesper Andersson's avatar Jesper Andersson
Browse files

Changed << to check for user defined flag on stream and adapt its behaviour accordingly

parent 35143a9d
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,21 @@
#include "options.h"
// Below I declare variables and a function
// needed for changing the behaviour of << so that the
// user can chose between old style and more detailed
// output.
// Jesper Andersson
namespace Utilities {
std::map<string,long> UserStreamFlag;
std::ostream &detailed_output(std::ostream& os)
{
if (UserStreamFlag.find("OutputType") == UserStreamFlag.end()) UserStreamFlag["OutputType"] = os.xalloc();
os.iword(UserStreamFlag["OutputType"]) = DetailedOutput;
return(os);
}
}
namespace Utilities {
using namespace std;
......@@ -45,8 +60,13 @@ namespace Utilities {
template<> ostream& Option<bool>::print(ostream& os) const
{
os << "# " << help_text() << endl;
if(set())
os << config_key().substr(0, config_key().find("="));
if (Utilities::UserStreamFlag.find("OutputType") != Utilities::UserStreamFlag.end() &&
os.iword(Utilities::UserStreamFlag["OutputType"]) == Utilities::DetailedOutput) {
os << key() << "=" << ( set() ? "True" : "False");
}
else {
if (set()) os << config_key().substr(0, config_key().find("="));
}
return os;
}
......
......@@ -8,6 +8,7 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include <iterator>
......@@ -17,6 +18,27 @@
using namespace std;
// Below I define constants and a function
// needed for changing the behaviour of << so that the
// user can chose between old style and more detailed
// output. If one wants for example a log-file with
// details of all parameters one would do something like
//
// Utilities::OptionParser options(...)
// ...
// ofstream dpf; // Detailed Parameter File
// Utilities::detailed_output(dpf);
// dpf.open("my_file.txt"));
// dpf << options << endl;
// dpf.close();
//
// Jesper Andersson
namespace Utilities {
const long RegularOutput = 4;
const long DetailedOutput = 5;
std::ostream &detailed_output(std::ostream& os);
}
namespace Utilities {
bool string_to_T(bool &b, const std::string& s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment