Walker test code coverage report
Current view: top level - Control - HelpFactory.hpp (source / functions) Hit Total Coverage
Commit: test_coverage.info Lines: 16 16 100.0 %
Date: 2022-09-21 13:52:12 Functions: 197 197 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 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                 :            : 
      23                 :            : namespace tk {
      24                 :            : namespace ctr {
      25                 :            : 
      26                 :            : //! \brief Keyword information bundle
      27                 :            : //! \details This bundle contains the information that is used to display
      28                 :            : //!    on-screen help on all command-line arguments and control file keywords
      29                 :            : //!    for an exectuable. This struct is stored in a container that associates
      30                 :            : //!    keywords (used by a grammar and parser) to this struct. The container, an
      31                 :            : //!    runtime, std::map, is filled by the CmdLine and InputDeck objects'
      32                 :            : //!    constructors by one or more brigand::for_each which loops through the
      33                 :            : //!    set of all keywords used in a grammar. The maps are stored in the CmdLine
      34                 :            : //!    and InputDeck objects (which are tagged tuples) and thus can be migrated
      35                 :            : //!    through the network, thus the Charm++ parck/unpack routines are defined.
      36                 :            : //! \see Info functor used to fill the std::maps
      37                 :            : struct KeywordInfo {
      38                 :            :   std::string shortDescription;           //!< Short description
      39                 :            :   std::string longDescription;            //!< Long description
      40                 :            :   std::optional< std::string > alias;     //!< Keyword alias
      41                 :            :   std::optional< std::string > expt;      //!< Expected type description
      42                 :            :   std::optional< std::string > lower;     //!< Lower bound as string
      43                 :            :   std::optional< std::string > upper;     //!< Upper bound as string
      44                 :            :   std::optional< std::string > choices;   //!< Expected choices description
      45                 :            : 
      46                 :            :   /** @name Pack/Unpack: Serialize KeywordInfo object for Charm++ */
      47                 :            :   ///@{
      48                 :            :   //! \brief Pack/Unpack serialize member function
      49                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      50                 :     145181 :   void pup( PUP::er& p ) {
      51                 :     145181 :     p | shortDescription;
      52                 :     145181 :     p | longDescription;
      53                 :     145181 :     p | alias;
      54                 :     145181 :     p | expt;
      55                 :     145181 :     p | lower;
      56                 :     145181 :     p | upper;
      57                 :     145181 :     p | choices;
      58                 :     145181 :   }
      59                 :            :   //! \brief Pack/Unpack serialize operator|
      60                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      61                 :            :   //! \param[in,out] info KeywordInfo object reference
      62         [ +  - ]:     144390 :   friend void operator|( PUP::er& p, KeywordInfo& info ) { info.pup(p); }
      63                 :            :   ///@}
      64                 :            : };
      65                 :            : 
      66                 :            : //! \brief A typedef for associating a keyword-string with its associated
      67                 :            : //!   information stored in a KeywordInfo struct
      68                 :            : using HelpFactory = std::map< std::string, KeywordInfo >;
      69                 :            : 
      70                 :            : //! \brief Help bundle on a single keyword
      71                 :            : //! \details This is used for delivering help on a single keyword. This struct
      72                 :            : //!    also differentiates between command-line arguments and control file
      73                 :            : //!    keywords.
      74                 :        886 : struct HelpKw {
      75                 :            :   HelpFactory::key_type keyword;        //!< Keyword string
      76                 :            :   HelpFactory::mapped_type info;        //!< Keyword information
      77                 :            :   bool cmd;                             //!< True if command-line keyword
      78                 :            : 
      79                 :            :   /** @name Pack/Unpack: Serialize HelpKw object for Charm++ */
      80                 :            :   ///@{
      81                 :            :   //! \brief Pack/Unpack serialize member function
      82                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      83                 :        791 :   void pup( PUP::er& p ) { p|keyword; p|info; p|cmd; }
      84                 :            :   //! \brief Pack/Unpack serialize operator|
      85                 :            :   //! \param[in,out] p Charm++'s PUP::er serializer object reference
      86                 :            :   //! \param[in,out] h HelpKw object reference
      87                 :        791 :   friend void operator|( PUP::er& p, HelpKw& h ) { h.pup(p); }
      88                 :            :   ///@}
      89                 :            : };
      90                 :            : 
      91                 :            : //! \brief Function object for filling a HelpFactory (std::map) with keywords
      92                 :            : //!   and their associated information bundle
      93                 :            : //! \details This struct is used as a functor to loop through a set of keywords
      94                 :            : //!   at compile-time and generate code for filling up the std::map.
      95                 :            : struct Info {
      96                 :            :   //! Store reference to map we are filling
      97                 :            :   tk::ctr::HelpFactory& m_factory;
      98                 :            :   //! Constructor: store reference to map to fill
      99                 :            :   explicit Info( tk::ctr::HelpFactory& factory ) : m_factory( factory ) {}
     100                 :            :   //! \brief Function call operator templated on the type that does the filling
     101                 :     138831 :   template< typename U > void operator()( brigand::type_<U> ) {
     102 [ +  - ][ +  - ]:     277662 :     m_factory[ U::string() ] = { U::shortDescription(),
     103                 :            :                                  U::longDescription(),
     104                 :            :                                  U::alias(),
     105                 :            :                                  U::expt(),
     106                 :            :                                  U::lower(),
     107                 :            :                                  U::upper(),
     108                 :            :                                  U::choices() };
     109                 :     138831 :   }
     110                 :            : };
     111                 :            : 
     112                 :            : } // ctr::
     113                 :            : } // tk::
     114                 :            : 
     115                 :            : #endif // HelpFactory_h

Generated by: LCOV version 1.14