QMCPACK
NativeInitializerPrint.hpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2022 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 /** \file
13  * The operator<< functions provide output for data structures that can be
14  * used to directly initialize them in test code.
15  *
16  * Usage is present in future test code and provides the "coverage" of these
17  * functions.
18  */
19 
20 #ifndef QMCPLUSPLUS_NATIVE_INTITIALIZER_PRINT_HPP
21 #define QMCPLUSPLUS_NATIVE_INTITIALIZER_PRINT_HPP
22 
23 #include <string>
24 #include <iostream>
25 #include "OhmmsPETE/TinyVector.h"
26 #include "OhmmsPETE/OhmmsVector.h"
27 
28 namespace qmcplusplus
29 {
30 
31 /** This wrapper is to allow us to leave the user facing operator<< for classes alone
32  */
33 template<typename OBJECT>
35 {
36 public:
37  using type_t = OBJECT;
38  NativePrint(const OBJECT& obj) : obj_(obj) {}
39  const OBJECT& get_obj() const { return obj_; }
40 
41 private:
42  OBJECT obj_;
43 };
44 
45 template<class T, unsigned D>
46 inline std::ostream& operator<<(std::ostream& out, const NativePrint<TinyVector<T, D>>& np_vec)
47 {
48  out << "{ ";
49  auto vec = np_vec.get_obj();
50  for (int i = 0; i < D - 1; ++i)
51  out << std::setw(12) << std::setprecision(10) << vec[i] << ", ";
52  out << std::setw(12) << std::setprecision(10) << vec[D - 1] << " }";
53  return out;
54 }
55 
56 template<class T>
57 inline std::ostream& operator<<(std::ostream& out, const NativePrint<std::vector<T>>& np_vec)
58 {
59  out << "{ ";
60  auto vec = np_vec.get_obj();
61  for (T& t : vec)
62  out << std::setprecision(10) << t << ", ";
63  out << " }";
64  return out;
65 }
66 
67 template<>
68 inline std::ostream& operator<<(std::ostream& out, const NativePrint<std::vector<bool>>& np_vec)
69 {
70  out << "{ ";
71  auto vec = np_vec.get_obj();
72  for (const bool& t : vec)
73  {
74  std::string bool_str = t ? "true" : "false";
75  out << std::setprecision(10) << bool_str << ", ";
76  }
77  out << " }";
78  return out;
79 }
80 
81 template<class T>
82 inline std::ostream& operator<<(std::ostream& out, const NativePrint<Vector<T>>& np_vec)
83 {
84  out << "{ ";
85  auto vec = np_vec.get_obj();
86  for (T& t : vec)
87  out << std::setprecision(10) << t << ", ";
88  out << " }";
89  return out;
90 }
91 
92 
93 } // namespace qmcplusplus
94 
95 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
This wrapper is to allow us to leave the user facing operator<< for classes alone.
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
const OBJECT & get_obj() const