Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:48

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file corecel/io/OutputInterface.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <iosfwd>  // IWYU pragma: export
0011 #include <string>  // IWYU pragma: export
0012 #include <string_view>  // IWYU pragma: export
0013 
0014 namespace celeritas
0015 {
0016 //---------------------------------------------------------------------------//
0017 struct JsonPimpl;
0018 
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Pure abstract interface for writing metadata output to JSON.
0022  *
0023  * At the end of the program/run, the OutputRegistry will call the "output"
0024  * method on all interfaces.
0025  *
0026  * \todo Perhaps another output method for saving a schema?
0027  */
0028 class OutputInterface
0029 {
0030   public:
0031     //! Output category (TODO: could replace with string/cstring?)
0032     enum class Category
0033     {
0034         input,
0035         result,
0036         system,
0037         internal,
0038         size_
0039     };
0040 
0041   public:
0042     //! Category of data to write
0043     virtual Category category() const = 0;
0044 
0045     //! Key for the entry inside the category.
0046     virtual std::string_view label() const = 0;
0047 
0048     // Write output to the given JSON object
0049     virtual void output(JsonPimpl*) const = 0;
0050 
0051   protected:
0052     // Protected destructor prevents direct deletion of pointer-to-interface
0053     ~OutputInterface() = default;
0054 };
0055 
0056 //---------------------------------------------------------------------------//
0057 // FREE FUNCTIONS
0058 //---------------------------------------------------------------------------//
0059 
0060 // Get a string representation of the category
0061 char const* to_cstring(OutputInterface::Category value);
0062 
0063 // Get the JSON representation of a single output (mostly for testing)
0064 std::string to_string(OutputInterface const& output);
0065 
0066 // Stream the JSON representation of a single output
0067 std::ostream& operator<<(std::ostream&, OutputInterface const& output);
0068 
0069 //---------------------------------------------------------------------------//
0070 }  // namespace celeritas