LCOV - code coverage report
Current view: top level - include/utils - DataFileUtils.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 4 4 100.0 %
Date: 2026-05-29 20:35:17 Functions: 2 2 100.0 %
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 <string>
      13             : #include <optional>
      14             : 
      15             : namespace Moose::DataFileUtils
      16             : {
      17             : 
      18             : /**
      19             :  * Context for where a data file came from
      20             :  */
      21             : enum class Context
      22             : {
      23             :   /// Relative to the base (typically an input file)
      24             :   RELATIVE,
      25             :   /// An absolute path
      26             :   ABSOLUTE,
      27             :   /// From installed/in-tree data
      28             :   DATA,
      29             :   /// Relative to the base, but not found
      30             :   RELATIVE_NOT_FOUND,
      31             :   /// Absolute, but not found
      32             :   ABSOLUTE_NOT_FOUND,
      33             :   /// Unused for default
      34             :   INVALID
      35             : };
      36             : 
      37             : /**
      38             :  * Representation of a data file path
      39             :  */
      40             : struct Path
      41             : {
      42       21028 :   Path() : path(), context(Context::INVALID), data_name() {}
      43       21038 :   Path(const std::string & path,
      44             :        const Context context,
      45             :        const std::optional<std::string> & data_name = std::optional<std::string>())
      46       21038 :     : path(path), context(context), data_name(data_name)
      47             :   {
      48       21038 :   }
      49             :   // Path to the file
      50             :   std::string path;
      51             :   /// Context for the file (where it came from)
      52             :   Context context;
      53             :   /// The name of the data registry the file came from (with context == DATA)
      54             :   std::optional<std::string> data_name;
      55             : };
      56             : 
      57             : /**
      58             :  * Options to be passed to getPath().
      59             :  */
      60             : struct GetPathOptions
      61             : {
      62             :   /// The base path by which to search for relative paths. This is usually
      63             :   /// the folder that an input file is in so that paths are searched relative
      64             :   /// to where that input file is.
      65             :   std::optional<std::string> base;
      66             :   /// Whether or not to search all registered data.
      67             :   bool search_all_data = true;
      68             :   /// Whether or not to error whenever a path is not found. If this is true,
      69             :   /// the only time an error is emitted is when an explicit data name is
      70             :   /// specified and not registered or when an explicit data name is specified
      71             :   /// and the file was not found within that registered data folder.
      72             :   bool graceful = false;
      73             : };
      74             : 
      75             : /**
      76             :  * Get the data path for a given path, searching the registered data
      77             :  *
      78             :  * @param path The path; can be prefixed with <name>: to search only data from <name>
      79             :  * @param options Search options; see docstring for GetPathOptions for more info
      80             :  */
      81             : Path getPath(std::string path, const GetPathOptions & options = {});
      82             : 
      83             : /**
      84             :  * Get the data path for a given path, searching the registered data given an explicit
      85             :  * data search path.
      86             :  *
      87             :  * This exists primarily so that you don't need to call getPath("moose:file").
      88             :  *
      89             :  * @param data_name - The registered data name
      90             :  * @param path - The path
      91             :  * @param base - The base by which to search for the file relative to (optional)
      92             :  */
      93             : Path getPathExplicit(const std::string & data_name,
      94             :                      const std::string & path,
      95             :                      const std::optional<std::string> & base = std::optional<std::string>());
      96             : }

Generated by: LCOV version 1.14