LCOV - code coverage report
Current view: top level - include/utils - JsonSyntaxTree.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 8601ad Lines: 2 2 100.0 %
Date: 2025-07-18 13:27:08 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "InputParameters.h"
      13             : #include "FileLineInfo.h"
      14             : #include "nlohmann/json.h"
      15             : #include <string>
      16             : #include <vector>
      17             : #include <utility>
      18             : 
      19             : /**
      20             :  * Holds the syntax in a Json::Value tree
      21             :  */
      22             : class JsonSyntaxTree
      23             : {
      24             : public:
      25             :   JsonSyntaxTree(const std::string & search_string);
      26         179 :   virtual ~JsonSyntaxTree() {}
      27             : 
      28             :   /**
      29             :    * Add parameters to the tree
      30             :    * @param parent_path The parent syntax path that the action belongs to
      31             :    * @param path The path of the action
      32             :    * @param is_type Whether this belongs to a "<type>" or not
      33             :    * @param action Name of the action
      34             :    * @param is_action Whether we are adding the parameter for an action (except Components)
      35             :    * @param params The InputParameters to add to the tree
      36             :    * @param lineinfo The FileLineInfo where the action/path was registered
      37             :    * @param classname the name of the class being added
      38             :    * @return Whether the parameters were added to the tree (ie if it matched the search string).
      39             :    */
      40             :   bool addParameters(const std::string & parent_path,
      41             :                      const std::string & path,
      42             :                      bool is_type,
      43             :                      const std::string & action,
      44             :                      bool is_action,
      45             :                      InputParameters * params,
      46             :                      const FileLineInfo & lineinfo,
      47             :                      const std::string & classname);
      48             : 
      49             :   /**
      50             :    * Add a task to the tree
      51             :    * @param path The path of the action
      52             :    * @param action Name of the action
      53             :    * @param task Name of the task
      54             :    * @param lineinfo The FileLineInfo where the action/task was registered
      55             :    */
      56             :   void addActionTask(const std::string & path,
      57             :                      const std::string & action,
      58             :                      const std::string & task,
      59             :                      const FileLineInfo & lineinfo);
      60             :   /**
      61             :    * Get the root of the tree.
      62             :    * @return The top level Json::Value holding the tree.
      63             :    */
      64         197 :   const nlohmann::json & getRoot() const { return _root; }
      65             : 
      66             :   /**
      67             :    * Add an associated type to a block
      68             :    * @param path Path of the block
      69             :    * @param type Type name to associate the block with
      70             :    */
      71             :   void addSyntaxType(const std::string & path, const std::string type);
      72             : 
      73             :   /**
      74             :    * Add the global section to the output
      75             :    */
      76             :   void addGlobal();
      77             : 
      78             :   /**
      79             :    * Utilities for making sense of c++ types
      80             :    */
      81             :   static std::string basicCppType(const std::string & cpp_type);
      82             : 
      83             : protected:
      84             :   std::string buildOptions(const std::iterator_traits<InputParameters::iterator>::value_type & p,
      85             :                            bool & out_of_range_allowed,
      86             :                            std::map<MooseEnumItem, std::string> & docs);
      87             : 
      88             :   size_t setParams(InputParameters * params, bool search_match, nlohmann::json & all_params);
      89             : 
      90             :   static std::string
      91             :   buildOutputString(const std::iterator_traits<InputParameters::iterator>::value_type & p);
      92             :   static std::vector<std::string> splitPath(const std::string & path);
      93             :   nlohmann::json & getJson(const std::string & parent, const std::string & path, bool is_type);
      94             :   nlohmann::json & getJson(const std::string & path);
      95             :   std::pair<std::string, std::string> getObjectLabel(const std::string & obj) const;
      96             :   std::pair<std::string, std::string> getActionLabel(const std::string & action) const;
      97             : 
      98             :   nlohmann::json _root;
      99             :   std::string _search;
     100             : 
     101             :   ///@{
     102             :   /// Maps storing action/object name to the label and file location
     103             :   std::map<std::string, std::pair<std::string, std::string>> _action_label_map;
     104             :   std::map<std::string, std::pair<std::string, std::string>> _object_label_map;
     105             :   ///@}
     106             : 
     107             :   // Allow the MooseServer class to use protected static convenience methods
     108             :   friend class MooseServer;
     109             : };

Generated by: LCOV version 1.14