Quinoa all test code coverage report
Current view: top level - Control - HelpFactory.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 21 21 100.0 %
Date: 2024-04-29 14:42:33 Functions: 26 26 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 10 50.0 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Control/HelpFactory.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     Command-line and input deck help factory
       9                 :            :   \details   This file contains some types that facilitate the generation of
      10                 :            :      on-screen help.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : #ifndef HelpFactory_h
      14                 :            : #define HelpFactory_h
      15                 :            : 
      16                 :            : #include <brigand/sequences/list.hpp>
      17                 :            : #include <brigand/algorithms/for_each.hpp>
      18                 :            : 
      19                 :            : #include "PUPUtil.hpp"
      20                 :            : #include "Factory.hpp"
      21                 :            : #include "Has.hpp"
      22                 :            : #include "Types.hpp"
      23                 :            : 
      24                 :            : namespace tk {
      25                 :            : namespace ctr {
      26                 :            : 
      27                 :            : //! \brief Keyword information bundle
      28                 :            : //! \details This bundle contains the information that is used to display
      29                 :            : //!    on-screen help on all command-line arguments and control file keywords
      30                 :            : //!    for an exectuable. This struct is stored in a container that associates
      31                 :            : //!    keywords (used by a grammar and parser) to this struct. The container, an
      32                 :            : //!    runtime, std::map, is filled by the CmdLine and InputDeck objects'
      33                 :            : //!    constructors by one or more brigand::for_each which loops through the
      34                 :            : //!    set of all keywords used in a grammar. The maps are stored in the CmdLine
      35                 :            : //!    and InputDeck objects (which are tagged tuples) and thus can be migrated
      36                 :            : //!    through the network, thus the Charm++ parck/unpack routines are defined.
      37                 :            : //! \see Info functor used to fill the std::maps
      38                 :            : struct KeywordInfo {
      39                 :            :   std::string shortDescription;           //!< Short description
      40                 :            :   std::string longDescription;            //!< Long description
      41                 :            :   std::optional< std::string > alias;     //!< Keyword alias
      42                 :            :   std::optional< std::string > expt;      //!< Expected type description
      43                 :            :   std::optional< std::string > lower;     //!< Lower bound as string
      44                 :            :   std::optional< std::string > upper;     //!< Upper bound as string
      45                 :            :   std::optional< std::string > choices;   //!< Expected choices description
      46                 :            : 
      47                 :            :   /** @name Pack/Unpack: Serialize KeywordInfo object for Charm++ */
      48                 :            :   ///@{
      49                 :            :   //! \brief Pack/Unpack serialize member function
      50                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      51                 :     451393 :   void pup( PUP::er& p ) {
      52                 :     451393 :     p | shortDescription;
      53                 :     451393 :     p | longDescription;
      54                 :     451393 :     p | alias;
      55                 :     451393 :     p | expt;
      56                 :     451393 :     p | lower;
      57                 :     451393 :     p | upper;
      58                 :     451393 :     p | choices;
      59                 :     451393 :   }
      60                 :            :   //! \brief Pack/Unpack serialize operator|
      61                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      62                 :            :   //! \param[in,out] info KeywordInfo object reference
      63         [ +  - ]:     449570 :   friend void operator|( PUP::er& p, KeywordInfo& info ) { info.pup(p); }
      64                 :            :   ///@}
      65                 :            : };
      66                 :            : 
      67                 :            : //! \brief A typedef for associating a keyword-string with its associated
      68                 :            : //!   information stored in a KeywordInfo struct
      69                 :            : using HelpFactory = std::map< std::string, KeywordInfo >;
      70                 :            : 
      71                 :            : //! \brief Help bundle on a single keyword
      72                 :            : //! \details This is used for delivering help on a single keyword. This struct
      73                 :            : //!    also differentiates between command-line arguments and control file
      74                 :            : //!    keywords.
      75                 :       1973 : struct HelpKw {
      76                 :            :   HelpFactory::key_type keyword;        //!< Keyword string
      77                 :            :   HelpFactory::mapped_type info;        //!< Keyword information
      78                 :            :   bool cmd;                             //!< True if command-line keyword
      79                 :            : 
      80                 :            :   /** @name Pack/Unpack: Serialize HelpKw object for Charm++ */
      81                 :            :   ///@{
      82                 :            :   //! \brief Pack/Unpack serialize member function
      83                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      84                 :       1823 :   void pup( PUP::er& p ) { p|keyword; p|info; p|cmd; }
      85                 :            :   //! \brief Pack/Unpack serialize operator|
      86                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      87                 :            :   //! \param[in,out] h HelpKw object reference
      88                 :       1823 :   friend void operator|( PUP::er& p, HelpKw& h ) { h.pup(p); }
      89                 :            :   ///@}
      90                 :            : };
      91                 :            : 
      92                 :            : //! \brief Function object for filling a HelpFactory (std::map) with keywords
      93                 :            : //!   and their associated information bundle
      94                 :            : //! \details This struct is used as a functor to loop through a set of keywords
      95                 :            : //!   at compile-time and generate code for filling up the std::map.
      96                 :            : struct Info {
      97                 :            :   //! Store reference to map we are filling
      98                 :            :   tk::ctr::HelpFactory& m_factory;
      99                 :            :   //! Constructor: store reference to map to fill
     100                 :       1369 :   explicit Info( tk::ctr::HelpFactory& factory ) : m_factory( factory ) {}
     101                 :            :   //! \brief Function call operator templated on the type that does the filling
     102                 :      62075 :   template< typename U > void operator()( brigand::type_<U> ) {
     103 [ +  - ][ +  - ]:     124150 :     m_factory[ U::string() ] = { U::shortDescription(),
     104                 :            :                                  U::longDescription(),
     105                 :            :                                  U::alias(),
     106                 :            :                                  U::expt(),
     107                 :            :                                  U::lower(),
     108                 :            :                                  U::upper(),
     109                 :            :                                  U::choices() };
     110                 :      62075 :   }
     111                 :            : 
     112                 :            :   //! Fill map in a simpler way passing a string rather than a brigand-type
     113                 :     309394 :   void fill( const tk::entry_t& kw )
     114                 :            :   {
     115 [ +  - ][ +  - ]:     618788 :     m_factory[kw.string()] = { kw.shortDescription(),
     116                 :            :                                kw.longDescription(),
     117                 :            :                                kw.alias(),
     118                 :            :                                kw.expt(),
     119                 :            :                                kw.lower(),
     120                 :            :                                kw.upper(),
     121                 :     928182 :                                kw.choices() };
     122                 :     309394 :   }
     123                 :            : };
     124                 :            : 
     125                 :            : } // ctr::
     126                 :            : } // tk::
     127                 :            : 
     128                 :            : #endif // HelpFactory_h

Generated by: LCOV version 1.14