Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
util.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file util.h
1 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
2 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
3 // MIT License
4 
5 #ifndef UTIL_H
6 #define UTIL_H
7 
8 #include <iostream>
9 #include <sstream>
10 
11 #include <boost/filesystem.hpp>
12 #include <boost/program_options/variables_map.hpp>
13 
14 #include "../src/fwd_decl.h"
15 
16 // testing utilities
17 
18 // Factory function; create a dummy boost::program_options::variables_map.
19 VarMap make_var_map(std::map<std::string, boost::any>&& args);
20 
21 // redirect stdout to a stringstream and safely restore upon destruction
24  // replace stdout buffer
25  cout_orig = std::cout.rdbuf(stream.rdbuf());
26  }
27 
29  // restore stdout to working state
30  std::cout.rdbuf(cout_orig);
31  }
32 
33  std::streambuf* cout_orig;
34  std::stringstream stream;
35 };
36 
37 // path that deletes itself when it goes out of scope
40  : path(
41  fs::temp_directory_path() /
42  fs::unique_path().replace_extension(ext)
43  )
44  {}
46  fs::remove_all(path);
47  }
48  const fs::path path;
49 };
50 
51 #endif // UTIL_H