Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/Control/RNGTest/CmdLine/CmdLine.hpp
4 : : \copyright 2012-2015 J. Bakosi,
5 : : 2016-2018 Los Alamos National Security, LLC.,
6 : : 2019-2021 Triad National Security, LLC.
7 : : All rights reserved. See the LICENSE file for details.
8 : : \brief RNGTest's command line
9 : : \details This file defines the heterogeneous stack that is used for storing
10 : : the data from user input during the command-line parsing of the
11 : : random number generator test suite, RNGTest.
12 : : */
13 : : // *****************************************************************************
14 : : #ifndef RNGTestCmdLine_h
15 : : #define RNGTestCmdLine_h
16 : :
17 : : #include <string>
18 : :
19 : : #include <brigand/algorithms/for_each.hpp>
20 : :
21 : : #include "QuinoaConfig.hpp"
22 : : #include "TaggedTuple.hpp"
23 : : #include "HelpFactory.hpp"
24 : : #include "Keywords.hpp"
25 : : #include "RNGTest/Types.hpp"
26 : :
27 : : namespace rngtest {
28 : : //! RNGTest control facilitating user input to internal data transfer
29 : : namespace ctr {
30 : :
31 : : //! Member data for tagged tuple
32 : : using CmdLineMembers = brigand::list<
33 : : tag::io, ios
34 : : , tag::verbose, bool
35 : : , tag::chare, bool
36 : : , tag::help, bool
37 : : , tag::helpctr, bool
38 : : , tag::quiescence, bool
39 : : , tag::trace, bool
40 : : , tag::version, bool
41 : : , tag::license, bool
42 : : , tag::cmdinfo, tk::ctr::HelpFactory
43 : : , tag::ctrinfo, tk::ctr::HelpFactory
44 : : , tag::helpkw, tk::ctr::HelpKw
45 : : , tag::error, std::vector< std::string >
46 : : >;
47 : :
48 : : //! CmdLine is a TaggedTuple specialized to RNGTest
49 : : class CmdLine : public tk::TaggedTuple< CmdLineMembers > {
50 : :
51 : : public:
52 : : //! RNGTest command-line keywords
53 : : //! \see tk::grm::use and its documentation
54 : : using keywords = tk::cmd_keywords< kw::verbose
55 : : , kw::charestate
56 : : , kw::control
57 : : , kw::help
58 : : , kw::helpctr
59 : : , kw::helpkw
60 : : , kw::screen
61 : : , kw::quiescence
62 : : , kw::trace
63 : : , kw::version
64 : : , kw::license
65 : : >;
66 : :
67 : : //! Set of tags to ignore when printing this CmdLine
68 : : using ignore =
69 : : brigand::set< tag::cmdinfo
70 : : , tag::ctrinfo
71 : : , tag::helpkw >;
72 : :
73 : : //! \brief Constructor: set all defaults.
74 : : //! \param[in] ctrinfo std::map of control file keywords and their info
75 : : //! \details Anything not set here is initialized by the compiler using the
76 : : //! default constructor for the corresponding type. The ctrinfo map
77 : : //! argument is optional. If not given, it is an empty std::map
78 : : //! constructed in-place and affects nothing. If given, it contains the
79 : : //! control file keywords, all of which are moved into the relevant slot
80 : : //! (tag::ctrinfo). This allows constructing, e.g., a CmdLine object both
81 : : //! with and without this information in place, which are both used at
82 : : //! different stages of the execution. For example, because the
83 : : //! command-line is parsed very early on during runtime while the input
84 : : //! deck is only parsed much later, the control-file keywords and their
85 : : //! information (owned by and generated by the input deck and its
86 : : //! constructor) is not yet available when the CmdLine object is
87 : : //! constructed. However, during command-line parsing it is still possible
88 : : //! to request information on a control file keyword, so it must be
89 : : //! available. The input deck is where all parsed information goes during
90 : : //! control file parsing and is stored at global scope, see, e.g.,
91 : : //! walker::g_inputdeck. This global-scope (still namespace-scope), input
92 : : //! deck object is thus created before command-line parsing. The input
93 : : //! deck object's constructor (working only on type information, available
94 : : //! at compile-time, of all the control file keywords) creates a run-time
95 : : //! map. This is a run-time map, but available before main() starts,
96 : : //! because it is const and it is initialized as a global-scope map. This
97 : : //! map is then passed in here as ctrinfo, and its contents inserted into
98 : : //! the CmdLine object, making the control-file keywords and their info
99 : : //! available during command-line parsing. Since the input deck stack
100 : : //! contains a copy of the command-line stack, the command-line stack must
101 : : //! be possible to be instantiated without passing the ctrinfo map,
102 : : //! otherwise it would be a mutual dependency.
103 : : // cppcheck-suppress noExplicitConstructor
104 : 364 : CmdLine( tk::ctr::HelpFactory ctrinfo = tk::ctr::HelpFactory() ) {
105 : 364 : get< tag::io, tag::screen >() =
106 [ + - ][ + - ]: 728 : tk::baselogname( tk::rngtest_executable() );
107 : 364 : get< tag::verbose >() = false; // Use quiet output by default
108 : 364 : get< tag::chare >() = false; // No chare state output by default
109 : 364 : get< tag::trace >() = true; // Output call and stack trace by default
110 : 364 : get< tag::version >() = false; // Do not display version info by default
111 : 364 : get< tag::license >() = false; // Do not display license info by default
112 : : // Initialize help: fill from own keywords + add map passed in
113 [ + - ]: 364 : brigand::for_each< keywords::set >( tk::ctr::Info( get<tag::cmdinfo>()) );
114 : 364 : get< tag::ctrinfo >() = std::move( ctrinfo );
115 : 364 : }
116 : :
117 : : /** @name Pack/Unpack: Serialize CmdLine object for Charm++ */
118 : : ///@{
119 : : //! \brief Pack/Unpack serialize member function
120 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
121 : 184 : void pup( PUP::er& p ) { tk::TaggedTuple< CmdLineMembers >::pup(p); }
122 : : //! \brief Pack/Unpack serialize operator|
123 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
124 : : //! \param[in,out] c CmdLine object reference
125 : 184 : friend void operator|( PUP::er& p, CmdLine& c ) { c.pup(p); }
126 : : //@}
127 : :
128 : : //! Compute and return log file name
129 : : //! \param[in] def Default log file name (so we don't mess with user's)
130 : : //! \param[in] nrestart Number of times restarted
131 : : //! \return Log file name
132 : 512 : std::string logname( const std::string& def, int nrestart ) const {
133 [ - + ]: 512 : if (get< tag::io, tag::screen >() != def)
134 : 0 : return get< tag::io, tag::screen >();
135 : : else
136 [ + - ]: 1024 : return tk::logname( tk::rngtest_executable(), nrestart );
137 : : }
138 : : };
139 : :
140 : : } // ctr::
141 : : } // rngtest::
142 : :
143 : : #endif // RNGTestCmdLine_h
|